How to setup startup scripts in Ubuntu

Published by burgerboydaddy on Tue, 01/08/2013 - 14:48


For some projects I needed to run startup scripts everytime when I start my ubuntu server. Here is little how-to with addition how to run some processes using non-sudo username (normal user account).

After some searching I found out that there is a small command that allows the root to run a process as a different user.
So when I had put “sudo -u burgerboydaddy” in front of my command it worked flawlessly.

- use vim or an equivalent to write your script and make sure it starts with
- make your script executable by doing
chmod +x <filename>
- copy your script to /etc/init.d/<filename>
- run “update-rc.d <filename> defaults” (as root) you may wish to alter defaults but this is for more advanced use, defaults will probably suit your needs

Your script will now be ran every time your system boots, in order to remove the file from booting,
first remove the script then run “update-rc.d <filename> remove” (as root) all your startup links should now be removed.

If you want to run a program as a specific user- put “sudo -u <username>” in front of the command in your script.


Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.


Add new comment