0

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?

mtak
  • 17,262
StarLord
  • 101

1 Answers1

0

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:

[Unit]
Description=Description of service
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/path/to/script

[Install]
WantedBy=multi-user.target

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

mtak
  • 17,262