Help us understand the problem. What is going on with this article?

systemdでサービスを動かす際、/var/runにディレクトリを作った時の落とし穴と対策

More than 1 year has passed since last update.

環境

CentOS 7

どんな状況?

  • systemdでサービスを起動したい。
  • その時の実行権限がrootじゃない。
  • 故に /var/run/[dir] を作成。
    • もちろん chown で[dir]の権限を実行ユーザにしている。
  • 作成した[dir]に、pidファイルやsockファイルが作られたりする。

何が問題?

対策

/etc/systemd/system/[サービス名].service

PermissionsStartOnly=true
ExecStartPre=/usr/bin/mkdir /var/run/[dir]
ExecStartPre=/usr/bin/chown -R [実行ユーザ]:[実行グループ] /var/run/[dir]
ExecStopPost=/usr/bin/rm -rf /var/run/[dir]

サービス起動前に[dir]を作成
サービス終了時に[dir]を削除(次回起動時にエラーになるため)
参考 : Handling /var/run with systemd
参考 : Systemd入門(4) - serviceタイプUnitの設定ファイル

s-yama
大きな森の入り口すぐ、7階。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした