What is the difference between systemd.services.<name>.script
and systemd.services.<name>.serviceConfig.ExecStart
?
ExecStart
does not run in a shell, script
runs in a shell.
what does that mean? I can use ExecStart to execute the command node index.js
, but I can also use script
to execute the command node index.js
. So I do not really understand when to use what.
Compare ExecStart = "a && b";
, script = "a && b";
, the former won’t work, the latter will.
script
just boils down to a ExecStart
call with a generated script on the fly with a runtime shell.
To expand on that:
ExecStart is the normal systemd attribute, nothing fancy.
script is just a convince wrapper that writes the content to a text file, makes it executable and adds that path to ExecStart, so that services can easily run a shell command or two when starting the service without having to worry aout that.
Oh okay, so I can basically just always use script instead of ExecStart? Is there also something like this wrapper for ExecPreStart?
Basically yes but if you don’t need shell features then the plain command should be used. Basically avoid the extra abstraction step if possible.
no
Actually yes. In fact, there’s one for all the Exec
things.
-
ExecStart
:script
-
ExecStartPre
:preStart
-
ExecStartPost
:postStart
-
ExecStop
:preStop
-
ExecStopPost
:postStop
I was searching for more variants if script but couldn’t immediately find it because of the naming.