Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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. –  Herman Torjussen Mar 17 '12 at 16:47

2 Answers 2

up vote 8 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

 
discard

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.