Run Programs Automatically on Linux

Server Daemons

The Greeks considered daemons to be spirits that work in the background, so that’s why daemons are called daemons.

The “d” in systemd stands for “daemon,” following the Unix convention of naming background processes by appending a lowercase “d” to their name. This reflects that systemd is a system daemon responsible for managing other daemons and system processes.

Systemctl is the primary command-line interface used to interact with and control the systemd system and service manager.

/etc/rc.local

is deprecated according to ChatGPT.

Graphical Applications

Using a desktop file in the autostart folder.

lxde?

If running a version with desktop GUI, put the desktop file for the program you want to auto-start in:

~/.config/autostart

Run Programs that Run Regularly

Crontab and systemd both schedule running programs. Crontab is simpler and much older. Systemd is the newer standard. It’s more complex but more powerful including logging etc.

To show all the services running:

systemctl list-units --type=service

To show the path and contents of a systemd unit file of a specific service:

systemctl cat awim-fastapi.service

To check the status of a service:

systemctl status awim-fastapi.service

To restart the service:

sudo systemctl restart awim-fastapi.service