Centos – Port to use CentOS init.d functions

centos

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

It looks like daemon will work for the start command and killproc is used for the stop command.

These are just shell functions defined in /etc/rc.d/init.d/functions. They're not as sophisticated as start-stop-daemon, but are pretty much what you have to work with on CentOS.

Would the --oknodo be needed in the CentOS env (the swap file is really only boot-time)?

daemon and killproc 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 how killproc will behave -- you may need to explicitly check whether the process is running before calling it.

The original start-stop-daemon for swapspace seems to have both -p and --pidfile (the same command). That must be an error.

It's not: --pidfile is a parameter to start-stop-daemon, while -p is a parameter to swapspace. The -- separates parameters to start-stop-daemon from parameters to the process being started.

Did I miss anything? Any idea why daemon not create the pid file?

You need to pass -p to swapspace, like this:

daemon --pidfile /var/run/swapspace.pid /usr/sbin/swapspace -p