Auto start with systemd


Three standards to start a program upon boot:
1. System V aka sysV classic init: up to Ubuntu 9.04
2. Upstart: for Ubuntu 9.10 to 14.10
3. systemd Ubuntu 15.04 and higher
This is Ubuntu 18.04 LTS running on AWS ec2 m5, systemd, using sshd service as example.
Current runlevel is 5, as seen by $runlevel, and it’s mapped to graphical.target as seen by $ls -l /lib/systemd/system/runlevel5.target and can be confirmed by $systemctl get-default
Not sure why it’s defaulted to graphic as this system doesn’t even have graphics installed.
Both symbol links, /etc/systemd/system/sshd.service and /etc/systemd/system/multi-user.target.wants/ssh.service points to /lib/systemd/system/ssh.service
To enable a service, create such a link, which can be achieved by:
sudo systemctl enable sshd.service
How rc.local works:
/lib/systemd/system/rc.local.service -> /lib/systemd/system/rc-local.service
“ExecStart=/etc/rc.local start” is in rc-local.service
There is no symbol link of rc.local in /etc/systemd/ because it’s pulled by /lib/systemd/system-generators/systemd-rc-local-generator automatically, which is binary.

Advertisements