rc.local script in some Linux distributions and Unix systems is a superuser startup script, usually located under the directory
/etc/etc/rc.d. The file name rc refers to Run Control.
sudo vi /etc/rc.local sudo chmod +x /etc/rc.local #sudo chmod +x /etc/rc.d/rc.local
sudo systemctl enable rc-local sudo systemctl start rc-local.service sudo systemctl status rc-local.service
Systemd is a services manager who assigns services control groups (cgroup) and tracks processes. Systemd is the process (PID) 1 responsible for the system startup.
sudo vi /etc/systemd/system/linuxhint.service
[Unit] Description= <Script name or description> [Service] ExecStart=/bin/bash /usr/sbin/linuxhint.sh #in this line specify the path to the script. [Install] WantedBy=multi-user.target
#sudo systemctl enable linuxhint sudo systemctl start linuxhint sudo systemctl status linuxhint
- Description= This directive describes the unit; you can set the unit name.
- Requires= Here, you can specify dependencies to prevent startup failures.
- Wants= Like the previous, it keeps the service working even if it doesn’t find the defined dependencies.
- After= The unit will start after the specified in this directive.
- Type= In the example shown above, forking indicates the service will be killed, keeping child processes that must be assigned a PID.
- PIDFile= Forking directive requires the PIDFile directive, which must contain the path to the file pid of the child process for Systemd to identify it.
- ExecStart= Here, you specify the path and commands you want to be executed. This is similar to the rc.local file.
- Restart= This directive instructs Systemd when to restart the unit. The available options are on-failure, on-abort, always, on-success, on-watchdog, or on-abnormal.
- StartLimitInterval= This directive indicates the unit has 60 seconds for 10 attempts to restart upon failure.
- StartLimitBurst= This directive indicates the attempts limit, in the example above, 10 attempts in 60 seconds.
- WantedBy= Here, you can specify this unit as a dependency; it is similar to the Wants directive, but to define the current unit is considered a dependency by another unit.
Note: You can check all Systemd directives at https://www.freedesktop.org/software/systemd/man/systemd.directives.html
sudo systemctl stop linuxhint sudo systemctl disable linuxhint sudo rm /etc/systemd/system/linuxhint.service #sudo rm /etc/systemd/system/xxx symlinks that might be related sudo systemctl daemon-reload sudo systemctl reset-failed