Tag Archives: Ubuntu

Adding a startup script as a service in Ubuntu

I write this up because I don’t want to look it up everytime I need it. This will create a simple service that executes a script in Ubuntu systemd.

 

1. Create a file: /etc/systemd/system/service-name.service

[Unit]
Description=Some Description of your service
After=network.target
After=systemd-user-sessions.service
After=network-online.target

[Service]
User=root
Type=simple
ExecStart=/path/to/your/script/start-all.sh
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10

[Install]
WantedBy=multi-user.target

2. Reload systemd

systemctl daemon-reload

3. Make that your script executable with:

chmod u+x /path/to/your/script/start-all.sh

4. Start it:

sudo systemctl start service-name

5. Enable it to run at boot

sudo systemctl enable service-name

tip: #!/bin/sh is necessary at the beginning of the script or startup will fail with error 203