O script abaixo está funcionando bem na inicialização do sistema.
No entanto, suas mensagens de log não são mostradas em /var/log/boot.log
, quando o sistema é inicializado.
Eu o comparei com outros scripts de init.d
e não pude chegar a nenhuma conclusão sobre o que estou perdendo.
Quando eu o executo via linha de comando sudo service <script> start|stop|restart
, as mensagens esperadas aparecem na saída do terminal.
O que devo fazer para obter as mensagens de log desse script em /var/log/boot.log
sem canalizar sua saída para o arquivo de log, usando apenas /lib/lsb/init-functions
?
Estou no Ubuntu 14.04 LTS.
Abaixo está o script e a configuração do nível de execução.
O script (nome: 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
Configuração do nível de execução
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