I want to write an init service script which runs the program as a particular user (and not root). I will then chkconfig this script and install into my production run level.
I could just put a su command in the script but I was wondering if there is a best practise of doing this.
Thanks,
Garry
Best Answer
You can just
su
. You won't need the password because the script will initally be running as root.There's also the
runuser
command.If you use
/etc/init.d/functions
you can use thedaemon
function which has an option for specifying the user to run as.I'd personally sway towards the latter all other things being equal.