Re: [arch-general] get pid of daemon in init script
On Feb 8, 2008 1:27 PM, Michael Krauss [EMAIL PROTECTED] 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
[arch-general] get pid of daemon in init script
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
Re: [arch-general] get pid of daemon in init script
On Feb 8, 2008 3:06 PM, Sentinel [EMAIL PROTECTED] wrote: Hi! It works perfectly (at least for me), just you have to ensure, that you call it with appropriate rights while testing: my testing: [EMAIL PROTECTED]:~$ su Password: with power comes great responsibility [EMAIL PROTECTED]:/home/sentinel# PID=`pidof -o %PPID -x /usr/sbin/proftpd` [EMAIL PROTECTED]:/home/sentinel# echo $PID 7469 [EMAIL PROTECTED]:/home/sentinel# [ -z $PID ] echo pid is empty [EMAIL PROTECTED]:/home/sentinel# Tom That is because you already have /usr/sbin/proftpd running. In the case of running the start initscript, the PID is sampled before the application ever starts, and hence will return no PID, as Dan already explained.
Re: [arch-general] get pid of daemon in init script
Hi! It works perfectly (at least for me), just you have to ensure, that you call it with appropriate rights while testing: my testing: [EMAIL PROTECTED]:~$ su Password: with power comes great responsibility [EMAIL PROTECTED]:/home/sentinel# PID=`pidof -o %PPID -x /usr/sbin/proftpd` [EMAIL PROTECTED]:/home/sentinel# echo $PID 7469 [EMAIL PROTECTED]:/home/sentinel# [ -z $PID ] echo pid is empty [EMAIL PROTECTED]:/home/sentinel# Tom Dan McGee wrote: On Feb 8, 2008 1:27 PM, Michael Krauss [EMAIL PROTECTED] 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
Re: [arch-general] get pid of daemon in init script
yes you are right. [EMAIL PROTECTED]:/home/sentinel# /etc/rc.d/proftpd stop :: Stopping ProFTPd Server [DONE] [EMAIL PROTECTED]:/home/sentinel# PID=`pidof -o %PPID -x /usr/sbin/proftpd` [EMAIL PROTECTED]:/home/sentinel# echo $PID [EMAIL PROTECTED]:/home/sentinel# Sorry, I made a mistake. I usually do not have my ftp server running. But I forgot, that I was moving something between my computer and laptop. :) Btw proftpd's init script does the same. The proftpd.pid file is empty. T Travis Willard wrote: On Feb 8, 2008 3:06 PM, Sentinel [EMAIL PROTECTED] wrote: Hi! It works perfectly (at least for me), just you have to ensure, that you call it with appropriate rights while testing: my testing: [EMAIL PROTECTED]:~$ su Password: with power comes great responsibility [EMAIL PROTECTED]:/home/sentinel# PID=`pidof -o %PPID -x /usr/sbin/proftpd` [EMAIL PROTECTED]:/home/sentinel# echo $PID 7469 [EMAIL PROTECTED]:/home/sentinel# [ -z $PID ] echo pid is empty [EMAIL PROTECTED]:/home/sentinel# Tom That is because you already have /usr/sbin/proftpd running. In the case of running the start initscript, the PID is sampled before the application ever starts, and hence will return no PID, as Dan already explained.