how to run script at boot using systemd
Example I have script to run at boot
Create your own script, my example is start-myscript.sh
Make that the script executable with:
chmod u+x /usr/local/bin/start-myscript.sh
And then create a file named end with .service, this file will be used to call the start-myscript.sh, example: myscript.service file should look like this:
[Unit]
Description=My Script
[Service]
ExecStart=/usr/local/bin/start-myscript.sh
[Install]
WantedBy=multi-user.target
Now do a few more steps to enable and use the .service file:
Place it in /lib/systemd/system folder with say a name of myscript.service
Start it:
sudo systemctl start myscript
Enable it to run at boot:
sudo systemctl enable myscript
Stop it:
sudo systemctl stop myscript
Create your own script, my example is start-myscript.sh
Make that the script executable with:
chmod u+x /usr/local/bin/start-myscript.sh
And then create a file named end with .service, this file will be used to call the start-myscript.sh, example: myscript.service file should look like this:
[Unit]
Description=My Script
[Service]
ExecStart=/usr/local/bin/start-myscript.sh
[Install]
WantedBy=multi-user.target
Now do a few more steps to enable and use the .service file:
Place it in /lib/systemd/system folder with say a name of myscript.service
Start it:
sudo systemctl start myscript
Enable it to run at boot:
sudo systemctl enable myscript
Stop it:
sudo systemctl stop myscript
Komentar