Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've set up my /etc/rc.local to start some services using a couple of scripts to bring my system up on reboot.

One script runs as root and starts nginx, mysql, php etc... and works fine.

The other stuff runs as my regular user, so I'm doing a sudo and it doesn't seem to work at boot time. Is there a problem running as unprivileges users at this stage of the boot process?

My rc.local looks like this -

#!/bin/sh
touch /var/lock/subsys/local

# main system start - web server, db etc...
/root/start-services.sh

# services run as me
/usr/bin/sudo -u tim /home/vhosts/myapp/bin/start-app.sh

Running the scripts when the system is up, everything works fine. But at boot time none of the services in start-app.sh start up and I can't find any trace of any errors in any logs.

What have I done wrong here?

share|improve this question
2  
This doesn't address the question directly, but using something like Monit to handle this may be a better option. Monit is available as an RPM for CentOS in the DAG repo. –  cjc Aug 10 '12 at 12:37

2 Answers 2

up vote 4 down vote accepted

Try with:

su USER -c 'command &'
share|improve this answer
    
Bingo. Works. Thanks! –  Tim Aug 10 '12 at 13:17

You should try /usr/bin/sudo -u tim /home/vhosts/myapp/bin/start-app.sh 2>&1 1>/tmp/start-app.log to write stdout and stderr to a file.

share|improve this answer
    
stdout and stderr both empty. It appears the script never runs –  Tim Aug 10 '12 at 13:08

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.