[arch-general] get pid of daemon in init script

Michael Krauss hippodriver at gmx.net
Fri Feb 8 14:27:08 EST 2008


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.

Kind Regards,
Michael Krauss


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




More information about the arch-general mailing list