visit
In this article, we will configure our Linux computer to autorun a script on boot. For the purpose of this article, we will be making use of systemd
services.
The main command used to introspect and control systemd is systemctl
.
First, we will create a Bash script in /usr/local/sbin
, for instance [notifyRemote.sh]
(//notifyRemote.sh)
, that would notify a remote machine once it’s booted.
sudo chmod +x /usr/local/sbin/notifyRemote.sh
Create a Unit file called startup.service
in /etc/systemd/system/
to define a systemd service. You will need root access (sudo
) to make changes or create these files.
sudo chmod +x /etc/systemd/system/startup.service
In /etc/systemd/system/startup.service
, we would paste the below into the file as such:
[Unit]
Description=My Startup
[Service]
ExecStart=/usr/local/sbin/notifyRemote.sh
[Install]
WantedBy=multi.user.target
The ExecStart is the most important key here because it points to the Bash program that will run when the service is started.
We can test the service by running sudo systemctl start startup.service
to confirm that the script will run.
sudo systemctl enable startup.service