home       inleiding       sysadmin       services       links       bash       werk       nothing      

daemon administratie: systemctl

Sedert 2016 gebruiken redhat, debian, ubuntu en linux mint het pakket systemd voor service beheer
Een uitgebreide uitleg vind je hier: digital ocean systemd.
 
we gebruiken eerst de service SSHd om service beheer te illustreren; daarvoor moeten we eerst de ssh service installeren. dat kan met:
 
$ sudo apt install openssh-server
 
 
We tonen kort de belangrijkste funkties:
 

  1. status van open-ssh tonen: [systemctl status naam.service]
     
    user@mint18-srv ~ $ sudo systemctl status ssh.service
    ● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
    Active: active (running) since Wed 2017-05-31 15:19:38 CEST; 1h 8min ago
    Main PID: 2620 (sshd)
    CGroup: /system.slice/ssh.service
           └─2620 /usr/sbin/sshd -D
     
    May 31 15:19:38 mint18-srv systemd[1]: Starting OpenBSD Secure Shell server...
    May 31 15:19:38 mint18-srv sshd[2620]: Server listening on 0.0.0.0 port 22.
    May 31 15:19:38 mint18-srv sshd[2620]: Server listening on :: port 22.
    May 31 15:19:38 mint18-srv systemd[1]: Started OpenBSD Secure Shell server.
    May 31 15:55:57 mint18-srv sshd[2924]: Accepted password for bert from 127.0.0.1
    May 31 15:55:57 mint18-srv sshd[2924]: pam_unix(sshd:session): session opened ..

     

  2. ssh-daemon stoppen: [systemctl stop naam.service]
     
    user@mint18-srv ~ $ sudo systemctl stop ssh.service
    (de command line zegt niets we moeten de status opvragen ...)
    user@mint18-srv ~ $ systemctl status ssh.service
    ● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
    Active: inactive (dead) since Wed 2017-05-31 16:31:10 CEST; 4s ago
    Main PID: 2620 (code=exited, status=0/SUCCESS)
    ...
    May 31 16:31:10 mint18-srv systemd[1]: Stopping OpenBSD Secure Shell server...
    May 31 16:31:10 mint18-srv systemd[1]: Stopped OpenBSD Secure Shell server.

     

  3. ssh-daemon starten: [systemctl start naam.service]
     
    user@mint18-srv ~ $ sudo systemctl start ssh.service
    user@mint18-srv ~ $ systemctl status ssh.service
    ● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2017-05-31 16:36:19 CEST; 5s ago
    Main PID: 3046 (sshd)
    CGroup: /system.slice/ssh.service
           └─3046 /usr/sbin/sshd -D
    May 31 16:36:19 mint18-srv systemd[1]: Starting OpenBSD Secure Shell server...
    May 31 16:36:19 mint18-srv sshd[3046]: Server listening on 0.0.0.0 port 22.
    May 31 16:36:19 mint18-srv sshd[3046]: Server listening on :: port 22.
    May 31 16:36:19 mint18-srv systemd[1]: Started OpenBSD Secure Shell server.

     

  4. ssh-daemon herstarten: [systemctl restart naam.service]
     
    herstarten is een stop gevolgd door een start
     
    user@mint18-srv ~ $ sudo systemctl restart ssh.service
    user@mint18-srv ~ $ systemctl status ssh.service
    ● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2017-05-31 16:40:56 CEST; 1s ago
    Main PID: 3055 (sshd)
    CGroup: /system.slice/ssh.service
           └─3055 /usr/sbin/sshd -D
    May 31 16:40:56 mint18-srv systemd[1]: Starting OpenBSD Secure Shell server...
    May 31 16:40:56 mint18-srv sshd[3055]: Server listening on 0.0.0.0 port 22.
    May 31 16:40:56 mint18-srv sshd[3055]: Server listening on :: port 22.
    May 31 16:40:56 mint18-srv systemd[1]: Started OpenBSD Secure Shell server.

    Merk op dat de PID veranderd is van 3046 naar 3055
     

  5. ssh-daemon reloaden: [systemctl reload naam.service]
     
    reloaden is een herinladen van de config-file (meestal na aanpassingen)
     
    user@mint18-srv ~ $ sudo systemctl reload ssh.service
    user@mint18-srv ~ $ systemctl status ssh.service
    ● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2017-05-31 16:40:56 CEST; 4min 21s ago
    Process: 3064 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
    Main PID: 3055 (sshd)
    CGroup: /system.slice/ssh.service
           └─3055 /usr/sbin/sshd -D
    May 31 16:40:56 mint18-srv systemd[1]: Starting OpenBSD Secure Shell server...
    May 31 16:40:56 mint18-srv sshd[3055]: Server listening on 0.0.0.0 port 22.
    May 31 16:40:56 mint18-srv sshd[3055]: Server listening on :: port 22.
    May 31 16:40:56 mint18-srv systemd[1]: Started OpenBSD Secure Shell server.
    May 31 16:45:16 mint18-srv systemd[1]: Reloading OpenBSD Secure Shell server.
    May 31 16:45:16 mint18-srv sshd[3055]: Received SIGHUP; restarting.
    May 31 16:45:16 mint18-srv systemd[1]: Reloaded OpenBSD Secure Shell server.
    May 31 16:45:16 mint18-srv sshd[3055]: Server listening on 0.0.0.0 port 22.

    De PID is nu gelijk gebleven ...
     

  6. ssh-daemon dis-ablen: [systemctl disable naam.service]
     
    disable, betekent dat de service niet meer automatisch wordt opgestart bij booten van je server
     
    user@mint18-srv ~ $ sudo systemctl disable ssh.service
    Synchronizing state of ssh.service with SysV init with /lib/systemd/systemd-sysv-install...
    Executing /lib/systemd/systemd-sysv-install disable ssh
    insserv: warning: current start runlevel(s) (empty) of script `ssh' overrides LSB defaults (2 3 4 5).
    insserv: warning: current stop runlevel(s) (2 3 4 5) of script `ssh' overrides LSB defaults (empty).
    Removed symlink /etc/systemd/system/sshd.service.

    user@mint18-srv ~ $ systemctl status ssh.service

    ● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: enabled)
    Active: active (running) since di 2017-06-06 12:32:52 CEST; 6h ago

    Hoewel bij de volgende system restart de service niet meer automatisch zal opstarten, wordt die nu met rust gelaten, en blijft de ssh.service draaien.
     
    We herstarten de machine:
    user@mint18-srv ~ ~$ sudo init 6
    Connection to 192.168.5.240 closed by remote host. Connection to 192.168.5.240 closed.
     
    ... en proberen nadien terug in te loggen:
    frank@system3 ~ $ ssh user@192.168.5.240
    ssh: connect to host 192.168.5.240 port 22: Connection refused
     

  7. ssh-daemon en-ablen: [systemctl enable naam.service]
     
    enable, betekent dat de service automatisch zal worden opgestart bij elke boot van je server.
    bij het installeren van een service met apt wordt een service normaal gezien automatisch ge-enabled.
     
    user@mint18-srv ~ $ sudo systemctl enable ssh.service
    Synchronizing state of ssh.service with SysV init with /lib/systemd/systemd-sysv-install...
    Executing /lib/systemd/systemd-sysv-install enable ssh
    insserv: warning: current start runlevel(s) (empty) of script `ssh' overrides LSB defaults (2 3 4 5).
    insserv: warning: current stop runlevel(s) (2 3 4 5) of script `ssh' overrides LSB defaults (empty).
    Created symlink from /etc/systemd/system/sshd.service to /lib/systemd/system/ssh.service.

     
    niet van toepassing:
     
    oefening: probeer de voorbeelden van hierboven met systemctl op de service httpd op je eigen Rocky LX 8 systeem of
    apache2 op je eigen ubuntu 20 systeem (sudo apt install apache2)
     
    SSH service in RedHat8
    33 sudo systemctl status sshd
    34 sudo systemctl status sshd.service
     
    APACHE2 in RedHat8
    37 sudo yum install httpd
    60 sudo systemctl status httpd
    63 sudo systemctl start httpd
     
    LYNX in RedHat8
    43 yum search lynx
    48 cd /etc/yum.repos.d/
    49 ls
    56 sudo dnf config-manager --set-enabled powertools
    57 sudo yum install lynx
     
    APACHE testen in RedHat8
    65 lynx localhost