Sysadmin:Launch at startup

From Earlham CS Department
Jump to navigation Jump to search

If you want to launch a program at startup, here's the process. It's controversial but systemd is the preferred approach to launching services at startup.

Make a service file

Go to /lib/systemd/system and create a myservice.service file (these are good defaults if you're not sure of all the specifications you need):

[Unit]
After=postgresql.service

[Service]
ExecStart=[mycommand]

[Install]
WantedBy=default.target

When you're happy with the unit file, copy it to /etc/systemd/system/..

If you're running a script directly at boot, make sure the script is executable or that you prepend sh or the appropriate shell to the ExecStart line.

  • chmod 664 /etc/systemd/system/[myservice].service
  • systemctl daemon-reload
  • systemctl enable [myservice].service

Test with:

  1. systemctl start [myservice].service
  2. systemctl status [myservice].service

Misc

Initial references: LinuxConfig, Linode

Some keyword spam for search purposes: login on boot bootup log in start up run process program