2

I have a init.d script that start|stops|restarts a daemon using the start-stop-daemon.

This daemon is always started as root. I want to be able to specify the user that the init.d script will use to start the daemon.

Tried using the --user option for start-stop-daemon but that is not working.

Can someone please suggest how to do this.

2
  • 1
    You might want look at /etc/init.d/functions: the daemon function already allows you to set an alternate user: daemon --user=my_user my_cmd &>/dev/null & This is implemented by wrapping the process invocation with runuser - more on this later. Sep 8, 2012 at 9:30
  • Acutally i have a init.d script. it calles the start-stop-daemon which also allows me to set the user and group, which I am doing. For some reason this is not working though.
    – kapad
    Sep 8, 2012 at 12:12

1 Answer 1

0

As Ubuntu is converting away from sysvinit to upstart, I'd suggest that you convert your script to an upstart job in the /etc/init/ directory instead. The man page is man 5 init.

There are setuid and setgid items to set the user and group under which the upstart job is run.


Assuming your script execs another script, I suppose you can add the su userid command to it to change the effective uid and gid to that of its argument. I'm uncertain whether its safe to run su in the sysvinit script itself without it changing these for subsequent /etc/init.d/ scripts, but perhaps that's OK, too.

3
  • Thanks. I'll try this. But do you know how to do this for an init.d script. I already have that script ready and I need to make this change ASAP.
    – kapad
    Sep 9, 2012 at 14:12
  • Added another idea, don't know if its feasible. Sep 9, 2012 at 14:43
  • Ya. Ill try the second one now. The first one didn't work for some reason. I saw the man pages for start-stop-daemon and it should work according to those pages, but didn't.
    – kapad
    Sep 28, 2012 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .