下面的脚本在系统启动时运行良好。
/var/log/boot.log
但是,系统启动时,其日志消息不会显示在。
我将它与其他init.d
脚本进行了比较,但无法得出我遗漏了什么的结论。
当我通过sudo service <script> start|stop|restart
命令行执行它时,预期的消息会出现在终端输出中。
我应该怎么做才能将该脚本中的日志消息放入其中,/var/log/boot.log
而不将其输出通过管道传输到日志文件,只需使用/lib/lsb/init-functions
?
我在使用 Ubuntu 14.04 LTS。
以下是脚本和运行级别配置。
脚本(名称:rtorrent)
#!/bin/bash
### BEGIN INIT INFO
# Provides: rtorrent
# Required-Start: $syslog $local_fs
# Required-Stop: $syslog $local_fs
# Should-Start: $remote_fs
# Should-Stop: $remote_fs
# X-Start-Before: xdm kdm gdm ldm sdm
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: rtorrent
# Description: Load up rtorrent in a screen session and pirate away
### END INIT INFO
###############
#
# TO INSTALL RUN
# sudo /usr/sbin/update-rc.d rtorrent defaults
# TO SEE SCRIPT OUTPUT
# cat /var/log/boot.log
#
##################
. /lib/lsb/init-functions
# EDIT THIS VARIABLE TO THE USER THAT YOU WANT RTORRENT TO RUN AS
USER=<myuserid>
case "$1" in
start)
log_daemon_msg "Starting rtorrent"
if [ -f /home/$USER/rtorrent/.session/rtorrent.lock ]; then
su $USER -c 'rm -f /home/$USER/rtorrent/.session/rtorrent.lock' &> /dev/null
fi
su $USER -c 'screen -d -m -S rtorrent rtorrent' &> /dev/null
if [ $? -gt 0 ]; then
log_failure_msg "FAILED."
log_end_msg 1
exit 0
else
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping rtorrent"
killall -w -s 2 /usr/local/bin/rtorrent &> /dev/null
if [ $? -gt 0 ]; then
log_failure_msg "FAILED."
log_end_msg 1
else
log_end_msg 0
fi
;;
restart)
$0 stop
sleep 3
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
运行级别配置
rc.local
rc0.d:
K02vmguest
K09apache2
K10unattended-upgrades
K20bandwidthd
K20btsync
K20osspd
K20rtorrent
K20speech-dispatcher
K20transmission-daemon
K20vboxautostart-service
K20vboxballoonctrl-service
K20vboxdrv
K20vboxweb-service
K20virtualbox
README
S20sendsigs
S30urandom
S31umountnfs.sh
S35networking
S40umountfs
S60umountroot
S90halt
rc1.d:
K02vmguest
K09apache2
K20acpi-support
K20bandwidthd
K20btsync
K20kerneloops
K20osspd
K20rtorrent
K20saned
K20snmpd
K20speech-dispatcher
K20transmission-daemon
K20vboxautostart-service
K20vboxballoonctrl-service
K20vboxdrv
K20vboxweb-service
K20virtualbox
README
S30killprocs
S70dns-clean
S70pppd-dns
S90single
rc2.d:
README
S20bandwidthd
S20btsync
S20kerneloops
S20osspd
S20snmpd
S20speech-dispatcher
S20transmission-daemon
S20vboxautostart-service
S20vboxballoonctrl-service
S20vboxdrv
S20vboxweb-service
S20virtualbox
S50rsync
S50saned
S70dns-clean
S70pppd-dns
S75sudo
S80rtorrent
S91apache2
S98vmguest
S99acpi-support
S99grub-common
S99ondemand
S99rc.local
rc3.d:
README
S20bandwidthd
S20btsync
S20kerneloops
S20osspd
S20snmpd
S20speech-dispatcher
S20transmission-daemon
S20vboxautostart-service
S20vboxballoonctrl-service
S20vboxdrv
S20vboxweb-service
S20virtualbox
S50rsync
S50saned
S70dns-clean
S70pppd-dns
S75sudo
S80rtorrent
S91apache2
S98vmguest
S99acpi-support
S99grub-common
S99ondemand
S99rc.local
rc4.d:
README
S20bandwidthd
S20btsync
S20kerneloops
S20osspd
S20snmpd
S20speech-dispatcher
S20transmission-daemon
S20vboxautostart-service
S20vboxballoonctrl-service
S20vboxdrv
S20vboxweb-service
S20virtualbox
S50rsync
S50saned
S70dns-clean
S70pppd-dns
S75sudo
S80rtorrent
S91apache2
S98vmguest
S99acpi-support
S99grub-common
S99ondemand
S99rc.local
rc5.d:
README
S20bandwidthd
S20btsync
S20kerneloops
S20osspd
S20snmpd
S20speech-dispatcher
S20transmission-daemon
S20vboxautostart-service
S20vboxballoonctrl-service
S20vboxdrv
S20vboxweb-service
S20virtualbox
S50rsync
S50saned
S70dns-clean
S70pppd-dns
S75sudo
S80rtorrent
S91apache2
S98vmguest
S99acpi-support
S99grub-common
S99ondemand
S99rc.local
rc6.d:
K02vmguest
K09apache2
K10unattended-upgrades
K20bandwidthd
K20btsync
K20osspd
K20rtorrent
K20speech-dispatcher
K20transmission-daemon
K20vboxautostart-service
K20vboxballoonctrl-service
K20vboxdrv
K20vboxweb-service
K20virtualbox
README
S20sendsigs
S30urandom
S31umountnfs.sh
S35networking
S40umountfs
S60umountroot
S90reboot
rcS.d:
README
S25brltty
S37apparmor
S47lm-sensors
S55urandom
S70x11-common