Page 1 of 1

Starting a service as a different user

Posted: 2015/11/04 16:22:01
by jordend
Hi,

I have my CentOS box running a backup server and I want it to automatically run two services at startup as a specific user. Any help with this would be greatly appreciated. Thanks!

Re: Starting a service as a different user

Posted: 2015/11/04 17:44:57
by aks
Depends on the program(s) involved. You should really look at using systemd, but that too depends on the programs and how they behave.

From the shell (so a script too), you could use su <user> -c "<commands_to_run> > <log_file> 2>&1 " &

Re: Starting a service as a different user

Posted: 2015/11/04 17:46:35
by jordend
Where would I put that script for it to start that service at startup?

Re: Starting a service as a different user

Posted: 2015/11/04 18:04:55
by TrevorH
Systemd unit files should go in /etc/systemd/system and you can look in /usr/lib/systemd/system for examples of others that are already in use to find one similar to the things you want to do. I believe the correct thing to put in the unit file would be User=youruser

Re: Starting a service as a different user

Posted: 2015/11/04 21:50:47
by jordend
Well, after all that, I found out from the vendor that this has to be ran as root. :/

Re: Starting a service as a different user

Posted: 2015/11/05 18:52:36
by aks
That's not good :twisted:
Complain and tell them your giving them money for what amounts to the crappiest of crap....