I'm running into a weird issue here. I compiled a daemon (namely, vblade, which is used to share drives for ATA over Ethernet support). As with most any other daemon, it must be run as root or else it does not run. First of all, here is the script (it is basically just a total copy of crond with added functions to properly create the pid file).
---
#!/bin/sh
# /etc/init.d/vblade: Start, stop and restart vblade daemon on SliTaz, at boot
# time or with the command line.
#
# To start daemon at boot time, just put the right name in the $RUN_DAEMONS
# variable of /etc/rcS.conf and configure options with /etc/daemons.conf.
#
. /etc/init.d/rc.functions
. /etc/daemons.conf
NAME=vblade
DESC="vblade deamon"
DAEMON=/usr/sbin/vblade
OPTIONS=$VBLADED_OPTIONS
PIDFILE=/var/run/vbladed.pid
case "$1" in
start)
if active_pidfile $PIDFILE $NAME ; then
echo "$NAME already running."
exit 1
fi
echo -n "Starting $DESC: $NAME... "
$DAEMON $OPTIONS >> /var/log/$NAME.log 2>&1 &
[ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
active_pidfile $PIDFILE $NAME
status
;;
stop)
if ! active_pidfile $PIDFILE $NAME ; then
echo "$NAME is not running."
exit 1
fi
echo -n "Stopping $DESC: $NAME... "
kill cat $PIDFILE
rm $PIDFILE
status
;;
restart)
if ! active_pidfile $PIDFILE $NAME ; then
echo "$NAME is not running."
exit 1
fi
echo -n "Restarting $DESC: $NAME... "
kill cat $PIDFILE
rm $PIDFILE
sleep 2
$DAEMON $OPTIONS >> /var/log/$NAME.log 2>&1 &
[ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
active_pidfile $PIDFILE $NAME
status
;;
*)
echo ""
echo -e "33[1mUsage:33[0m /etc/init.d/basename $0
[start|stop|restart]"
echo ""
exit 1
;;
esac
exit 0
---
Here is the problem: this does not autostart vblade on startup during the init process even though I have everything properly defined (vblade in rcS.conf and options in daemons.conf). In contrast, all my other daemons I added there (udhcpd, inetd) do. However, if I run it as root after the system is up, it executes just fine. Another strange issue, if I get rid of the "&" to daemonize the process in the line "$DAEMON $OPTIONS >> /var/log/$NAME.log 2>&1 &", it autostarts just fine with the rest of my daemons. However, this is a hack at best, because then you see /etc/init.d/vblade start listed in the process list. How do I get this daemon to autostart with init AND properly daemonize? Ideally, only /usr/sbin/vblade $OPTIONS should be listed in ps if it daemonizes properly. I tried to use the conf file that comes with the vblade .deb package, but that uses lsb functions so it does not work.