Saturday, February 28, 2015

Fix /opt/etc/init.d scripts not executing issue in LS VL Buffalo linkstation

I noticed that the transmission-daemon start up script (S95transmission.sh) added to /opt/etc/init.d/ directory does not get executed when the linkstation is started up.

Let's look at how startup scripts put in to /opt/etc/init.d/ directory are invoked.

1. /etc/init.d/rcS invokes /etc/init.d/rc.optware script. These are the last few lines in the rcS script.

/usr/local/bin/hdd_raid_syncspeed.sh
            
# Optware setup
[ -x /etc/init.d/rc.optware ] && /etc/init.d/rc.optware start
                                                     
exit 0 

2. Then /etc/init.d/rc.optware script mounts /opt partition and invokes /opt/etc/rc.optware script.

case "$1" in
    start)
        echo "Starting Optware."
        if test -n "${REAL_OPT_DIR}"; then
            if ! grep ' /opt ' /proc/mounts >/dev/null 2>&1 ; then
                mkdir -p /opt
                mount -o bind ${REAL_OPT_DIR} /opt
            fi
        fi
[ -x /opt/etc/rc.optware ] && /opt/etc/rc.optware
    ;;
    reconfig)


3. This /opt/etc/rc.optware script simply executes scripts matches with S??*  located in /opt/etc/init.d/ directory.

#!/bin/sh

# Start all init scripts in /opt/etc/init.d
# executing them in numerical order.
#
for i in /opt/etc/init.d/S??* ;do

# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue

case "$i" in
  *.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)


So after some investigations I have found out that rcS script didn't execute it's last few lines. It seemed it exited just after executing /usr/local/bin/hdd_raid_syncspeed.sh line. The simple solution was to move this line to the bottom of the script so that the optware setup is executed first. Now the startup script added to the /opt/etc/rc.optware is started whenever the linkstation is rebooted. :)

The last few lines of rcS after the modification,

#/usr/local/bin/hdd_raid_syncspeed.sh
            
# Optware setup
[ -x /etc/init.d/rc.optware ] && /etc/init.d/rc.optware start
                                         
/usr/local/bin/hdd_raid_syncspeed.sh
                        

exit 0