systemd是Linux操作系统的框架和服务管理器。在作为引导的第一个进程(如PID 1)继续运行时,它将作为init系统运行。可以提高和保持用户空间服务。本文介绍-“学习Linux上的现代服务管理系统(Systemd)”
要获取有关systemd的更多信息,请使用以下命令,如下所示–
$ systemd -h
样本输出应如下所示–
Starts up and maintains the system or user services. -h --help Show this help --test Determine startup sequence, dump it and exit --no-pager Do not pipe output into a pager --dump-configuration-items Dump understood unit configuration items --unit=UNIT Set default unit --system Run a system instance, even if PID != 1 --user Run a user instance --dump-core[=BOOL] Dump core on crash --crash-vt=NR Change to specified VT on crash --crash-reboot[=BOOL] Reboot on crash --crash-shell[=BOOL] Run shell on crash .......................................................................................
要获取有关systemd的版本信息,请使用以下命令,如下所示–
$ systemd --version
样本输出应如下所示–
systemd 229 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN
要确定启动顺序,请使用以下命令,如下所示–
$ systemd --test
样本输出应如下所示–
State Change Timestamp: Mon 2017-01-30 11:15:37 IST Inactive Exit Timestamp: Mon 2017-01-30 11:15:37 IST Active Enter Timestamp: Mon 2017-01-30 11:15:37 IST Active Exit Timestamp: n/a Inactive Enter Timestamp: n/a GC Check Good: yes Need Daemon Reload: no Transient: no Slice: n/a CGroup: n/a CGroup realized: no CGroup mask: 0x0 CGroup members mask: 0x0 Name: sys-devices-platform-serial8250-tty-ttyS26.device Following Set Member: dev-ttyS26.device Job Timeout: 1min 30s ..............................................................................
要获取转储并了解单元配置项,请使用以下命令–
$ systemd --dump-configuration-items
样本输出应如下所示–
[Scope] Slice=SLICE CPUAccounting=BOOLEAN CPUShares=SHARES StartupCPUShares=SHARES CPUQuota=OTHER MemoryAccounting=BOOLEAN MemoryLimit=LIMIT DeviceAllow=DEVICE DevicePolicy=POLICY BlockIOAccounting=BOOLEAN BlockIOWeight=WEIGHT StartupBlockIOWeight=WEIGHT BlockIODeviceWeight=DEVICEWEIGHT BlockIOReadBandwidth=BANDWIDTH .....................................................................................
要分析系统引导过程,请使用以下命令–
$ systemd-analyze
样本输出应如下所示–
Startup finished in 8.740s (firmware) + 4.483s (loader) + 3.616s (kernel) + 4min 21.244s (userspace) = 4min 38.084s
要获取列表启动过程及其时间,请使用以下命令,如下所示:
$ systemd-analyze blame
样本输出应如下所示–
3min 59.399s apt-daily.service 16.585s NetworkManager-wait-online.service 11.182s grub-common.service 9.532s apport.service 9.224s irqbalance.service 8.986s networking.service 8.916s snapd.refresh.service 8.859s speech-dispatcher.service 7.709s dev-sda2.device 7.641s gpu-manager.service 7.641s rsyslog.service 7.078s avahi-daemon.service 6.178s lightdm.service ..............................................................................
要显示控制组内容,请使用以下命令,如下所示–
$ systemd-cgls
样本输出应如下所示–
Control group /: -.slice ├─init.scope │ └─1 /lib/systemd/systemd --system --deserialize 19 ├─system.slice │ ├─avahi-daemon.service │ │ ├─733 avahi-daemon: running [linux-Inspiron-3542.local │ │ └─806 avahi-daemon: chroot helpe │ ├─thermald.service │ │ └─845 /usr/sbin/thermald --no-daemon --dbus-enable │ ├─dbus.service │ │ ├─ 759 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activ │ │ └─2637 /usr/lib/x86_64-linux-gnu/fwupd/fwupd │ ├─ModemManager.service │ │ └─871 /usr/sbin/ModemManager │ ├─cron.service │ │ └─850 /usr/sbin/cron -f │ ├─apache2.service │ │ ├─ 4441 /usr/sbin/apache2 -k start
要按资源使用量显示最高控制组,请使用以下命令,如下所示–
$sudo systemd-cgtop
样本输出应如下所示–
Control Group Tasks %CPU Memory Input/s Output/s / - 20.0 6.3G - - /init.scope 1 - - - - /system.slice 125 - - - - /user.slice 695 - - - - /user.slice/user-1000.slice 654 - - - - /user.slice/user-126.slice 41 - - - -
Systemctl可用于自省和管理“ systemd”系统和服务管理器的状态。
要获取有关systemctl的更多信息,请使用以下命令,如下所示–
$ systemctl --help
样本输出应如下所示–
Query or send control commands to the systemd manager. -h --help Show this help --version Show package version --system Connect to system manager --user Connect to user service manager -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List units with particular LOAD or SUB or ACTIVE state -p --property=NAME Show only properties by this name -a --all Show all loaded units/properties, including dead/empty ones. To list all units installed on the system, use the 'list-unit-files' command instead. -l --full Don't ellipsize unit names on output ...........................................................................
要获取systemctl的版本,请使用以下命令–
$ systemctl --version
样本输出应如下所示–
systemd 229 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN
要获取所有正在运行的服务的列表,请使用以下命令,如下所示–
$ systemctl
样本输出应如下所示–
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS10.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS11.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS12.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS13.device loaded active plugged /sys/devices/platfor
要使用systemctl启动服务,请使用以下命令,如下所示–
$ sudo systemctl start application.service
使用systemctl启动服务的示例示例如下所示–
$ sudo systemctl start bluetooth.service
要获取bluetooth.service的状态,如下所示–
$ systemctl status bluetooth
样本输出应如下所示–
bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2017-01-27 09:32:45 IST; 3 days ago Docs: man:bluetoothd(8) Main PID: 954 (bluetoothd) Status: "Running" CGroup: /system.slice/bluetooth.service └─954 /usr/lib/bluetooth/bluetoothd Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: gatt-time-server: Input/output error (5) Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Not enough free handles to register service Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Not enough free handles to register service Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Sap driver initialization failed. Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: sap-server: Operation not permitted (1) Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Endpoint registered: sender=:1.68 path=/Med Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Endpoint registered: sender=:1.68 path=/Med Jan 30 11:20:54 linux-Inspiron-3542 systemd[1]: Started Bluetooth service. Jan 30 11:21:07 linux-Inspiron-3542 systemd[1]: Started Bluetooth service. Jan 30 11:41:00 linux-Inspiron-3542 systemd[1]: Started Bluetooth service.
要停止服务,请使用以下命令,如下所示–
$ sudo systemctl stop bluetooth.service
要验证上述命令,请使用以下命令,如下所示–
$ systemctl status bluetooth
样本输出应如下所示–
bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: inactive (dead) since Mon 2017-01-30 11:45:35 IST; 4s ago Docs: man:bluetoothd(8) Main PID: 954 (code=exited, status=0/SUCCESS) Status: "Quitting" ..................................................................................
要重新启动服务,请使用以下命令,如下所示–
$ sudo systemctl restart bluetooth.service
要使服务能够在启动时启动,请使用以下命令,如下所示:
$ sudo systemctl enable bluetooth.service
要禁用在启动时启动的服务,请使用以下命令,如下所示–
$ sudo systemctl disable bluetooth.service
要验证是否启用了服务,请使用以下命令,如下所示–
$ sudo systemctl is-enabled bluetooth.service; echo $?
样本输出应如下所示–
enabled 0
要屏蔽服务,请使用以下命令,如下所示–
$ sudo systemctl mask bluetooth.service
要取消屏蔽服务,请使用以下命令,如下所示–
$ sudo systemctl unmask bluetooth.service
要终止服务,请使用以下命令,如下所示–
$ sudo systemctl kill bluetooth.service
要获取服务的配置详细信息,请使用以下命令,如下所示–
$ sudo systemctl show bluetooth
样本输出应如下所示–
Restart=no NotifyAccess=none RestartUSec=100ms TimeoutStartUSec=1min 30s TimeoutStopUSec=1min 30s RuntimeMaxUSec=infinity WatchdogUSec=0 WatchdogTimestampMonotonic=0 ............................................................
要分析服务的关键链,请使用以下命令,如下所示:
$ sudo systemd-analyze critical-chain bluetooth.service
样本输出应如下所示–
The time after the unit is active or started is printed after the "@" character. The time the unit takes to start is printed after the "+" character. bluetooth.service +886ms
要获取依赖项列表,请使用以下命令,如下所示–
$ sudo systemctl list-dependencies bluetooth.service
要获取特定类型的列表单位,请使用以下命令,如下所示–
systemctl -t mount
样本输出应如下所示–
UNIT LOAD ACTIVE SUB DESCRIPTION -.mount loaded active mounted / boot-efi.mount loaded active mounted /boot/efi dev-hugepages.mount loaded active mounted Huge Pages File System dev-mqueue.mount loaded active mounted POSIX Message Queue File System proc-sys-fs-binfmt_misc.mount loaded active mounted Arbitrary Executable File Formats File Syste run-user-1000-gvfs.mount loaded active mounted /run/user/1000/gvfs run-user-1000.mount loaded active mounted /run/user/1000 run-user-126.mount loaded active mounted /run/user/126 sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System sys-kernel-debug.mount loaded active mounted Debug File System ....................................................................
要显示所有已加载的单位/属性,包括空/空,请使用以下命令,如下所示:
$ systemctl -a
样本输出应如下所示–
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Forma ● org.freedesktop.network1.busname not-found inactive dead org.freedesktop.network1.busnam dev-cdrom.device loaded active plugged HL-DT-ST_DVD+_-RW_GU90N dev-cdrw.device loaded active plugged HL-DT-ST_DVD+_-RW_GU90N dev-disk-by\x2did-ata\x2dHL\x2dDT\x2dST_DVD\x2b_\x2dRW_GU90N_M7FE9H30316.device loaded acti dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S.device loaded active plugged TOSH dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S\x2dpart1.device loaded active plugg dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S\x2dpart2.device loaded active plugg dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S\x2dpart3.device loaded active plugg dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c.device loaded active plugged TOSHIBA_MQ01AB dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c\x2dpart1.device loaded active plugged TOSHI dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c\x2dpart2.device loaded active plugged TOSHI dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c\x2dpart3.device loaded active plugged TOSHI dev-disk-by\x2did-wwn\x2d0x5001480000000000.device loaded active plugged HL-DT-ST_DV ..............................................................................................
要获取单位文件列表,请使用以下命令,如下所示–
$ systemctl list-unit-files
样本输出应如下所示–
UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-sys-fs-binfmt_misc.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 alsa-restore.service static alsa-state.service static alsa-utils.service masked anacron-resume.service enabled anacron.service enabled .................................................
要获取指定单位文件的列表,请使用以下命令,如下所示–
$ sudo systemctl list-unit-files --type=moun
样本输出应如下所示–
UNIT FILE STATE dev-hugepages.mount static dev-mqueue.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static 6 unit files listed. ......................................................
要显示主机和本地容器的单元列表,请使用以下命令,如下所示–
$ sudo systemctl -r
样本输出应如下所示–
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged ............................................................................................
要指定如何处理已排队的作业,请在排队新作业时使用以下命令,如下所示:
$ systemctl --job-mode=active
样本输出应如下所示–
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS10.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS11.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS12.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS13.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS14.device loaded active plugged /sys/devices/plat ..............................................................................................
要获取所有套接字类型,请使用以下命令,如下所示–
$ systemctl --show-types
样本输出应如下所示–
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platf ........................................................................................
关闭或睡眠时要忽略抑制物。使用以下命令,如下所示–
$ systemctl -i
样本输出应如下所示–
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS10.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS11.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS12.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS13.device loaded active plugged /sys/devices/plat ............................................................................................
要获取套接字信息列表,请使用以下命令,如下所示
$sudo systemctl list-unit-files --type=socket
样本输出应如下所示–
UNIT FILE STATE acpid.socket enabled apport-forward.socket enabled avahi-daemon.socket enabled cups.socket enabled dbus.socket static saned.socket disabled snapd.socket enabled syslog.socket static systemd-bus-proxyd.socket static systemd-fsckd.socket static systemd-initctl.socket static ........................................................................
要启用套接字,请使用以下命令,如下所示–
$ sudo systemctl start saned.socket
在上面的命令中,saned.socket是单位文件。
要停止套接字,请使用以下命令,如下所示–
$ sudo systemctl stop saned.socket
要重新启动套接字,请使用以下命令,如下所示–
$ sudo systemctl restart saned.socket
要重新加载套接字,请使用以下命令,如下所示–
$ sudo systemctl reload saned.socket
要启用套接字,请使用以下命令,如下所示–
$ sudo systemctl enable saned.socket
要禁用套接字,请使用以下命令,如下所示–
$ sudo systemctl disable saned.socket
要屏蔽套接字,请使用以下命令,如下所示–
$ sudo systemctl mask saned.socket
要取消屏蔽该套接字,请使用以下命令,如下所示–
$ sudo systemctl unmask saned.socket
要获取套接字的状态,请使用以下命令,如下所示–
$ sudo systemctl status saned.socket
样本输出应如下所示–
saned.socket - saned incoming socket Loaded: loaded (/lib/systemd/system/saned.socket; disabled; vendor preset: enabled) Active: active (listening) since Mon 2017-01-30 12:30:05 IST; 2min 59s ago Listen: [::]:6566 (Stream) Accepted: 0; Connected: 0 Jan 30 12:30:05 linux-Inspiron-3542 systemd[1]: Listening on saned incoming socket.
要重新引导系统,请使用以下命令,如下所示–
$sudo systemctl reboot
要挂起系统,请使用以下命令,如下所示–
$sudo systemctl suspend
要使系统休眠,请使用以下命令,如下所示–
$sudo systemctl hibernate
要关闭系统,请使用以下命令,如下所示–
$ sudo systemctl poweroff
要关闭系统,请使用以下命令,如下所示–
$sudo systemctl halt
在本文中,我们了解了–学习Linux上的现代服务管理系统(Systemd),我们将提供更多基于Linux的技巧和窍门。继续阅读!