2

The script below is working fine at system startup.

However, its log messages don't show in /var/log/boot.log, when the system boots.

I compared it with other init.d scripts and couldn't reach any conclusion as to what I am missing.

When I execute it via sudo service <script> start|stop|restart command line, the expected messages show up in the terminal output.

What should I have to do to get the log messages from this script into /var/log/boot.log without piping its output to the log file, just by using /lib/lsb/init-functions?

I'm on Ubuntu 14.04 LTS.

Below is the script and runlevel configuration.

The script (name: 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

Runlevel configuration

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
5
  • Is your syslogd already up and running when you call this init script?
    – Jan
    Sep 11, 2014 at 22:05
  • @Jan How can I check that?
    – oneaty
    Sep 12, 2014 at 9:32
  • Quite difficult without some knowlegde of how logging works. You can check if your init script is called prior to starting syslogd (or whatever you may use) in your runlevel configuration.
    – Jan
    Sep 12, 2014 at 9:40
  • 1
    @Jan I apended my runlevel configuration to the post, but I couldn't determine when syslogd is called. Btw, why is it important to determine if syslogd starts before the script? Is it the program responsible for handling /lib/lsb/init-functions like log_daemon_msg, log_failure_msg, log_end_msg, etc?
    – oneaty
    Sep 12, 2014 at 14:26
  • Did you check if /var filesystem is ready when your script starts?
    – Lety
    Dec 22, 2015 at 11:23

1 Answer 1

1

You (and me) started from the wrong assumption. According to this,

[...] the messages are printed the console and written to usplash (if applicable).

There's also this post on SO saying that you should rather use #!/bin/sh instead of bash (but failing to provide a reason for that).

So even if there's no issue with using bash, you won't find something in the logs, only on the screen.

3
  • That's the most common approach we find on the Internet regarding this issue, but I would go with that as a last resource. I'm trying to understand why some scripts that use /lib/lsb/init-functions the same way my rtorrent script does do show on /var/log/boot.log but rtorrent don't. For example, this script shows its output in /var/log/boot.log, as you can see in the boot.log file.
    – oneaty
    Sep 12, 2014 at 17:13
  • As for the #!/bin/sh thing, I'm already using it, as you can see in the script
    – oneaty
    Sep 12, 2014 at 17:21
  • I made a small mod to my post to make it more clear that I'm not just looking for a workaround, but a full understanding of the issue
    – oneaty
    Sep 12, 2014 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .