Execute command or code during boot on Linux with Systemd - /etc/rc.local
Instructions to execute code/commands for Linux at startup with Systemd.
For example Ubuntu 15.04 and above.
Please follow the instructions below.
Create a service and add this code:
sudo vi (or nano) /etc/systemd/system/rc-local.service
[Unit] Description=/etc/rc.local Compatibility
[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target
Create /etc/rc.local, add this code, and set the file executable:
sudo vi (or nano) /etc/rc.local
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # EXAMPLE:cpufreq-set -r -g performance
sudo chmod +x /etc/rc.local
Enable the service and reboot your machine:
sudo systemctl enable rc-local
sudo reboot now