On Feb 8, 2008 1:27 PM, Michael Krauss <hippodriver@gmx.net> wrote:
Hi to .*
I must write a rc init script for a server I am packaging. Therefor I have copied the init script of cups. Now I recognized that both pid files, cups.pid and my own, in /var/run are empty.
Further investigations have shown that
"pidof -o %PPID -x /usr/bin/cdvserver"
returns nothing in the start) case but in stop) it seems to work. I don't understand why pidof isn't working as expected.
Because you are calling pidof before the process starts- bash does not do lazy evaluation of your expressions. If you want to store the PID of the newly started process, you will have to make another PID=... call to get it in the else block where you access it.
Here is my init script: #!/bin/bash
. /etc/rc.conf . /etc/rc.d/functions
PID=`pidof -o %PPID -x /usr/bin/cdvserver` PIDFILE="/var/run/cdvserver.pid" case "$1" in start) stat_busy "Starting Codeville Server" [ -z "$PID" ] && /usr/bin/cdvserver if [ $? -gt 0 ]; then stat_fail else echo "Started " $PID echo $PID > $PIDFILE add_daemon cdv stat_done fi ;; stop) stat_busy "Stopping Codeville Server" [ ! -z "$PID" ] && kill $PID &> /dev/null if [ $? -gt 0 ]; then stat_fail else rm $PIDFILE rm_daemon cdv stat_done fi ;; restart) $0 stop sleep 1 $0 start ;; *) echo "usage: $0 {start|stop|restart}" esac exit 0