[systemd-devel] What is the best way to run a shell script through 'ExecStart'

Tom Gundersen teg at jklm.no
Mon Sep 30 06:31:51 PDT 2013


Hi Muhammad,

On Mon, Sep 30, 2013 at 3:25 PM, Muhammad Shakeel
<muhammad_shakeel at mentor.com> wrote:
> I have been trying to convert a LSB initscript of a package into
> corresponding systemd service fyile. Most init scripts are simple and
> translating them into systemd unit files is non-trivial. In this case it is
> a relatively long script involving some loops.
>
> 1) Should I write a script file separately and then call it through
> 'ExecStart'?
> or
> 2) It would be good (and do-able) idea to fit whole script inside
> ExecStart=/bin/sh -c " <script>"? (If yes, I would prefer it as it will free
> me from hassle of maintaining two files)

If you need something non-trivial (such as loops or a script over more
than a couple of lines), then I suggest keeping it in a separate file.
Systemd service files intentionally do not support loops (or other
control structures).

HTH,

Tom


More information about the systemd-devel mailing list