On Ubuntu 11.10, if I run /usr/bin/cserver -c /etc/cserver.conf & it'll work fine.
But if I run service cserver start or /etc/init.d/cserver start as I did on 10.10, it won't. It just says "starting cServer", and that's the last I hear of it.
Here's the script:
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: cserver
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network $time
# Should-Stop: $network $time
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Start and stop the cserver server daemon
# Description: Controls the cserver server daemon
### END INIT INFO
#
set -e
set -u
${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
CSERVERDIR=/usr/bin
PROG=./cserver
OPTIONS=" -c /etc/cserver.conf > /dev/null 2>&1 &"
start() {
echo -n "Starting cServer "
cd $CSERVERDIR
daemon $PROG $OPTIONS
RETVAL=$?
echo
return $RETVAL
}
stop() {
CSERVERPID=$(pidof cserver)
if [ $CSERVERPID ] ; then
echo -n "Stopping cServer "
kill $(pidof cserver)
RETVAL=$?
else
echo "cServer not running"
RETVAL=1
fi
echo
return $RETVAL
}
status() {
CSERVERPID=$(pidof cserver)
if [ $CSERVERPID ] ; then
echo -n "cServer is running"
RETVAL=0
else
echo -n "cServer is stopped"
RETVAL=1
fi
echo
return $RETVAL
}
# See how we were called.
RETVAL=0
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
exit 1
esac
exit $?
Although I never had to do this on the original server, and sysv-rc-conf showed it present in the list and starting at the right levels, I manually tried doing the update-rc.d and it complained about an invalid lsb header, which led me to this question and guide. So I changed the header as above, and here's what it looked like before:
#!/bin/bash
#
#
# chkconfig: 345 99 99
#
# description: cserver init
# processname: cserver
# Source function library.
# . /etc/rc.d/init.d/functions
Now, there's that line about "Source function library", but that directory doesn't even exist and the line is commented out anyway.
I've checked the permissions and symlinks etc on the old server, and everything seems identical.
A little bit dazed and confused now - perhaps a fresh and more knowledgaeble pair of eyes can spot something here? Thanks.
UPDATE and EDIT: Thanks kubankczyk - I went for your suggestion of copying another found the nginx startup script to be the simplest, and ended up with the following:
#!/bin/sh
### BEGIN INIT INFO
# Provides: cserver
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the cserver server
# Description: starts cserver using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/cserver
NAME=cserver
DESC=cserver
DAEMON_OPTS=" -c /etc/cserver.conf"
#test -x $DAEMON || exit 0
set -e
#set -u
#${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
. /lib/lsb/init-functions
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON || true
sleep 1
start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
status)
status_of_proc -p /var/run/$NAME.pid "$DAEMON" cserver && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0
Not sure whether it's correct, but at least it starts the service! Thanks.