Operating System - Linux
1831483 Members
3360 Online
110025 Solutions
New Discussion

start stop scripts for application

 
Jon Gomersall
Advisor

start stop scripts for application

I need to start and stop an application by a specific user NOT root..

6 REPLIES 6
Patrick Terlisten
Honored Contributor

Re: start stop scripts for application

Hello,

try running "su $USERNAME -c $COMMAND".

Hope this helps.

Best regards,
Patrick
Best regards,
Patrick
Ivan Ferreira
Honored Contributor

Re: start stop scripts for application

Does that means that you want that a normal user (not root) should be able to start an application? If so, use SUDO.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Jon Gomersall
Advisor

Re: start stop scripts for application

I want to start an appication as a specific user when the server boots up...

Also need to shutdown the applications as the same user on system shutdown.



Ben Stokes
Frequent Advisor

Re: start stop scripts for application

e.g. If your user is called jim and your application is /home/jim/application, you could add this to /etc/rc.d/rc.local:

su -c '/home/jim/application' jim &
Jared Middleton
Frequent Advisor

Re: start stop scripts for application

One possible example...

/etc/init.d/myapp:
-------------
#!/bin/sh
#
# chkconfig: 235 99 10
# description: myapp Startup/Shutdown Script

case "$1" in
start)
su -c "/app/start_myapp - USERID
touch /var/lock/subsys/myapp
;;
stop)
su -c "/app/stop_myapp - USERID
rm -f /var/lock/subsys/myapp
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac
-------------
Stuart Browne
Honored Contributor

Re: start stop scripts for application

You might also want to look at the 'runuser' command.

It will do basically the same thing for what you're intending, but bypasses some of the PAM checks.

If you're on a RedHat/Centos system, you might also want to use the built-in 'functions' that are available to the init.d startup/shutdown commands, in particular the 'daemon' command (with the '--user ' flag). This wraps various things and ends up calling 'runuser', but also logs it in the same fashion as all the other commands.

The 'killproc' routine however doesn't have any as-user support however.
One long-haired git at your service...