systemd
Location: /usr/lib/systemd/system/ and /etc/systemd/system/
設定範例
# cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH Daemon
After=network.target
[Service]
EnvironmentFile=/etc/sysconfig/ssh
ExecStartPre=/usr/sbin/sshd-gen-keys-start
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
systemctl mask <service>.service
- mask 只要使用, 不可以手動啟動服務
- unmask 取消mask
查詢的方式 ( 該服務會被導向到 /dev/null )
# ls -l /etc/systemd/system | grep null
以類型來列出
# systemctl -t service
# systemctl -t service | grep ssh
sshd.service loaded active running OpenSSH Daemon
有些 target 可以跟 runlevel 對照
Target units group service and other units
Some target units are the equivalent to runlevels
- multi-user.target - runlevel 3
- graphical.target - runlevel 5
# systemctl -t target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
開機的時候可以在 linux 那一行指定 target 來暫時切換target ( runlevel )
例如原本是圖形界面, 開機要指定文字界面開機
systemd.unit=multi-user.target
開機以文字界面(runlevel 3) 開機, 但是如果想切換圖形界面
可以更改 target 來達成 ( 當然目前還可以用 init 切換 )
#systemctl isolate graphical.target
開機時間
# systemd-analyze
Startup finished in 2.739s (kernel) + 17.430s (userspace) = 20.170s
詳細的列出
# systemd-analyze blame
11.260s network.service
8.133s network@ens160.service
2.104s ModemManager.service
2.050s SuSEfirewall2_init.service
1.658s network@ens192.service
1.522s rsyslog.service
974ms vmtoolsd.service
SLES 12 跟 openSUSE 13.2 一樣用 systemd-logger 取代 syslog-ng
Systemd has an internal log daemon – journald
透過導向的方式存檔
journalctl > file.txt
systemd and cgroups
- Each service is placed into a cgroup in /sys/fs/cgroup/systemd/system.slice
- systemd uses this directory to control services, not for resource control
See man systemd.resourcecontrol for available options
檢查相關資訊
# systemd-cgls
Working Directory /sys/fs/cgroup/systemd/system.slice:
├─1 /sbin/init showopts
├─polkit.service
│ └─18657 /usr/lib/polkit-1/polkitd --no-debug
├─accounts-daemon.service
│ └─18652 /usr/lib/accounts-daemon
├─system-network.slice
│ ├─network@ens192.service
│ │ ├─1955 avahi-autoipd: [ens192] sleeping
│ │ └─1956 avahi-autoipd: [ens192] callout dispatche
│ └─network@ens160.service
│ ├─1518 avahi-autoipd: [ens160] sleeping
│ └─1519 avahi-autoipd: [ens160] callout dispatche
沒有留言:
張貼留言