Got error from apache after upgraded Debian to Jessie (8.x)

I upgraded my Debian server to Jessie yesterday, due to I didn’t update all the configs, I found some errors, and got to fix them.

Error message:

Starting web server: apache2 failed!
The apache2 configtest failed. … (warning).
Output of config test was:
AH00526: Syntax error on line 89 of /etc/apache2/apache2.conf:
Invalid command ‘LockFile’, perhaps misspelled or defined by a module not included in the server
configuration
Action ‘configtest’ failed.
The Apache error log may have more information.

Solution:

Edit /etc/apache2/apache2.conf, replace line 89:
LockFile ${APACHE_LOCK_DIR}/accept.lock
with this line:
Mutex file:${APACHE_LOCK_DIR} default

Another error:

Starting web server: apache2 failed!
The apache2 configtest failed. … (warning).
Output of config test was:
AH00526: Syntax error on line 17 of /etc/apache2/sites-enabled/000-default.conf:
Either all Options must start with + or -, or no Option may.

Action ‘configtest’ failed.
The Apache error log may have more information.

So just add symbol + for the options without prefix symbol and it works again.

Error: Read-only file system on Linux

Today I found that there is a strange situation, in certain mount point on my web server (Debian GNU/Linux 7.8), every process with write behavior will get message like this:

touch: cannot touch `test’: Read-only file system

I don’t think I mount it as read-only, so I check it:
$ mount | grep srv
And I got:

/dev/sdb1 on /srv type ext4 (ro,relatime,data=ordered)

Very strange … there was something wrong, could I remount it with r/w? I tried:
$ sudo mount -o remount,rw,relatime,data=ordered /srv
Hmmmm …

mount: cannot remount block device /dev/sdb1 read-write, is write-protected

Okay, seems I need to check the filesystem …
$ sudo umount /srv
$ sudo fsck.ext4 /dev/sdb1

The process didn’t take long time, just within 3 mins, and that’s the result:

e2fsck 1.42.5 (29-Jul-2012)
/dev/sdb1: recovering journal
/dev/sdb1 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 796453/122077184 files (3.8% non-contiguous), 321192367/488281498 blocks

Let’s mount it again:
$ sudo mount -o rw,relatime,data=ordered /srv
Oh, I didn’t get any error message this time, let’s check it again:
$ mount | grep srv
And …

/dev/sdb1 on /srv type ext4 (rw,relatime,data=ordered)

Okay, nice … very easy this time, I’ve got some disks with destroyed partition before, event I can’t not recognize its partition type, though I fixed it, but I didn’t record the process that time, ha.

How to check battery status in cli under Debian/Ubuntu based Linux?

You may need to install upower via sudo apt-get install upower first

use -e / –enumerate to list the devices:

‘peter@peter-MacBookPro ~ $ upower -e
/org/freedesktop/UPower/devices/line_power_ADP1
/org/freedesktop/UPower/devices/battery_BAT0

use -i / –show-info and the device path to show the details

peter@peter-MacBookPro ~ $ upower –show-info /org/freedesktop/UPower/devices/battery_BAT0
native-path: BAT0
vendor: *********************************
model: *********************************
power supply: yes
updated: Sat 14 Feb 2015 04:11:52 PM CST (9 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
energy: 7.63 Wh
energy-empty: 0 Wh
energy-full: 55.75 Wh
energy-full-design: 57.7 Wh
energy-rate: 15.946 W
voltage: 10.9 V
time to empty: 28.7 minutes
percentage: 13%
capacity: 96.6205%
History (charge):
1423901482 13.000 discharging
History (rate):
1423901512 15.946 discharging
1423901482 14.978 discharging
1423901452 14.740 discharging
1423901422 16.179 discharging

Easier method to show all details in one line command:

$ upower -e | xargs -n 1 upower -i
native-path: ADP1
power supply: yes
updated: Sat 14 Feb 2015 09:58:27 AM CST (22532 seconds ago)
has history: no
has statistics: no
line-power
online: no

native-path: BAT0
vendor: *********************************
model: *********************************
power supply: yes
updated: Sat 14 Feb 2015 04:13:52 PM CST (7 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
energy: 7.08 Wh
energy-empty: 0 Wh
energy-full: 55.75 Wh
energy-full-design: 57.7 Wh
energy-rate: 18.069 W
voltage: 10.846 V
time to empty: 23.5 minutes
percentage: 12%
capacity: 96.6205%
History (charge):
1423901602 12.000 discharging
History (rate):
1423901632 18.069 discharging
1423901602 16.164 discharging
1423901572 15.799 discharging
1423901542 16.767 discharging

Screenshot:
batteryCliStatusScreenshot

Building NAT on Debian GNU/Linux with iptables

interfaces:

eth0(internal):
192.168.1.254
eth1(external):
aaa.bbb.ccc.ddd

enable forwarding:

sudo sysctl net.ipv4.ip_forward=1

iptables commands(can be saved to a shell script):

clean up old rules

iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

accept loopback traffic

iptables -A INPUT -i lo -j ACCEPT

allow internal connections

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

masquerade

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

reject connections from eth1

iptables -A FORWARD -i eth1 -o eth1 -j REJECT

Easy and fast!

backup the rules:


sudo iptables-save > /path/savedConfig

auto load the rules:


sudo sh -c "echo 'pre-up iptables-restore < /path/savedConfig' >> /etc/network/interfaces

How to find reverse dependency on Debian/Ubuntu based GNU/Linux?

List all the reverse depends of certain package:

$ apt-cache rdepends pkg_name

For example:

$ apt-cache rdepends vde2

And you’ll get result like this:

vde2
Reverse Depends:
virtualbox
qemu-system-x86
qemu-system-sparc
qemu-system-ppc
qemu-system-misc
qemu-system-mips
qemu-system-arm
user-mode-linux
virtualbricks
virtualbox
vdetelweb
libvde-dev
libvde-dev
user-mode-linux
qemu-kvm
qemu-system
liblwipv6-2

More details via $ apt-cache showpkg pkg_name

Package: vde2
Versions:
2.3.2-4 (/var/lib/apt/lists/opensource.nchc.org.tw_debian_dists_wheezy_main_binary-amd64_Packages) (/var/lib/dpkg/status)
Description Language:
File: /var/lib/apt/lists/opensource.nchc.org.tw_debian_dists_wheezy_main_binary-amd64_Packages
MD5: c1d59c710a94c274459c01b82f926c5a
Description Language: en
File: /var/lib/apt/lists/opensource.nchc.org.tw_debian_dists_wheezy_main_i18n_Translation-en
MD5: c1d59c710a94c274459c01b82f926c5a

Reverse Depends:
virtualbox,vde2
qemu-system-x86,vde2
qemu-system-sparc,vde2
qemu-system-ppc,vde2
qemu-system-misc,vde2
qemu-system-mips,vde2
qemu-system-arm,vde2
user-mode-linux,vde2
virtualbricks,vde2
virtualbox,vde2
vdetelweb,vde2
libvde-dev,vde2 2.3.2-1
libvde-dev,vde2 2.3.2-1
user-mode-linux,vde2
qemu-kvm,vde2
qemu-system,vde2
liblwipv6-2,vde2
Dependencies:
2.3.2-4 – adduser (0 (null)) libc6 (2 2.7) libpcap0.8 (2 0.9.8) libvde0 (0 (null)) libvdeplug2 (0 (null)) vde2-cryptcab (0 (null)) qemu-kvm (0 (null)) qemu (0 (null)) vde (0 (null))
Provides:
2.3.2-4 –
Reverse Provides:

If we only want to know the installed dependencies, ask aptitude:

$ aptitude why vde2

It’ll tell us:

i qemu Depends qemu-system (>= 1.1.2+dfsg-6a+deb7u6)
i A qemu-system Recommends vde2

What about recursive depends? Try $ apt-rdepends --reverse pkg_name !
(Install via apt-get install apt-rdepends)

PS: reverse-depends has similar feature, but it’s in ubuntu-dev-tools, which depends on toooooo many packages, so I’ll not suggest you to use it for just finding the dependencies.