admin_grundlagen:systemd_service_unit_files
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Nächste Überarbeitung | Vorherige Überarbeitung | ||
| admin_grundlagen:systemd_service_unit_files [2016/11/24 10:04] – angelegt stefan_miethke | admin_grundlagen:systemd_service_unit_files [2025/09/02 13:23] (aktuell) – ingo_wichmann | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== Beispiel für eine Service | + | ====== Beispiel für ein Service |
| + | |||
| + | Unit File anlegen: | ||
| + | systemctl edit --full --force nc.service | ||
| <file txt / | <file txt / | ||
| - | [Unit] | ||
| - | Description=my netcat service | ||
| - | |||
| [Service] | [Service] | ||
| ExecStart=/ | ExecStart=/ | ||
| - | |||
| - | [Install] | ||
| - | WantedBy=multi-user.target | ||
| </ | </ | ||
| - | Systemd Konfiguration neu laden | + | (( |
| + | Lennart Poettering [[https:// | ||
| + | " | ||
| + | |||
| + | )) | ||
| + | |||
| + | Syntax des Unit Files prüfen: | ||
| + | systemd-analyze verify nc.service | ||
| + | (( | ||
| + | Fehlermeldung " | ||
| + | )) | ||
| + | |||
| + | Systemd Konfiguration neu laden (( nicht nötig, wenn das Unit File mit '' | ||
| systemctl daemon-reload | systemctl daemon-reload | ||
| Zeile 19: | Zeile 28: | ||
| Start überprüfen | Start überprüfen | ||
| + | systemctl status nc | ||
| + | |||
| + | Beschreibung hinzufügen: | ||
| + | systemctl edit --full nc.service | ||
| + | |||
| + | <file txt / | ||
| + | [Unit] | ||
| + | Description=my netcat service | ||
| + | |||
| + | … | ||
| + | </ | ||
| + | |||
| + | Beschreibung überprüfen | ||
| systemctl status nc | systemctl status nc | ||
| Beim Booten starten | Beim Booten starten | ||
| + | systemctl edit --full nc.service | ||
| + | |||
| + | <file txt / | ||
| + | … | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | </ | ||
| + | |||
| systemctl enable nc | systemctl enable nc | ||
| + | |||
| + | Nach beendeter Verbindung neustarten: | ||
| + | |||
| + | <file txt / | ||
| + | … | ||
| + | |||
| + | [Service] | ||
| + | … | ||
| + | Restart=always | ||
| + | </ | ||
| + | |||
| + | ====== Beispiel für ein User Service Unit ====== | ||
| + | Sinnloses Skript anlegen: | ||
| + | mkdir ~/bin | ||
| + | vim ~/ | ||
| + | |||
| + | <code bash ~/ | ||
| + | #!/bin/bash | ||
| + | dd if=/ | ||
| + | </ | ||
| + | |||
| + | Als Benutzer Unit File anlegen: | ||
| + | systemctl --user edit --force --full fillfs.service | ||
| + | |||
| + | <file txt ~/ | ||
| + | [Service] | ||
| + | ExecStart=/ | ||
| + | </ | ||
| + | |||
| + | Syntax des Unit Files überprüfen: | ||
| + | systemd-analyze --user verify fillfs.service | ||
| + | |||
| + | " | ||
| + | systemctl --user start fillfs | ||
| + | |||
| + | Sehen was passiert: | ||
| + | systemctl --user status fillfs | ||
| + | journalctl --user -fu fillfs | ||
| + | watch -d df -h | ||
| + | |||
| + | |||
| ===== vmstat daemon service unit ===== | ===== vmstat daemon service unit ===== | ||
| Zeile 44: | Zeile 116: | ||
| VMDELAY=" | VMDELAY=" | ||
| VMLOGFILE="/ | VMLOGFILE="/ | ||
| + | </ | ||
| + | |||
| + | ====== Dienste absichern ====== | ||
| + | ((Lennart Poettering schreibt: // | ||
| + | should enable wherever we can. Specifically ProtectSystem=, | ||
| + | ProtectHome=, | ||
| + | ProtectedControlGroups=, | ||
| + | PrivateNetwork=, | ||
| + | RestrictNamespaces=, | ||
| + | |||
| + | TODO: noch nicht getestet | ||
| + | |||
| + | <file txt> | ||
| + | ProtectSystem=full | ||
| + | </ | ||
| + | oder | ||
| + | <file txt> | ||
| + | ProtectSystem=strict | ||
| + | ReadWritePaths=/ | ||
| + | ReadOnlyPaths=/ | ||
| + | CapabilityBoundingSet=~CAP_SYS_ADMIN | ||
| + | SystemCallFilter=~@mount, | ||
| + | </ | ||
| + | |||
| + | <file txt> | ||
| + | ProtectHome=true | ||
| + | ProtectKernelTunables=true | ||
| + | ProtectKernelModules=true | ||
| + | ProtectedControlGroups=true | ||
| + | PrivateTmp=true | ||
| + | PrivateDevices=true | ||
| + | SystemCallFilter=~@mount, | ||
| + | RestrictAddressFamilies=AF_UNIX, | ||
| + | RestrictNamespaces=true | ||
| + | RestrictRealtime=true | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | </ | ||
| + | |||
| + | Für lokale Dienste (systlog ohne netzwerk, cron (falls keine Jobs auf das Netzwerk zugreifen sollen), ...) zusätzlich: | ||
| + | <file txt> | ||
| + | PrivateNetwork=true | ||
| + | RestrictAddressFamilies=AF_UNIX | ||
| + | </ | ||
| + | |||
| + | TODO: Für Dienste, die keine Daten dauerhaft speichern (ntpd? unbound?): | ||
| + | <file txt> | ||
| + | DynamicUser=yes | ||
| + | User=unbound | ||
| + | Group=unbound | ||
| </ | </ | ||
admin_grundlagen/systemd_service_unit_files.1479981860.txt.gz · Zuletzt geändert: 2016/11/24 10:04 von stefan_miethke
