3

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?

Tim
  • 584
  • 2
  • 9
  • 20
  • 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 Answers2

4

Try with:

su USER -c 'command &'
golja
  • 1,621
  • 10
  • 14
2

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.

Alex
  • 7,939
  • 6
  • 38
  • 52