Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
This daemon helper tool makes a good start-stop-daemon replacement. It expects its argument program not to fork and takes care of restarting/stopping/checking if its running with the appropriate arguments. –  sr_ Apr 25 '13 at 6:17

1 Answer 1

up vote 2 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.