Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to run a command on startup on my Ubuntu Server. Does anyone know how to do this? Does /etc/rc.local run as superuser? Any help will be appreciated. Thanks!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

/etc/rc.local will run as root.

Most of the init process is run as root, or starts out that way.

share|improve this answer
add comment

There's a couple of places you can do this:

/etc/init.d (and then making a link to /etc/rc[runlevel].d - usually 2) works pretty well - so you can specify start up and shut down bits in there.

That's kind of an old way (though oh so very easy). You can also do something with upstart. Look at this page (look at the "Writing Jobs" section).

The big gotcha - the path is normally not quite what you'd expect. So I'd suggest running something along the lines of "echo $PATH > /init_path" from whatever script first to see if you might have an issue (check /init_path and see what's in there.. perfectly safe to remove this file). While it's easy to specify paths in your script, it's worth setting the PATH variable accordingly as anything run from whatever script may also need things in PATH.

share|improve this answer
add comment

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.