Operating System - HP-UX
1836639 Members
1802 Online
110102 Solutions
New Discussion

Re: startup app's with a different user/owner from root

 
SOLVED
Go to solution
A.K.
Frequent Advisor

startup app's with a different user/owner from root

Hi all,
I need to set application to start on startup
So I need to put it in /sbin/init.d and a link /sbin/rc#.d/ .
But what if I need it to start with a different user/owner from root?
Where do I specify it?

Thanks,
4 REPLIES 4
Shannon Petry
Honored Contributor

Re: startup app's with a different user/owner from root

if you look at the man page for su, you will see that it has an optio for selecting a user, and a -c option for running a command.

I.E. I use a different ID to start apache than root.

su - httpd -c /usr/local/sbin/run_apache.sh

The - runs the login scripts (.profile, .login) for the user "httpd". The -c option is the command I run as the user.

Regards,
Shannon
Microsoft. When do you want a virus today?
Sridhar Bhaskarla
Honored Contributor
Solution

Re: startup app's with a different user/owner from root

Hi,

Write a script that will start your application. call it say /home/user/bin/app.sh.

Create your startup and shutdown script for /sbin/init.d. Inside of it in the start portion do the following

su - user -c /home/user/bin/app.sh

You can write two scripts appstart.sh and appstop.sh and call them in start and stop portions of init script or, write one script that takes start and stop as the arguments and call them from init script.

-Sri

You may be disappointed if you fail, but you are doomed if you don't try
Hai Nguyen_1
Honored Contributor

Re: startup app's with a different user/owner from root

There are some threads on this in the forum already.

This is the syntax for root to run a command as another user:

# su - user_id /full_path_name/command

If the command requires some arguments, then use:

# su - user_id "/full_path_name/command arguments"

You can "man su" for more info.

Hai
Hai Nguyen_1
Honored Contributor

Re: startup app's with a different user/owner from root

"-c" is missing in my second syntax which should have read:

# su - user_id -c "/full..."

Hai