systemd が使いにくいので避けていたのですが、やっとFedora 15 を 17 にアップデートしてみました。実はFedora 15もsystemdを採用しているがまだ随分とSystemV系のスクリプトが残っていた。しかしFedora 17ではsystemdを使いこなさないとサーバ運用できないので、調べた結果をまとめてみた。 (Upstartは短命だったな。。。)
まずは、どんなサービスがあるか一覧を確認。
# systemctl --full list-unit-files UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static media.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static .... (省略) .... httpd-event.service disabled httpd-worker.service disabled httpd.service disabled ip6tables.service enabled iptables.service enabled ... (省略) ....
Apache (httpd.service) は無効(disabled)になっているのが分かるし、ファイアウォール(iptables) は有効(enable)になっているのが分かる。static はおそらくシステム必須のもので変更できないやつかな?(後で調べてみよう)
ちなみに、関連するファイルは/usr/lib/systemd/systemにあるみたい。/usr/lib/systemd/system/httpd.service ファイルの中身はFedora 17の場合こんな内容だった。
[Unit] Description=The Apache HTTP Server (prefork MPM) After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/httpd/httpd.pid EnvironmentFile=/etc/sysconfig/httpd ExecStart=/usr/sbin/httpd $OPTIONS -k start ExecReload=/usr/sbin/httpd $OPTIONS -t ExecReload=/bin/kill -HUP $MAINPID ExecStop=/usr/sbin/httpd $OPTIONS -k stop PrivateTmp=true [Install] WantedBy=multi-user.target
起動してみる。 /etc/init.d/のスクリプト実行するのと比べてコマンド打つのが少し面倒になった。
# systemctl start httpd.service
停止はstartをstopにするだけ。
# systemctl stop httpd.service
上記はあくまで手動での起動・停止なので、次はシステム起動時に自動的に起動できるようにしてみる。
# systemctl enable httpd.service ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
System Vと同じく、シンボリックリンクを作って自動起動を制御しているみたいなので、手動でシンボリックリンク作ってもいけそうだ。
有効になったかどうかを確認してみると、無事enableになったのが確認できた。
# systemctl --full list-unit-files | grep httpd.service httpd.service enabled
無効はenableの逆、disalbe を使う。
# systemctl disable httpd.service rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
以上、基本操作はこんなところでしょうか。そのうちシステムの起動プロセスも調べてみよう。