Systemd が Fedora に導入されたのは 2011 年 5 月 24 日にリリースされ Fedora 15 の時ですから、先日リリースされた RHL 7 / Cent OS 7 に systemd が採用されたからと言って、自分にとって真新しいものはないはずです。しかし、マジメに systemd を勉強してこなかったので、引用サイト 1. を読み、自分の環境 (Cent OS 7) での使用例をまとめました。例に取り上げているサービスは httpd です。
systemctl コマンドで現在有効な Unit を一覧する場合
# systemctl --type=service --no-pager
UNIT LOAD ACTIVE SUB DESCRIPTION
abrt-ccpp.service loaded active exited Install ABRT coredump hook
abrt-oops.service loaded active running ABRT kernel log watcher
abrt-xorg.service loaded active running ABRT Xorg log watcher
abrtd.service loaded active running ABRT Automated Bug Reporting
...
(省略)
...
udisks2.service loaded active running Disk Manager
upower.service loaded active running Daemon for power management
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
73 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
#
定義されているすべてのサービスを確認する場合
# systemctl list-unit-files --type=service --no-pager UNIT FILE STATE abrt-ccpp.service enabled abrt-oops.service enabled abrt-pstoreoops.service disabled abrt-vmcore.service enabled ... (省略) ... vmtoolsd.service enabled wacom-inputattach@.service static wpa_supplicant.service disabled 251 unit files listed. #
HTTP デーモンを起動する Unit である httpd.service について、自動起動を有効化/無効化する場合
# systemctl enable httpd.service ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service' # systemctl disable httpd.service rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
システム起動後に手動で起動/停止/再起動する場合
# systemctl start httpd.service # systemctl stop httpd.service # systemctl restart httpd.service
httpd.service」の稼働状態を表示する例
# systemctl status httpd.service httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: active (running) since 月 2014-08-25 13:18:04 JST; 15s ago Process: 5654 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Main PID: 5659 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─5659 /usr/sbin/httpd -DFOREGROUND ├─5660 /usr/libexec/nss_pcache 1277958 off /etc/httpd/alias ├─5661 /usr/sbin/httpd -DFOREGROUND ├─5662 /usr/sbin/httpd -DFOREGROUND ├─5663 /usr/sbin/httpd -DFOREGROUND ├─5664 /usr/sbin/httpd -DFOREGROUND ├─5665 /usr/sbin/httpd -DFOREGROUND └─5666 /usr/sbin/httpd -DFOREGROUND 8月 25 13:18:03 localhost.localdomain httpd[5659]: AH00558: httpd: Could no... 8月 25 13:18:04 localhost.localdomain systemd[1]: Started The Apache HTTP S... Hint: Some lines were ellipsized, use -l to show in full. #
journald によるログの表示
# journalctl -u httpd.service -a --no-pager
-- Logs begin at 月 2014-08-25 12:30:25 JST, end at 月 2014-08-25 13:20:01 JST. --
8月 25 12:31:14 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
8月 25 12:31:15 localhost.localdomain httpd[1212]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
8月 25 12:31:16 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
8月 25 13:15:48 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
8月 25 13:15:55 localhost.localdomain systemd[1]: Stopping The Apache HTTP Server...
...
(省略)
...