This question already has an answer here:

I have a script that is used to start my application and it works fine. However the issue is that I need to be able to execute that script automatically at boot up in case of a power failure or a reboot. Could anyone please guide me as to how can I do this?

marked as duplicate by MariusMatutiae linux May 24 '17 at 9:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Normally services that are supposed to be always up are controlled by systemd (in newer versions of Ubuntu). You can create your own systemd configuration. If you just want to run the script, create the following file in /etc/systemd/system/servicename.service:

Description=Description of service



Then reload the systemd configuration and enable the service at boot time:

$ systemctl daemon-reload
$ systemctl enable servicename
$ systemctl start servicename

However, you can also have systemd start the process directly, without involving the script. In that case, systemd will restart the process when it dies. A fairly comprehensive guide can be found on https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

  • I did try this and created my service file, however after reboot the script did not execute, is there someplace where I can see the logs as to what is happening wrong. – StarLord May 23 '17 at 19:05
  • journalctl -u servicename – mtak May 23 '17 at 20:34
  • With this config the process will not restart if you kill the process. – bronze man Mar 19 '18 at 8:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.