Systemd systemctl: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Thomas (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „=== aktivieren/deaktivieren systemstart === *systemctl enable *systemctl disable *systemctl is-enabled === service steuern === *systemctl start *systemctl st…“) |
|||
| (47 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
| − | === | + | =Example= |
| − | *systemctl enable | + | *cat /etc/systemd/system/chat.service |
| − | *systemctl disable | + | <pre> |
| − | + | [Unit] | |
| − | === service | + | Description=chat service |
| − | *systemctl | + | After=network.target syslog.target |
| − | *systemctl | + | |
| − | *systemctl | + | [Service] |
| − | *systemctl | + | Type=simple |
| − | *systemctl | + | ExecStart=/bin/bash -c "/bin/ncat -l -p 3333 > /tmp/chat.log" |
| − | === service | + | User=root |
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | </pre> | ||
| + | |||
| + | =Systemctl= | ||
| + | ==Edit== | ||
| + | *systemctl edit chat.service --full | ||
| + | ==Daemon Reload== | ||
| + | *systemctl daemon-reload | ||
| + | |||
| + | ==Start== | ||
| + | *systemctl start chat.service | ||
| + | ==Stop== | ||
| + | *systemctl stop chat.service | ||
| + | ==Enable== | ||
| + | *systemctl enable chat.service | ||
| + | Created symlink from /etc/systemd/system/multi-user.target.wants/chat.service to /etc/systemd/system/chat.service. | ||
| + | ==Disable== | ||
| + | *systemctl disable chat.service | ||
| + | Removed symlink /etc/systemd/system/multi-user.target.wants/chat.service. | ||
| + | ==Reload== | ||
| + | *systemctl reload chat.service | ||
| + | |||
| + | ==Restart== | ||
| + | *systemctl restart chat.service | ||
| + | |||
| + | ==Is enabled== | ||
| + | *systemctl is-enabled chat.service | ||
| + | disabled | ||
| + | ==Mask== | ||
| + | *systemctl mask apache2.service | ||
| + | Created symlink from /etc/systemd/system/apache2.service to /dev/null. | ||
| + | |||
| + | ==Unmask== | ||
| + | *systemctl unmask apache2.service | ||
| + | Removed symlink /etc/systemd/system/apache2.service. | ||
| + | |||
| + | ==Status== | ||
| + | *systemctl status chat.service | ||
| + | <pre> | ||
| + | ● chat.service - chat service | ||
| + | Loaded: loaded (/etc/systemd/system/chat.service; disabled; vendor preset: enabled) | ||
| + | Active: active (running) since Di 2017-10-24 16:20:26 CEST; 17s ago | ||
| + | Main PID: 10949 (bash) | ||
| + | CGroup: /system.slice/chat.service | ||
| + | ├─10949 /bin/bash -c /bin/netcat -l -p 3333 > /tmp/chat.log | ||
| + | └─10951 /bin/netcat -l -p 3333 | ||
| + | |||
| + | Okt 24 16:20:26 bajor.xinux.lan systemd[1]: Started chat service. | ||
| + | </pre> | ||
| + | |||
| + | ==List Dependencies== | ||
| + | *systemctl list-dependencies apache2 | ||
| + | <pre> | ||
| + | apache2.service | ||
| + | ● ├─system.slice | ||
| + | ● ├─network-online.target | ||
| + | ● │ ├─networking.service | ||
| + | ● │ └─NetworkManager-wait-online.service | ||
| + | ● └─sysinit.target | ||
| + | ● ├─apparmor.service | ||
| + | ● ├─brltty.service | ||
| + | ● ├─console-setup.service | ||
| + | ... | ||
| + | </pre> | ||
| + | ==List Units== | ||
*systemctl list-units | *systemctl list-units | ||
| + | <pre> | ||
| + | UNIT LOAD ACTIVE SUB DESCRIPTION | ||
| + | proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats File System Automount Point | ||
| + | sys-devices-LNXSYSTM:00-LNXSYBUS:00-PNP0A08:00-device:02-ATK0110:00-hwmon-hwmon1.device loaded active plugged /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:02/ATK0110:00/hwmon/hwmon1 | ||
| + | sys-devices-pci0000:00-0000:00:01.0-0000:01:00.0-hwmon-hwmon0.device loaded active plugged /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/hwmon/hwmon0 | ||
| + | ... | ||
| + | </pre> | ||
| + | |||
| + | ==List Unit Files== | ||
*systemctl list-unit-files | *systemctl list-unit-files | ||
| + | <pre> | ||
| + | UNIT FILE STATE | ||
| + | proc-sys-fs-binfmt_misc.automount static | ||
| + | dev-hugepages.mount static | ||
| + | dev-mqueue.mount static | ||
| + | mnt-data.mount enabled | ||
| + | mnt-media.mount enabled | ||
| + | proc-fs-nfsd.mount static | ||
| + | proc-sys-fs-binfmt_misc.mount static | ||
| + | run-rpc_pipefs.mount static | ||
| + | sys-fs-fuse-connections.mount static | ||
| + | sys-kernel-config.mount static | ||
| + | sys-kernel-debug.mount static | ||
| + | acpid.path enabled | ||
| + | cups.path enabled | ||
| + | systemd-ask-password-console.path static | ||
| + | systemd-ask-password-plymouth.path static | ||
| + | systemd-ask-password-wall.path static | ||
| + | systemd-networkd-resolvconf-update.path static | ||
| + | accounts-daemon.service enabled | ||
| + | acpid.service disabled | ||
| + | ... | ||
| + | </pre> | ||
| + | |||
| + | ==Failed== | ||
*systemctl --failed | *systemctl --failed | ||
| + | <pre> | ||
| + | 0 loaded units listed. Pass --all to see loaded but inactive units, too. | ||
| + | To show all installed unit files use 'systemctl list-unit-files'. | ||
| + | </pre> | ||
| + | ==Löschen der Journalprotokolle für den spezifischen Dienst== | ||
| + | *'''journalctl --rotate --unit ''name_des_dienstes.service'' ''' | ||
| + | *'''journalctl --vacuum-time=1s''' | ||
| − | == | + | ==Isolate Halt == |
*systemctl isolate halt | *systemctl isolate halt | ||
| + | ==Poweroff== | ||
*systemctl poweroff | *systemctl poweroff | ||
| + | ==Suspend== | ||
*systemctl suspend | *systemctl suspend | ||
| + | ==Hibernate== | ||
*systemctl hibernate | *systemctl hibernate | ||
| + | ==Reboot== | ||
| + | *systemctl reboot | ||
| + | |||
| + | ==List Timers== | ||
| + | *systemctl list-timers | ||
| + | <pre> | ||
| + | NEXT LEFT LAST PASSED UNIT ACTIVATES | ||
| + | Di 2017-10-24 21:12:15 CEST 4h 26min left Di 2017-10-24 14:01:54 CEST 2h 44min ago apt-daily.timer apt-daily.service | ||
| + | Mi 2017-10-25 14:31:55 CEST 21h left Di 2017-10-24 14:31:55 CEST 2h 14min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service | ||
| + | Mo 2017-10-30 03:05:56 CET 5 days left Di 2017-10-24 14:36:05 CEST 2h 10min ago snapd.refresh.timer snapd.refresh.service | ||
| + | n/a n/a Di 2017-10-24 14:18:24 CEST 2h 27min ago ureadahead-stop.timer ureadahead-stop.service | ||
| + | |||
| + | 4 timers listed. | ||
| + | Pass --all to see loaded but inactive timers, too. | ||
| + | </pre> | ||
| + | ==List Sockets== | ||
| + | *systemctl list-sockets | ||
| + | <pre> | ||
| + | systemctl list-sockets | ||
| + | LISTEN UNIT ACTIVATES | ||
| + | /dev/rfkill systemd-rfkill.socket systemd-rfkill.service | ||
| + | /run/acpid.socket acpid.socket acpid.service | ||
| + | /run/dmeventd-client dm-event.socket dm-event.service | ||
| + | /run/dmeventd-server dm-event.socket dm-event.service | ||
| + | /run/lvm/lvmetad.socket lvm2-lvmetad.socket lvm2-lvmetad.service | ||
| + | /run/lvm/lvmpolld.socket lvm2-lvmpolld.socket lvm2-lvmpolld.service | ||
| + | ... | ||
| + | </pre> | ||
| + | ==Set Target== | ||
| + | *systemctl -f enable multi-user.target | ||
| + | *systemctl -f enable graphical.target | ||
| + | ==Get Default Target== | ||
| + | *systemctl get-default | ||
| + | graphical.target | ||
| + | ==Changing Target== | ||
| + | *systemctl isolate multi-user.target | ||
| + | |||
| + | ==Set Default Target== | ||
| + | *systemctl set-default multi-user.target | ||
| + | |||
| + | ==Show Targets== | ||
| + | *systemctl list-units --type target | ||
| + | <pre> | ||
| + | UNIT LOAD ACTIVE SUB DESCRIPTION | ||
| + | basic.target loaded active active Basic System | ||
| + | bluetooth.target loaded active active Bluetooth | ||
| + | ceph-mds.target loaded active active ceph target allowing to start/stop all ceph-mds@.service instances at once | ||
| + | ceph-mon.target loaded active active ceph target allowing to start/stop all ceph-mon@.service instances at once | ||
| + | ... | ||
| + | </pre> | ||
| + | =New Stuff= | ||
| + | *systemctl list-dependencies | ||
| + | |||
| + | *systemctl cat cron.service | ||
| + | <pre> | ||
| + | # /lib/systemd/system/cron.service | ||
| + | [Unit] | ||
| + | Description=Regular background program processing daemon | ||
| + | Documentation=man:cron(8) | ||
| + | After=remote-fs.target nss-user-lookup.target | ||
| + | |||
| + | [Service] | ||
| + | EnvironmentFile=-/etc/default/cron | ||
| + | ExecStart=/usr/sbin/cron -f $EXTRA_OPTS | ||
| + | IgnoreSIGPIPE=false | ||
| + | KillMode=process | ||
| + | Restart=on-failure | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | </pre> | ||
| + | |||
| + | =fstab= | ||
| + | *systemctl daemon-reload erzeug .mounts mit dem Namen des Mountpoints | ||
| + | =socket= | ||
| + | ;socket starten anstatt service | ||
| + | *beispiel cockpit= | ||
| + | =systemctl status= | ||
| + | *systemctl statis <PID> | ||
| + | =systemd.analyze= | ||
| + | Verbesserungsvorschläge | ||
| + | *systemd-analyze security pakagekit | ||
Aktuelle Version vom 2. Juli 2024, 07:00 Uhr
Example
- cat /etc/systemd/system/chat.service
[Unit] Description=chat service After=network.target syslog.target [Service] Type=simple ExecStart=/bin/bash -c "/bin/ncat -l -p 3333 > /tmp/chat.log" User=root [Install] WantedBy=multi-user.target
Systemctl
Edit
- systemctl edit chat.service --full
Daemon Reload
- systemctl daemon-reload
Start
- systemctl start chat.service
Stop
- systemctl stop chat.service
Enable
- systemctl enable chat.service
Created symlink from /etc/systemd/system/multi-user.target.wants/chat.service to /etc/systemd/system/chat.service.
Disable
- systemctl disable chat.service
Removed symlink /etc/systemd/system/multi-user.target.wants/chat.service.
Reload
- systemctl reload chat.service
Restart
- systemctl restart chat.service
Is enabled
- systemctl is-enabled chat.service
disabled
Mask
- systemctl mask apache2.service
Created symlink from /etc/systemd/system/apache2.service to /dev/null.
Unmask
- systemctl unmask apache2.service
Removed symlink /etc/systemd/system/apache2.service.
Status
- systemctl status chat.service
● chat.service - chat service
Loaded: loaded (/etc/systemd/system/chat.service; disabled; vendor preset: enabled)
Active: active (running) since Di 2017-10-24 16:20:26 CEST; 17s ago
Main PID: 10949 (bash)
CGroup: /system.slice/chat.service
├─10949 /bin/bash -c /bin/netcat -l -p 3333 > /tmp/chat.log
└─10951 /bin/netcat -l -p 3333
Okt 24 16:20:26 bajor.xinux.lan systemd[1]: Started chat service.
List Dependencies
- systemctl list-dependencies apache2
apache2.service ● ├─system.slice ● ├─network-online.target ● │ ├─networking.service ● │ └─NetworkManager-wait-online.service ● └─sysinit.target ● ├─apparmor.service ● ├─brltty.service ● ├─console-setup.service ...
List Units
- systemctl list-units
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats File System Automount Point sys-devices-LNXSYSTM:00-LNXSYBUS:00-PNP0A08:00-device:02-ATK0110:00-hwmon-hwmon1.device loaded active plugged /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:02/ATK0110:00/hwmon/hwmon1 sys-devices-pci0000:00-0000:00:01.0-0000:01:00.0-hwmon-hwmon0.device loaded active plugged /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/hwmon/hwmon0 ...
List Unit Files
- systemctl list-unit-files
UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static mnt-data.mount enabled mnt-media.mount enabled proc-fs-nfsd.mount static proc-sys-fs-binfmt_misc.mount static run-rpc_pipefs.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static acpid.path enabled cups.path enabled systemd-ask-password-console.path static systemd-ask-password-plymouth.path static systemd-ask-password-wall.path static systemd-networkd-resolvconf-update.path static accounts-daemon.service enabled acpid.service disabled ...
Failed
- systemctl --failed
0 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
Löschen der Journalprotokolle für den spezifischen Dienst
- journalctl --rotate --unit name_des_dienstes.service
- journalctl --vacuum-time=1s
Isolate Halt
- systemctl isolate halt
Poweroff
- systemctl poweroff
Suspend
- systemctl suspend
Hibernate
- systemctl hibernate
Reboot
- systemctl reboot
List Timers
- systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES Di 2017-10-24 21:12:15 CEST 4h 26min left Di 2017-10-24 14:01:54 CEST 2h 44min ago apt-daily.timer apt-daily.service Mi 2017-10-25 14:31:55 CEST 21h left Di 2017-10-24 14:31:55 CEST 2h 14min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service Mo 2017-10-30 03:05:56 CET 5 days left Di 2017-10-24 14:36:05 CEST 2h 10min ago snapd.refresh.timer snapd.refresh.service n/a n/a Di 2017-10-24 14:18:24 CEST 2h 27min ago ureadahead-stop.timer ureadahead-stop.service 4 timers listed. Pass --all to see loaded but inactive timers, too.
List Sockets
- systemctl list-sockets
systemctl list-sockets LISTEN UNIT ACTIVATES /dev/rfkill systemd-rfkill.socket systemd-rfkill.service /run/acpid.socket acpid.socket acpid.service /run/dmeventd-client dm-event.socket dm-event.service /run/dmeventd-server dm-event.socket dm-event.service /run/lvm/lvmetad.socket lvm2-lvmetad.socket lvm2-lvmetad.service /run/lvm/lvmpolld.socket lvm2-lvmpolld.socket lvm2-lvmpolld.service ...
Set Target
- systemctl -f enable multi-user.target
- systemctl -f enable graphical.target
Get Default Target
- systemctl get-default
graphical.target
Changing Target
- systemctl isolate multi-user.target
Set Default Target
- systemctl set-default multi-user.target
Show Targets
- systemctl list-units --type target
UNIT LOAD ACTIVE SUB DESCRIPTION basic.target loaded active active Basic System bluetooth.target loaded active active Bluetooth ceph-mds.target loaded active active ceph target allowing to start/stop all ceph-mds@.service instances at once ceph-mon.target loaded active active ceph target allowing to start/stop all ceph-mon@.service instances at once ...
New Stuff
- systemctl list-dependencies
- systemctl cat cron.service
# /lib/systemd/system/cron.service [Unit] Description=Regular background program processing daemon Documentation=man:cron(8) After=remote-fs.target nss-user-lookup.target [Service] EnvironmentFile=-/etc/default/cron ExecStart=/usr/sbin/cron -f $EXTRA_OPTS IgnoreSIGPIPE=false KillMode=process Restart=on-failure [Install] WantedBy=multi-user.target
fstab
- systemctl daemon-reload erzeug .mounts mit dem Namen des Mountpoints
socket
- socket starten anstatt service
- beispiel cockpit=
systemctl status
- systemctl statis <PID>
systemd.analyze
Verbesserungsvorschläge
- systemd-analyze security pakagekit