6

I am using Arch Linux.

I need to start my web application automatically should the server should restart. I need to run it as user 'www'.

How can I do this?

Kevin
  • 40,767
t123
  • 193
  • 1
    To run a command as user www you could use:sudo -u www some_command. –  Mar 17 '12 at 16:47

2 Answers2

13

You need to write an init script for your web application. (Examples for Dropbox and RTorrent. You can find more examples if you search the wiki for add_daemon.)

Your script would use su to run the application as the appropriate user. (Init scripts run as root, so they can su to any user.)

The critical line would look something like

su www -c "/path/of/app &"

Then you would add your new daemon to the DAEMONS list in /etc/rc.conf, so it will be started automatically after booting.

cjm
  • 27,160
5

Use su to run it as the user, and put it into your /etc/rc.local to run it at boot.

su -c "start_server" www &
Kevin
  • 40,767