Hacker News new | ask | show | jobs
by colemickens 3446 days ago
Why would you run the Exec command through systemd-escape? The help text says that's for the NAME of the unit... Am I missing something?

Also, I'm failing to think of a scripting purpose that requires you to place non-trivial bash directly in a systemd unit that couldn't be solved by writing out the script somewhere and just invoking the script in the unit.

2 comments

> Now agreed, if your workflow demands that you embed a Bash while loop in a unit, you’re already in a bad place, but there are times where this is required for templating purposes.

It's right there in the post. I have indeed had to do something like this in the wild to run a Docker container with special needs.

I don't see how "templating purposes" answers the question. I deploy services on VMs that need to parameterized and I can parameterize via templating a written-to-disk shell script that is then just simply executed in the unit... or I can have more dynamic parameterization and use environment variables and Environment= lines in the unit. The latter solution means the substitution is effectively happening in the same place as if they were inlined parameters, so I can't imagine a scenario when it wouldn't be workable.
Both you and OP haven't mentioned why you needed to do it inline as opposed to in an external script, though.
> Am I missing something?

You're not. Contrived example is contrived.