今回は systemd に対応している httpd と SysV init の MongoDB をインストール、設定などして違いなどを把握してみました。
参考
httpd
まずはインストール
$sudo yum install httpd
ここまでは同じ。
でも /etc/rc.d/init.d/ 配下にスクリプトがない。
どこにあるのかと探すと /usr/lib/systemd/system/httpd.service
に対応するスクリプトがありました。
スクリプトの内容は以下。
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
なんとなーく書いてある意味はこうかな、というのもありますが、ドキュメントとしては以下をみると良さそうな感じでした。
起動したり、ステータスを見てみます。
# 起動
$systemctl start httpd.service
# ステータス
$systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
Active: active (running) since 金 2016-07-29 22:48:14 EDT; 8s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 4094 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─4094 /usr/sbin/httpd -DFOREGROUND
├─4095 /usr/sbin/httpd -DFOREGROUND
├─4096 /usr/sbin/httpd -DFOREGROUND
├─4097 /usr/sbin/httpd -DFOREGROUND
├─4098 /usr/sbin/httpd -DFOREGROUND
└─4099 /usr/sbin/httpd -DFOREGROUND
7月 29 22:48:14 localhost.localdomain httpd[4094]: AH00558: httpd: Could no...
7月 29 22:48:14 localhost.localdomain systemd[1]: Started The Apache HTTP S...
Hint: Some lines were ellipsized, use -l to show in full.
# 自動起動確認
$sudo systemctl is-enabled httpd.service
disabled
# 自動起動有効化
$sudo systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
# 自動起動確認
$sudo systemctl is-enabled httpd.service
enabled
MongoDB
MongoDB サーバーを CentOS7 にインストールする
インストールしてみます。
$sudo curl http://repo.mongodb.org/yum/redhat/mongodb-org.repo -o /etc/yum.repos.d/mongodb.repo
$yum list --enablerepo=mongodb-org | grep mongo
$ sudo yum install --enablerepo=mongodb-org mongodb-org mongodb-org-server
ついでに自動起動してみます。
$systemctl enable mongod
mongod.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mongod on
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
む、色々表示されました。ネイティブサービスではないので chkconfig コマンドを実行したと書いてますね。
/usr/lib/systemd/system/
を確認すると mondod.service がない。ここにファイルがないのでネイティブサービスでないと判断したのかしら。
いつもの init 配下をみるとこちらに起動スクリプトが。
$/etc/rc.d/init.d/ |grep mongo
-rwxr-xr-x. 1 root root 3538 7月 12 14:21 mongod
色々確認
# chkconfig コマンドで表示される。httpdはない
$chkconfig --list
注記: この出力は SysV サービスのみであり、ネイティブな systemd のサービスは含ま れていません。
systemd services. SysV 設定のデータはネイティブな systemd の設定によって上書きされます。
systemd サービスを一覧表示するには 'systemctl list-unit-files' を使用して ください。
特定のターゲットにおいて有効化されているサービスを確認するには、
'systemctl list-dependencies [target]' 。
iprdump 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd-x11 0:off 1:off 2:off 3:on 4:off 5:on 6:off
# 自動起動確認。chkconfig を代わりに実行し、結果を表示。
$systemctl is-enabled mongod.service
mongod.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mongod --level=5
enabled
CentOS でも旧来の SysV init を利用するサービスも使えて systemctl コマンドでもいい感じにやってくれると。