システムサービスユニットを順番に起動するには?

システムサービスユニットを順番に起動するには?

次のサービスユニットが0から3(0、1、2、3)の順序で始まるようにするにはどうすればよいですか? echo-date-1.service アイデアを有効にしてみました。 echo-date-2が必要で、echo-date-3が必要で、echo-date-0が必要なので、echo-date-0を最初に起動してからEchoを起動します。日付-1,2,3。 systemd-analyzeグラフを調べると、順序が間違っているようです。

ここに画像の説明を入力してください。

-------------------
echo-date-1.service
-------------------
[Unit]
Description=Start echo-date-1
Requires=echo-date-2.service
**After=echo-date-0.service**

[Service]
ExecStart=/home/USER/bash/echo-date-1.sh

[Install]
WantedBy=multi-user.target



-------------------
echo-date-2.service
-------------------
[Unit]
Description=Start echo-date-2
Requires=echo-date-3.service
**After=echo-date-1.service**

[Service]
ExecStart=/home/USER/bash/echo-date-2.sh

[Install]
WantedBy=multi-user.target



-------------------
echo-date-3.service
-------------------
[Unit]
Description=Start echo-date-3
Requires=echo-date-0.service
**After=echo-date-2.service**

[Service]
ExecStart=/home/USER/bash/echo-date-3.sh

[Install]
WantedBy=multi-user.target




-------------------
echo-date-0.service
-------------------
[Unit]
Description=Start echo-date-0

[Service]
ExecStart=/home/USER/bash/echo-date-0.sh

[Install]
WantedBy=multi-user.target

編集する: 私は成功したと信じています。どちらも書かなければなりません。必要そして後ろに内部に単位サービスファイルセクション。のみ使用必要または後ろに動作しません。両方を使用する必要があります。理由がありますか?

これは、サービスファイルのsystemd-analyzeプロット出力とsystemctl状態です(PID番号を参照)。

ここに画像の説明を入力してください。

● echo-date-0.service - Start echo-date-0
   Loaded: loaded (/etc/systemd/system/echo-date-0.service; disabled; vendor preset: disabled)
   Active: inactive (dead) since Tue 2017-07-18 16:04:43 EDT; 9min ago
  Process: 281 ExecStart=/home/USER/bash/echo-date-0.sh (code=exited, status=0/SUCCESS)
 Main PID: 281 (code=exited, status=0/SUCCESS)

Jul 18 16:04:43 localhost systemd[1]: Started Start echo-date-0.

● echo-date-1.service - Start echo-date-1
   Loaded: loaded (/etc/systemd/system/echo-date-1.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Tue 2017-07-18 16:04:43 EDT; 10min ago
  Process: 283 ExecStart=/home/USER/bash/echo-date-1.sh (code=exited, status=0/SUCCESS)
 Main PID: 283 (code=exited, status=0/SUCCESS)

Jul 18 16:04:43 localhost systemd[1]: Started Start echo-date-1.

● echo-date-2.service - Start echo-date-2
   Loaded: loaded (/etc/systemd/system/echo-date-2.service; disabled; vendor preset: disabled)
   Active: inactive (dead) since Tue 2017-07-18 16:04:43 EDT; 10min ago
  Process: 284 ExecStart=/home/USER/bash/echo-date-2.sh (code=exited, status=0/SUCCESS)
 Main PID: 284 (code=exited, status=0/SUCCESS)

Jul 18 16:04:43 localhost systemd[1]: Started Start echo-date-2.

● echo-date-3.service - Start echo-date-3
   Loaded: loaded (/etc/systemd/system/echo-date-3.service; disabled; vendor preset: disabled)
   Active: inactive (dead) since Tue 2017-07-18 16:04:43 EDT; 10min ago
  Process: 285 ExecStart=/home/USER/bash/echo-date-3.sh (code=exited, status=0/SUCCESS)
 Main PID: 285 (code=exited, status=0/SUCCESS)

Jul 18 16:04:43 localhost systemd[1]: Started Start echo-date-3.

ベストアンサー1

内部にシステム装置文書は、順序を制御するためにRequires/Before組み合わせを使用する必要があることを示していますAfter。あなたの例では、以下を設定します。

# echo-date-0.service
[Unit]
Description=Start echo-date-0

[Service]
ExecStart=/home/USER/bash/echo-date-0.sh

[Install]
WantedBy=multi-user.target

# echo-date-1.service
[Unit]
Description=Start echo-date-1
Requires=echo-date-0.service
After=echo-date-0.service

[Service]
ExecStart=/home/USER/bash/echo-date-1.sh

[Install]
WantedBy=multi-user.target

# echo-date-2.service
[Unit]
Description=Start echo-date-2
Requires=echo-date-1.service
After=echo-date-1.service

[Service]
ExecStart=/home/USER/bash/echo-date-2.sh

[Install]
WantedBy=multi-user.target

# echo-date-3.service
[Unit]
Description=Start echo-date-3
Requires=echo-date-2.service
After=echo-date-2.service

[Service]
ExecStart=/home/USER/bash/echo-date-3.sh

[Install]
WantedBy=multi-user.target

その後、echo-date-3.service有効にして他のすべてのサービスを起動します。

おすすめ記事