動作するサービスがあり、dhcpcd.service
githubプルを実行し、DHCPが機能しない場合はホストを確認できないため、実行後にのみ機能します。network.target
これは、DHCP サービスが完了する前に実行されます。サービスが実行されていると(サーバー)ユーザーはmichael
ログインしません。
問題は、すべてのケースを処理するために非常に長く醜い遅延を使用せずに作業できるほど遅く実行できないことです。
ExecStartPre=sleep 30
サービスは次のとおりですupdatecontinue.service
(私が試したいくつかの組み合わせの1つAfter=
)。
# man systemd.service
# man systemd.unit
#
# Debug with (will print errors at the bottom, time is in UTC!):
# -n50 to show 50 lines
# sudo systemctl status updatecontinue
#
# Or to get a plot (open with chrome so its searchable):
# systemd-analyze plot > ~/plot.svg
[Unit]
Description=Check if an update is halfway through, if yes, then update/enable OverlayFS/reboot
[Service]
Type=simple
ExecStart=/home/michael/.venv/terminal/bin/python3 /home/michael/terminal/script/update.py --check
After=dhcpcd.service
User=michael
[Install]
WantedBy=multi-user.target
ここで定義された場所から始まらないことがわかります。
ノート
次のように設定しても:
After=dhcpcd.service systemd-update-utmp-runlevel.service systemd-timesyncd.service
RON推奨注意事項
systemctl get-default
レポートgraphical.target
このサービスを利用してください:
[Unit]
Description=Check if an update is halfway through, if yes, then update/enable OverlayFS/reboot
[Service]
Type=idle
ExecStart=/home/michael/.venv/terminal/bin/python3 /home/michael/terminal/script/update.py --check
After=default.target
TimeoutStartSec=0
User=michael
[Install]
WantedBy=default.target
結果:
ベストアンサー1
systemdが解決しようとするいくつかの競合を定義してWantedBy=multi-user.target
追加しました。After=multi-user.target
この回答の下でより大きな説明/実験を見ることができます。
代わりにサービスが早すぎる場合は、サービスが失敗する理由を見つけてください。実行する代わりにサービス/ターゲットをAfter=multi-user.target
実行してください。After=
After=network.target
私の考えでは、唯一の問題がネットワークであれば追加します。
ユーザーログインが必要な場合はバスを使用してください--user
。
グラフィックセッションが必要な場合は、WantedBy=graphical.target
システムバスまたはWantedBy=graphical-session.target
ユーザーバスを検討してください。
使用すると関係をWantedBy=multi-user.target
結びます。multi-user.target
Wants=updatecontinue.service
これはただ始まるとupdatecontinue.service
始まるという意味です。起動に失敗しmulti-user.target
てもupdatecontinue.service
問題はありませんmulti-user.target
。
updatecontinue.service
その後、関係を提供しますRequires=multi-user.target
。これは重大な紛争です。 (起動するRequires=
とWants=
これ、それも始まります)。例外:それデバイスをアクティブにできません。これデバイスが起動しません。
したがって、実際には互いに起動する2つのデバイスしかありませんが、これはおそらく望むものではありません。Requires=
明確にするために依存関係を削除します。
Before
/関係は機能します。以下はAfter
/なしで対話する2つのサービスの例です。Before
After
$ systemctl --user cat {early,late}.service
# /home/stew/.config/systemd/user/early.service
[Unit]
Wants=late.service
[Service]
ExecStartPre=sleep 2
ExecStart=sleep 20
# /home/stew/.config/systemd/user/late.service
[Service]
ExecStart=sleep 5
$ systemctl --user start early
$ journalctl --user --since "2 minutes ago" --no-hostname
Mar 08 15:54:42 systemd[1064]: Starting early.service...
Mar 08 15:54:42 systemd[1064]: Started late.service.
Mar 08 15:54:44 systemd[1064]: Started early.service.
同時にサービスが開始されることを確認できます。
late.service
それでは関係を築きましょうAfter=early.service
。
$ systemctl --user cat {early,late}.service
# /home/stew/.config/systemd/user/early.service
[Unit]
Wants=late.service
[Service]
ExecStartPre=sleep 2
ExecStart=sleep 20
# /home/stew/.config/systemd/user/late.service
[Unit]
After=early.service
[Service]
ExecStart=sleep 5
$ systemctl --user start early
$ journalctl --user --since "2 minutes ago" --no-hostname
Mar 08 16:01:09 systemd[1064]: Starting early.service...
Mar 08 16:01:11 systemd[1064]: Started early.service.
Mar 08 16:01:11 systemd[1064]: Started late.service.
この場合、完了がlate.service
始まったことがわかります(スタンバイセルになります)。early.service
ExecStartPre
active (running)
サービスとは異なり、ターゲットは「開始済み」状態に移行しません。代わりに、彼らは「達成」された。 andを使って同じことを試してみましょうearly.target
。late.service
しかし、late.service
始めるのに少し時間がかかります。
$ systemctl --user cat early.target late.service
# /home/stew/.config/systemd/user/early.target
[Unit]
Wants=late.service
# /home/stew/.config/systemd/user/late.service
[Service]
ExecStartPre=sleep 2
ExecStart=sleep 5
$ systemctl --user start early.target
$ journalctl --user --since "2 minutes ago" --no-hostname
Mar 08 16:07:27 systemd[1064]: Starting late.service...
Mar 08 16:07:29 systemd[1064]: Started late.service.
Mar 08 16:07:29 systemd[1064]: Reached target early.target.
early.target
「到着」に2秒かかることがわかります。これは、すべての目標の「Wants =」が「アクティブ化」ステップを完了し、「アクティブ(実行中)」状態に入ったときにのみ、ターゲットが「達成」されることを意味します。
これを知ることで、After=foo.target
aとの混合がWantedBy=foo.target
やや矛盾する理由がわかります。 foo.target
到着前に始めるのを待っています。その間は、foo.target
始める前にあなたに連絡したいと思います。