Custom daemon script: works, but does not run at boot / startup
Posted
by
pearjoint
on Ask Ubuntu
See other posts from Ask Ubuntu
or by pearjoint
Published on 2011-04-10T08:56:31Z
Indexed on
2011/06/21
0:30 UTC
Read the original article
Hit count: 292
this is Ubuntu 10.10 Maverick.
I have the following shell script in init.d that I want to run as a "daemon" (background service with start/stop/restart really) at system startup. There is a symlink in rc3.d. I tried 4 and 5 too. (Ideally this would initialize before graphical login happens and before a user logs in.)
IMPORTANT: the script works 100% as expected and required when testing this with service MetaLeapDaemon start and service MetaLeapDaemon stop. (This shell script calls a Python program which makes sure the appropriate .pid files are both created at startup and deleted at exit.)
So generally it works fine but now my only issue is why it will not be run at any of the run-levels I tried. I know for sure it isn't run because the log file it normally creates does not get created.
As you can see (by the lack of any uid:gid args in the start-stop-daemon commands) this would currently run only under root, is this forbidden in a default setup?
Here's the script, pretty much your run-off-the-mill daemon script really:
#! /bin/sh
DAEMON=/opt/metaleap/_core/daemon/MetaLeapDaemon.py
NAME=MetaLeapDaemon
DESC="MetaLeapDaemon"
test -f $DAEMON || exit 0
set -e
case "$1" in
start)
start-stop-daemon --start --pidfile /var/run/$NAME.pid --exec $DAEMON
;;
stop)
start-stop-daemon --stop --pidfile /var/run/$NAME.pid
;;
restart)
start-stop-daemon --stop --pidfile /var/run/$NAME.pid
sleep 1
start-stop-daemon --start --pidfile /var/run/$NAME.pid --exec $DAEMON
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
© Ask Ubuntu or respective owner