Sobes.tech
Junior — Middle

What methods can be used to set an application to automatically start on system boot in Linux?

sobes.tech AI

Answer from AI

In Linux, there are several ways to set up an application to automatically start at system boot:

  1. systemd service — a modern and recommended method. A unit file is created in /etc/systemd/system/ or ~/.config/systemd/user/, describing how to start the application. The service is then enabled with the command systemctl enable service_name.

  2. init.d scripts — an older method for systems with SysVinit. Scripts are placed in /etc/init.d/ and added to the desired runlevels using update-rc.d or chkconfig.

  3. crontab with @reboot — you can add a task to crontab with the directive @reboot so that the command runs at startup.

  4. Autostart in user session — for graphical environments, you can add a script or shortcut to the autostart folder, for example ~/.config/autostart/.

Example of a systemd unit file:

[Unit]
Description=My Application
After=network.target

[Service]
ExecStart=/usr/local/bin/myapp
Restart=always

[Install]
WantedBy=multi-user.target

After creating the file, you need to execute:

sudo systemctl daemon-reload
sudo systemctl enable myapp.service
sudo systemctl start myapp.service
What methods can be used to set an application to… - sobes.tech