Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm porting a Debian init.d script to CentOS. In the Debian script, it uses start-stop-daemon for launching the process. The script uses start-stop-daemon's --group flag to change to a different group-id when starting the daemon process.

How do I set the group-id of the daemon process in the init script on CentOS?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

CentOS init scripts use /etc/init.d/functions, which declares a "daemon" function that most other init scripts use. But daemon doesn't accept any group flags.

It ends up calling:

$nice runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $*"

A quick /sbin/runuser --help shows that runuser accepts a flag to specify group, so try:

runuser -g $group; daemon ...
share|improve this answer
add comment

If CentOS doesn't provide any better way (which would surprise me a little), you can fall back on su's lesser known counterpart, sg:

sg foogroup -c 'exec foodaemon --bar'
share|improve this answer
    
It would surprise me as well! I was hoping someone with more experience with CentOS than I would chime in. –  Lorin Hochstein Oct 22 '10 at 2:58
add comment

There is setuidgid: "setuidgid runs another program under a specified account's uid and gid."

It is part of daemontools, however, it probably is not available in the CentOS repositories due to DJBs strange licenses. So you might have to find a RPM (e.g. here) or build from source.

share|improve this answer
add comment

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.