PCの起動時にArchのサービスが開始されません。

PCの起動時にArchのサービスが開始されません。

私はアーチLinuxを使用しています。/etc/systemd/system/次のようなサービスがあります。

[Unit]
After=network.target

[Service]
Type=simple
ExecStart=(...)service.py
ExecReload=(...)service.py
Restart=always

ネットワーク接続によって異なりますので、ネットワーク形成後に起動するように設定しました。

コンピュータを起動すると、サービスは常に無効になっています。手動で起動すると完全に実行されます。内部エラーが発生しても再起動します。コンピュータの電源を入れたのになぜ起動しないのですか?

編集する

サービスを有効にすると、次のメッセージが表示されます。

➜  ~ systemctl enable py_service.service                                                                                                                     
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.`

これらの点について:

  1. シンボリックリンクがありません

  2. それはヘルパーではありません。

  3. 私はこれがすべて覆われていると思いました。After=network...

  4. これはどういう意味なのかわかりません。

編集2@dustballの提案に従って、次のように編集しました。

cat /etc/systemd/system/py_service.service 
[Install]
WantedBy=multi-user.target

[Unit]
After=network.target

[Service]
Type=simple
ExecStart=(...)service.py
ExecReload=(...)service.py
Restart=always

しかし、起動時に起動しません:(

編集3 上記の設定がうまくいきましたが、それを有効にするのを忘れました。 (@Daniel Hに感謝します。)リロードサービスを使用してください

sudo systemctl daemon-reload

次に、次を使用して有効にします。

systemctl enable py_service.service

ベストアンサー1

エラーメッセージはすでに(部分的に)答えを提供します。サービスには「インストール」セクションがあります。唯一のオプションは「WantedBy =」です。サービスを有効にするには、ターゲットでそれを要求する必要があります。

例:NetworkManagerには「WantedBy = network.target」があるため、NetworkManagerを有効にするとnetwork.targetにグループ化され、systemdがnetwork.targetを起動するとすぐに起動します。

デーモンを挿入する必要があるSysV-initのランレベルと同じだと思います。それ以外の場合...いつ始めるべきですか?

安全なデフォルトは、最後に開始された「WantedBy = multi-user.target」を設定することです。

おすすめ記事