What are good equivalent centos commands using functions in /etc/init.d/functions
such as daemon
to perform the following tasks?
STARTCMD='start-stop-daemon --start --exec /usr/sbin/swapspace --quiet --pidfile /var/run/swapspace.pid -- -d -p'
STOPCMD='start-stop-daemon --stop --oknodo --quiet --pidfile /var/run/swapspace.pid'
It looks like daemon
will work for the start command and killproc
is used for the stop command.
. /etc/init.d/functions
pushd /usr/sbin
daemon --pidfile /var/run/swapspace.pid /usr/sbin/swapspace
. /etc/init.d/functions
killproc -p $(cat /var/run/swapspace.pid)
Would the –oknodo be needed in the CentOS env (the swap file is really only boot-time)? "oknodo – Return exit status 0 instead of 1 if no actions are (would be) taken."
I don't see quiet in daemon
or killproc
, I can't imagine that it would matter though.
The original start-stop-daemon for swapspace seems to have both -p and –pidfile (the same command). That must be an error.
Did I miss anything? Any idea why daemon not create the pid file?
Best Answer
These are just shell functions defined in
/etc/rc.d/init.d/functions
. They're not as sophisticated asstart-stop-daemon
, but are pretty much what you have to work with on CentOS.daemon
andkillproc
don't have that option so you don't.daemon
will exit successfully if the process is already running so that's fine. I'm not sure howkillproc
will behave -- you may need to explicitly check whether the process is running before calling it.It's not:
--pidfile
is a parameter tostart-stop-daemon
, while-p
is a parameter toswapspace
. The--
separates parameters tostart-stop-daemon
from parameters to the process being started.You need to pass
-p
toswapspace
, like this: