LoginSignup
4
6

More than 5 years have passed since last update.

systemdについて調べたメモ

Last updated at Posted at 2016-03-18

systemd とは

systemdは従来 /etc/rc.d/init.d とかでサービスに対する起動/停止/再起動などの制御手順をシェルスクリプトとして記述していたものをもっと簡単な記述で実現できるようにしたもの。

設定ファイルの場所

systemd は起動したとき /etc/systemd/system/default.target を読み、それに依存するUnitを全て読み込み処理する仕組みになっている。

システムが提供する設定ファイルの本体は /usr/lib/systemd/system 配下に格納されていて、/etc/systemd/system 配下にシンボリックリンクが作成されている。

サーバ固有の設定等を行う場合は /usr/lib/sytemd/system から /etc/systemd/system ファイルをコピーして変更するか、/etc/systemd/system 配下にファイルを作成するのが流儀っぽい。

設定ファイルの中身

nginx.service の例

参考: NGINX systemd service file | NGINX

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

User=hoge
Group=fuga

[Install]
WantedBy=multi-user.target

現在稼働しているUnitを確認

例)稼働中のserviceの一覧

# systemctl list-units --type=service

全てのUnitを確認(現在稼働していないものも含む)

例)全serviceの一覧

# systemctl list-units --type=service

システム起動時の自動起動のOn/Off

自動起動On

# systemctl enable nginx

自動起動Off

# systemctl disable nginx

Unitの起動

# systemctl start nginx

Unitの停止

# sytemctl stop nginx

Unitの再起動

# sytemctl restart nginx

参考

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6