Systemd with multiple execStart

i I know if it is possible to create a service with the same script running with different input parameters. For instance:

[Unit]
Description=script description

[Service]
Type=simple
ExecStart=/script.py parameters1
ExecStart=/script.py parameters2
Restart=on-failure

[Install]
WantedBy=multi-user.target

Is it possible? will it be launched in sequential mode? or in two different processes? Regards

+4
source share
2 answers

if Type=simplein your device’s file, you can specify only one ExecStart, but you can add as many ExecStartPre,ExecStartPost`, but none of them is suitable for long commands, because they are executed sequentially and all one start starts before the next starts.

If Type=oneshotyou can specify multiple ExecStart, they are run sequentially not in parallel.

, :

1

, /etc/systemd/system/foo@.service. : ( @).

[Unit]
Description=script description %I

[Service]
Type=simple
ExecStart=/script.py %i
Restart=on-failure

[Install]
WantedBy=multi-user.target

:

$ systemctl start foo@parameter1.service foo@parameter2.service

...

, :

#/etc/systemd/system/bar.target
[Unit]
Description=bar target
Requires=multi-user.target
After=multi-user.target
AllowIsolate=yes

.service WantedBy=bar.target :

#/etc/systemd/system/foo@.service
[Unit]
Description=script description %I

[Service]
Type=simple
ExecStart=/script.py %i
Restart=on-failure

[Install]
WantedBy=bar.target

foo, , :

$ systemctl daemon-reload
$ systemctl enable foo@param1.service
$ systemctl enable foo@param2.service
$ systemctl start bar.target

:, .

+8

ExecStartPre ExecStartPost

[Unit]
Description=script description

[Service]
Type=simple
ExecStartPre=/script.py parameters1
ExecStart=/script.py parameters2
Restart=on-failure

[Install]
WantedBy=multi-user.target
+1

Source: https://habr.com/ru/post/1692005/


All Articles