How Setup Startup Scripts Ubuntu

Tue, Jan 8, 2013 1-minute read

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 running command:
    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 ” in front of the command in your script.