🐧
Linux
  • Introduction
  • 🖇️general
    • essentials
    • other commands
    • Superuser-do (sudo)
    • SUID, SGID, sticky bit
    • /dev/null
    • environment variables
    • special variables
    • shebang
  • spool
  • 🔧bash
    • overview
    • redirection
    • loop
    • .bashrc
  • text processing
    • grep
    • sed
    • awk
  • xxd/hexdump
  • text editors
    • nano
    • vi/vim
  • 📂filesystem & directories
    • Filesystem Hierachy Standard (FHS)
      • /etc
        • hosts, hosts.allow, hosts.deny
        • /cron.d
        • /httpd
        • /samba.d
        • hostname
        • crontab
        • shadow
        • passwd
        • profile
        • services
      • /dev
      • /proc
        • version
      • /mnt
      • /opt
      • /sbin
      • /lib
      • /usr
      • /tmp
      • /var
      • /bin
      • /run
    • chroot
  • find
  • locate
  • ⌚processes & jobs
    • cronjob
    • daemon
  • ⛓️system
    • systemctl
    • hostname
    • systemd
  • 🗃️media
    • ffmpeg
    • pdftk
  • 🔒Security
    • ufw
  • firejail
  • apparmor
  • 📦Package management
    • dpkg
    • apt/apt-get
  • Storage
    • lsblk
    • mount/umount
  • df/du
  • user management
    • chsh
  • Networking
    • Introduction
    • routing table/interface management
    • /etc/hosts, /etc/hosts.allow, /etc/hosts.deny
Powered by GitBook
On this page
  1. system

systemd

To add a systemd service, simply add a file with the .service extension in the /etc/systemd/system directory.

Basic systemd service configuration file:

[Unit]
Description=[description]
After=network.target  # Script runs after the network is UP

[Service]
ExecStart=/path/to/script.sh
Restart=always  # Script will restart if it fails
User=root # run as the root user

[Install]
WantedBy=multi-user.target  # Services start at boot

The script /path/to/script.sh will be executed by the root user after the network is UP.

Start the service

systemctl daemon-reload
systemctl enable [name_of_service].service

Common errors

  1. ExecStart

  • Script path not found

  • Script is not executable

  • Script does not contain shebang (#!) — alternatively, include shell path before the script path

Eg. /bin/bash /path/to/script.sh

PrevioushostnameNextffmpeg

Last updated 2 months ago

⛓️