
systemd
次のようなサービスがあります。
[Service]
ExecStart=/usr/local/bin/binary subcommand
User=my-user
Group=my-group
EnvironmentFile=/etc/my-service/config
内容を変えています。/etc/my-service/config
daemon-reload
サービスを実行または再ロードする必要がありますか?
ExecReload
私のユニットファイルにはディレクティブはありません。これはsystemctl reload my-service
動作に影響しますか?
答え1
また、基本プロセスでも読み込まれdaemon-reload
ません。reload
EnvironmentFile=
マニュアルページには、EnvironmentFile=
プロセスが実行される直前にリストされたファイルを読むことが示されています。
- これはファイルを読み取るか、それを意味します
start
。restart
その理由は、start
またはrestart
プロセスを実行するためです。 - これはまた、notまたは単位
daemon-reload
に影響がないことを示しています。daemon-reload
start
restart
- これは、メインプロセスが作成されない
reload
ため影響がないことを示しています。reload
構成を再ロードするために基本プロセスにシグナルを送信する機会のみを提供します。ExecReload=
定義がない場合は特にそうです。
サポート実験
$ systemctl --user cat env.service
# /home/stew/.config/systemd/user/env.service
[Service]
ExecStart=/bin/bash -c "while true; do sleep 1; echo $EXAMPLE_ENV; done"
EnvironmentFile=%h/env
$ cat ~/env
EXAMPLE_ENV="Hi"
$ systemctl --user start env.service
その後、操作中にログを監視します。
$ journalctl --user -u env.service -f
...
Feb 11 15:35:47 stewbian systemd[1108]: Started env.service.
Feb 11 15:35:48 stewbian bash[911848]: Hi
Feb 11 15:35:49 stewbian bash[911848]: Hi
その後、環境ファイルを変更しましたが、出力に変更はありませんでした。
$ sed -i -e 's/Hi/Yo/' ~/env
...
Feb 11 15:37:13 stewbian bash[911848]: Hi
Feb 11 15:37:14 stewbian bash[911848]: Hi
Feb 11 15:37:15 stewbian bash[911848]: Hi
それからaを試しましたが、systemctl reload
出力に変化がないことを確認しました。
$ systemctl --user reload env.service
Failed to reload env.service: Job type reload is not applicable for unit env.service.
...
Feb 11 15:38:14 stewbian bash[911848]: Hi
Feb 11 15:38:15 stewbian bash[911848]: Hi
それからaを試しましたが、daemon-reload
出力に変化がないことを確認しました。
$ systemctl --user daemon-reload
...
Feb 11 15:38:46 stewbian bash[911848]: Hi
Feb 11 15:38:47 stewbian bash[911848]: Hi
その後、再起動を試み、変更を確認しました。
$ systemctl --user restart env.service
...
Feb 11 15:39:29 stewbian bash[911848]: Hi
Feb 11 15:39:30 stewbian bash[911848]: Hi
Feb 11 15:39:30 stewbian systemd[1108]: Stopping env.service...
Feb 11 15:39:30 stewbian systemd[1108]: Stopped env.service.
Feb 11 15:39:30 stewbian systemd[1108]: Started env.service.
Feb 11 15:39:31 stewbian bash[912531]: Yo
Feb 11 15:39:32 stewbian bash[912531]: Yo
ExecReload=/bin/bash -c 'echo $EXAMPLE_ENV
デバイスに追加する興味深い点の1つです。この場合、私はこれを得ます:
Feb 11 15:58:24 stewbian bash[914611]: Hi
Feb 11 15:58:25 stewbian bash[914611]: Hi
Feb 11 15:58:26 stewbian systemd[1108]: Reloading env.service...
Feb 11 15:58:26 stewbian bash[914640]: Yo
Feb 11 15:58:26 stewbian systemd[1108]: Reloaded env.service.
Feb 11 15:58:26 stewbian bash[914611]: Hi
Feb 11 15:58:27 stewbian bash[914611]: Hi
したがって、ここでは始める前に実際に読み取られますが、新しいsystemd
環境だけが新しいプロセスに渡されることがわかります。既存のプロセスのコンテキストは変更されません。EnvironmentFile=
ExecReload=
システム環境変数置換が行の解析中に何の影響も与えなかったことを確認するために、別のスクリプトに入れてbash
再試行しましたExec*=
。同じ結果です。
サポート文書
man systemd.exec
:
EnvironmentFile=
...
The files listed with this directive will be read shortly before
the process is executed (more specifically, after all processes
from a previous unit state terminated. This means you can
generate these files in one unit state, and read it with this
option in the next. The files are read from the file system of
the service manager, before any file system changes like bind
mounts take place).
man systemctl
:
reload PATTERN...
Asks all units listed on the command line to reload their
configuration. Note that this will reload the service-specific
configuration, not the unit configuration file of systemd. If you
want systemd to reload the configuration file of a unit, use the
daemon-reload command. In other words: for the example case of
Apache, this will reload Apache's httpd.conf in the web server,
not the apache.service systemd unit file.
This command should not be confused with the daemon-reload
command.
daemon-reload
Reload the systemd manager configuration. This will rerun all
generators (see systemd.generator(7)), reload all unit files, and
recreate the entire dependency tree. While the daemon is being
reloaded, all sockets systemd listens on behalf of user
configuration will stay accessible.
This command should not be confused with the reload command.
In other words: for the example case of Apache, this will reload Apache's httpd.conf in the
web server, not the apache.service systemd unit file.
This command should not be confused with the daemon-reload command.
man systemd.service
:
ExecReload=
Commands to execute to trigger a configuration reload in the
service. This argument takes multiple command lines, following
the same scheme as described for ExecStart= above. Use of this
setting is optional. Specifier and environment variable
substitution is supported here following the same scheme as for
ExecStart=.
One additional, special environment variable is set: if known,
$MAINPID is set to the main process of the daemon, and may be
used for command lines like the following:
ExecReload=kill -HUP $MAINPID
Note however that reloading a daemon by sending a signal (as with
the example line above) is usually not a good choice, because
this is an asynchronous operation and hence not suitable to order
reloads of multiple services against each other. It is strongly
recommended to set ExecReload= to a command that not only
triggers a configuration reload of the daemon, but also
synchronously waits for it to complete. For example, dbus-
broker(1) uses the following:
ExecReload=busctl call org.freedesktop.DBus \
/org/freedesktop/DBus org.freedesktop.DBus \
ReloadConfig