Linux’s init system

Install

Sudo pacman -S systemd

Systemctl

Software to configure the system’s OS Service that run at startup.

  • systemctl enable service to enable autostart of the service
  • systemctl disable service
  • systemctl start service runs the service
  • systemctl restart service

Creating Services

  1. vim /etc/systemd/system/myservice.service
[Unit]
Description=Serve site using npx serve
After=network.target
 
[Service]
Type=simple
WorkingDirectory=/path-to-work-with
ExecStart=/command-to-run
Restart=always
RestartSec=10
Environment=NODE_ENV=production
 
[Install]
WantedBy=multi-user.target
  1. sudo systemctl enable myservice.service
  2. sudo systemctl start myservice.service

Creating Userland Services

  1. apt install dbus-user-session dbus
  2. reboot
  3. mkdir -p ~/.config/systemd/user
  4. vim ~/.config/systemd/user/myservice.service
  5. Write the service file here
  6. systemctl