Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
To run a command as user www you could use:sudo -u www some_command. – user13742 Mar 17 '12 at 16:47
up vote 10 down vote accepted

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.

share|improve this answer

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 &
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.