How to start a script at boot?

There are a bunch of how-tos out there:

https://www.howtogeek.com/687970/how-to-run-a-linux-program-at-startup-with-systemd/

In short, create your script,
copy it to /usr/local/bin,
make it executable

create a service file (cribbd from How-To Geek)
/etc/systemd/system/myService.service

[Unit]
Description=Service Example
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
ExecStart=/usr/local/bin/myService.sh
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target

Make sure the service is executable.

If it’s a one shot:

[Unit]
Description=Simple Example
ConditionFirstBoot=yes
[Service]
Type=oneshot
ExecStart=/usr/local/bin/myService.sh
[Install]
WantedBy=multi-user.target

It’s a bit more tidy than putting everything in rc.local. But I do miss rc.local :slight_smile:

3 Likes