exec script as user on boot not root

Is there a way to change a process owned by root to be owned by another user. I am interested in finding out if there is a way to put a script in /etc/rc2.d that will start up automatically on reboot that will not be owned by root

This is for security reasons.. The Service that runs on my server recomends that I dont run it as root..
Im at the office right now and I have the script on my home computer, if needed I can post it. But Im merly intressted if its possible and what command exec�s stuff as an assigned user. root -> run startTS.sh as user seb

Hi.

I don't suppose you can change the uid of a running process, but to run something at startup from /etc/rc.d, as a different user, use "su"

man su

ofc... its always the simplest solution...
Then Ill add

su seb

In the beginning of the script so the command that starts the service is run as user seb
For some reason I dident think logging on as a normal user at that stage worked. Kinda stupid now when I think about it. Heh thank you

Within the startup script /etc/rc2.d/Snnnxxxxx execute a script in another directory to do what you want.

su seb -c "script to be executed"

BTW. On many unixes rc3 is the place to start user applications (not rc2).

Thank you methyl. As you realise this is my first on boot script. I have done a handfull of diffrent scripts that manualy exec when thay are needed..

Ok so I will make a script in /etc/rc2.d/

su seb -c "/home/seb/tss/startservice.sh"

Did I understand you correct in this matter?

Hi.

Yes, exactly.

I would run it with "su -"

su - seb -c "/home/seb/tss/startservice.sh"

That way you get seb's environment too.

If you have a method to stop the application when you shutdown, don't forget to create a Knnnnnnn script too.

(the Snnnnn and Knnnnn scripts are often generic...)

case "$1" in
start )
        startsrc -g ssh
        ;;
stop )
        stopsrc -g ssh
        ;;
* )
        echo "Usage: $0 (start | stop)"
        exit 1
esac

The number you use for your S and K scripts determines the order in which your script is executed, so make sure everything else your application needs (i.e. Oracle, or whatever) is started before you start your application.

If you use "su - seb -c ......" you may need to edit your profile scripts and stop them running commands like "stty" which need a real terminal.

if [ -t 1 ]
then
      # Do commands which need a terminal
fi

I usually create a set of environment scripts for each application and call the appropriate script from startup scripts and user profiles. This is most useful for database engines such as Oracle.

See "man rc" for an explanation of startup script names etc. . Always test the scripts thoroughly before rebooting the machine. Remember to have a stop "K" script for every start "S" script and to stop in the reverse order you start.

Thanks alot for all the advice.. Ill start testing when I get home and got some time. Im currently at the office.