WEIGEL FORUM
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    Systemd Services

    Linux
    1
    1
    8
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DerMeldosD
      DerMeldos
      last edited by

      You can look at existing services for inspiration.

      root@QBIT0718:~# systemctl cat sshd.service 
      # /lib/systemd/system/ssh.service
      [Unit]
      Description=OpenBSD Secure Shell server
      Documentation=man:sshd(8) man:sshd_config(5)
      After=network.target auditd.service
      ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
      
      [Service]
      EnvironmentFile=-/etc/default/ssh
      ExecStartPre=/usr/sbin/sshd -t
      ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
      ExecReload=/usr/sbin/sshd -t
      ExecReload=/bin/kill -HUP $MAINPID
      KillMode=process
      Restart=on-failure
      RestartPreventExitStatus=255
      Type=notify
      RuntimeDirectory=sshd
      RuntimeDirectoryMode=0755
      
      [Install]
      WantedBy=multi-user.target
      Alias=sshd.service
      

      Please also look at the manpage of systemd for more details and options on service configuration.

      Services can be created in "/etc/systemd/system/"

      root@QBIT0718:~# ls /etc/systemd/system/
      cross-seed.service                      getty.target.wants           qbittorrent-nox.service  sshd.service
      cross-seed.service.save                 multi-user.target.wants      remote-fs.target.wants   sysinit.target.wants
      dbus-org.freedesktop.timesync1.service  network-online.target.wants  sockets.target.wants     timers.target.wants
      

      Basic Systemctl Commands:

      systemctl enable sshd.service
      systemctl start sshd.service
      systemctl disable sshd.service  
      systemctl stop sshd.service
      systemctl restart sshd.service
      systemctl reload sshd.service    #reload is not as harsh as restart
      systemctl daemon-reload   #reloads systemd, its needed after adding a service for example
      

      To View all services on the system if running or not use below command:

      systemctl list-units --type service --all
      

      Example Output:

      root@QBIT0718:~# systemctl list-units --type service --all
        UNIT                                 LOAD      ACTIVE   SUB     DESCRIPTION                                            
        apparmor.service                     loaded    active   exited  Load AppArmor profiles
        apt-daily-upgrade.service            loaded    inactive dead    Daily apt upgrade and clean activities
        apt-daily.service                    loaded    inactive dead    Daily apt download activities
      ● auditd.service                       not-found inactive dead    auditd.service
        auth-rpcgss-module.service           loaded    inactive dead    Kernel Module supporting RPCSEC_GSS
      ● connman.service                      not-found inactive dead    connman.service
      ● console-screen.service               not-found inactive dead    console-screen.service
        console-setup.service                loaded    active   exited  Set console font and keymap
        cron.service                         loaded    active   running Regular background program processing daemon
        cross-seed.service                   loaded    active   running cross-seed daemon
        dbus.service                         loaded    active   running D-Bus System Message Bus
      ● display-manager.service              not-found inactive dead    display-manager.service
        dpkg-db-backup.service               loaded    inactive dead    Daily dpkg database backup service
        e2scrub_all.service                  loaded    inactive dead    Online ext4 Metadata Check for All Filesystems
        e2scrub_reap.service                 loaded    inactive dead    Remove Stale Online ext4 Metadata Check Snapshots
        emergency.service                    loaded    inactive dead    Emergency Shell
        fstrim.service                       loaded    inactive dead    Discard unused blocks on filesystems from /etc/fstab
        getty-static.service                 loaded    inactive dead    getty on tty2-tty6 if dbus and logind are not available
        getty@tty1.service                   loaded    active   running Getty on tty1
      ● gssproxy.service                     not-found inactive dead    gssproxy.service
        ifup@ens18.service                   loaded    active   exited  ifup for ens18
        ifupdown-pre.service                 loaded    active   exited  Helper to synchronize boot up for ifupdown
        initrd-cleanup.service               loaded    inactive dead    Cleaning Up and Shutting Down Daemons
        initrd-parse-etc.service             loaded    inactive dead    Mountpoints Configured in the Real Root
        initrd-switch-root.service           loaded    inactive dead    Switch Root
        initrd-udevadm-cleanup-db.service    loaded    inactive dead    Cleanup udev Database
      ● kbd.service                          not-found inactive dead    kbd.service
        keyboard-setup.service               loaded    active   exited  Set the console keyboard layout
        kmod-static-nodes.service            loaded    active   exited  Create List of Static Device Nodes
        logrotate.service                    loaded    inactive dead    Rotate log files
        man-db.service                       loaded    inactive dead    Daily man-db regeneration
        modprobe@configfs.service            loaded    inactive dead    Load Kernel Module configfs
        modprobe@dm_mod.service              loaded    inactive dead    Load Kernel Module dm_mod
        modprobe@drm.service                 loaded    inactive dead    Load Kernel Module drm
        modprobe@efi_pstore.service          loaded    inactive dead    Load Kernel Module efi_pstore
        modprobe@fuse.service                loaded    inactive dead    Load Kernel Module fuse
        modprobe@loop.service                loaded    inactive dead    Load Kernel Module loop
        networking.service                   loaded    active   exited  Raise network interfaces
      ● NetworkManager.service               not-found inactive dead    NetworkManager.service
      ● nfs-server.service                   not-found inactive dead    nfs-server.service
        nfs-utils.service                    loaded    inactive dead    NFS server and client services
      ● plymouth-quit-wait.service           not-found inactive dead    plymouth-quit-wait.service
      ● plymouth-start.service               not-found inactive dead    plymouth-start.service
        qbittorrent-nox.service              loaded    active   running qBittorrent Command Line Client
        rc-local.service                     loaded    inactive dead    /etc/rc.local Compatibility
        rescue.service                       loaded    inactive dead    Rescue Shell
        rpc-gssd.service                     loaded    inactive dead    RPC security service for NFS client and server
        rpc-statd-notify.service             loaded    active   exited  Notify NFS peers of a restart
        rpc-statd.service                    loaded    active   running NFS status monitor for NFSv2/3 locking.
        rpc-svcgssd.service                  loaded    inactive dead    RPC security service for NFS server
        rpcbind.service                      loaded    active   running RPC bind portmap service
        snmpd.service                        loaded    active   running Simple Network Management Protocol (SNMP) Daemon.
        ssh.service                          loaded    active   running OpenBSD Secure Shell server
      ● syslog.service                       not-found inactive dead    syslog.service
        systemd-ask-password-console.service loaded    inactive dead    Dispatch Password Requests to Console
        systemd-ask-password-wall.service    loaded    inactive dead    Forward Password Requests to Wall
        systemd-binfmt.service               loaded    active   exited  Set Up Additional Binary Formats
        systemd-firstboot.service            loaded    inactive dead    First Boot Wizard
        systemd-fsck-root.service            loaded    inactive dead    File System Check on Root Device
        systemd-fsckd.service                loaded    inactive dead    File System Check Daemon to report status
      ● systemd-hwdb-update.service          not-found inactive dead    systemd-hwdb-update.service
        systemd-initctl.service              loaded    inactive dead    initctl Compatibility Daemon
        systemd-journal-flush.service        loaded    active   exited  Flush Journal to Persistent Storage
        systemd-journald.service             loaded    active   running Journal Service
        systemd-logind.service               loaded    active   running User Login Management
        systemd-machine-id-commit.service    loaded    inactive dead    Commit a transient machine-id on disk
        systemd-modules-load.service         loaded    active   exited  Load Kernel Modules
        systemd-networkd.service             loaded    inactive dead    Network Configuration
      ● systemd-oomd.service                 not-found inactive dead    systemd-oomd.service
        systemd-pcrphase-initrd.service      loaded    inactive dead    TPM2 PCR Barrier (initrd)
        systemd-pcrphase-sysinit.service     loaded    inactive dead    TPM2 PCR Barrier (Initialization)
        systemd-pcrphase.service             loaded    inactive dead    TPM2 PCR Barrier (User)
        systemd-pstore.service               loaded    inactive dead    Platform Persistent Storage Archival
        systemd-random-seed.service          loaded    active   exited  Load/Save Random Seed
        systemd-remount-fs.service           loaded    active   exited  Remount Root and Kernel File Systems
        systemd-repart.service               loaded    inactive dead    Repartition Root Disk
        systemd-sysctl.service               loaded    active   exited  Apply Kernel Variables
        systemd-sysext.service               loaded    inactive dead    Merge System Extension Images into /usr/ and /opt/
        systemd-sysusers.service             loaded    active   exited  Create System Users
        systemd-timesyncd.service            loaded    active   running Network Time Synchronization
        systemd-tmpfiles-clean.service       loaded    inactive dead    Cleanup of Temporary Directories
        systemd-tmpfiles-setup-dev.service   loaded    active   exited  Create Static Device Nodes in /dev
        systemd-tmpfiles-setup.service       loaded    active   exited  Create System Files and Directories
        systemd-udev-settle.service          loaded    inactive dead    Wait for udev To Complete Device Initialization
        systemd-udev-trigger.service         loaded    active   exited  Coldplug All udev Devices
        systemd-udevd.service                loaded    active   running Rule-based Manager for Device Events and Files
      ● systemd-update-done.service          not-found inactive dead    systemd-update-done.service
        systemd-update-utmp-runlevel.service loaded    inactive dead    Record Runlevel Change in UTMP
        systemd-update-utmp.service          loaded    active   exited  Record System Boot/Shutdown in UTMP
        systemd-user-sessions.service        loaded    active   exited  Permit User Sessions
      ● systemd-vconsole-setup.service       not-found inactive dead    systemd-vconsole-setup.service
        user-runtime-dir@0.service           loaded    active   exited  User Runtime Directory /run/user/0
        user@0.service                       loaded    active   running User Manager for UID 0
        wazuh-agent.service                  loaded    active   running Wazuh agent
        wg-quick@wg0.service                 loaded    active   exited  WireGuard via wg-quick(8) for wg0
      
      LOAD   = Reflects whether the unit definition was properly loaded.
      ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
      SUB    = The low-level unit activation state, values depend on unit type.
      95 loaded units listed.
      To show all installed unit files use 'systemctl list-unit-files'.
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB | Contributors