LoginSignup
1
0

More than 5 years have passed since last update.

systemd で起動するサービスで環境変数が読み込めなかった

Posted at

環境

  • CentOS7

参考

問題

systemd で起動するサービスで環境変数の読み込みを行う処理が合ったが、失敗し、エラーログが出力されていた。(具体的には $HOME の読み込み)
起動されるプロセスを ps コマンドで確認すると root ユーザーで実行されているようで、かつ root ユーザーで env コマンドを見ても環境変数は指定されており、なんでやとなっていた

解決方法

起動対象の /etc/systemd/system/xxxx.service についてユーザー名を指定する。
以下のような記述を追記。

xxxx.service
[Service]
User=root

変更後、対象サービスの停止、設定変更のリロード、サービス起動を行うことで環境変数が読み込めないエラーは発生しなくなった。

$systemctl stop xxxx
$systemctl daemon-reload
$systemctl start xxxx

これを見るとUserを指定しない場合、rootでは実行されていなかったということなのか?一度時間があれば調べてみる

1
0
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
1
0