Is it possible to create service with the same script started with different input parameters?
Example:
[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 serial-mode? Or in two different process?
if Type=simple in your unit file, you can only specify one ExecStart, but you can add as many ExecStartPre , ExecStartPost , but none of this is suited for long running commands, because they are executed serially and everything one start is killed before starting the next one.
Run multiple instances To manage one, just append its name after the @ symbol. Start each instance with the appropriate command: littlebank: systemctl start httpd@littlebank. bigbank: systemctl start httpd@bigbank.
ExecStart. The commands and arguments executed when the service starts. ExecStartPre, ExecStartPost. Additional commands that are executed before or after the command in ExecStart .
ExecStart= : This specifies the full path and the arguments of the command to be executed to start the process. This may only be specified once (except for “oneshot” services).
if Type=simple
in your unit file, you can only specify one ExecStart, but you can add as many ExecStartPre
, ExecStartPost
, but none of this is suited for long running commands, because they are executed serially and everything one start is killed before starting the next one.
If Type=oneshot
you can specify multiple ExecStart, they run serially not in parallel.
If what you want is to run multiple units in parallel, there a few things you can do:
You can use template units, so you create a /etc/systemd/system/[email protected]
. NOTE: (the @
is important).
[Unit] Description=script description %I [Service] Type=simple ExecStart=/script.py %i Restart=on-failure [Install] WantedBy=multi-user.target
And then you exec:
$ systemctl start [email protected] [email protected]
or...
You can create multiple units that links to a single target:
#/etc/systemd/system/bar.target [Unit] Description=bar target Requires=multi-user.target After=multi-user.target AllowIsolate=yes
And then you just modify you .service units to be WantedBy=bar.target
like:
#/etc/systemd/system/[email protected] [Unit] Description=script description %I [Service] Type=simple ExecStart=/script.py %i Restart=on-failure [Install] WantedBy=bar.target
Then you just enable the foo services you want in parallel, and start the bar target like this:
$ systemctl daemon-reload $ systemctl enable [email protected] $ systemctl enable [email protected] $ systemctl start bar.target
NOTE: that this works with any type of units not only template units.
You can use ExecStartPre
or ExecStartPost
for one of scripts
[Unit] Description=script description [Service] Type=simple ExecStartPre=/script.py parameters1 ExecStart=/script.py parameters2 Restart=on-failure [Install] WantedBy=multi-user.target
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With