5

I'm using the sh -c exec idiom in an ExecStart statement (in a service unit file) to interpolate some shell commands. For example:

ExecStart=/bin/sh -ec "exec /usr/bin/foo $(/usr/bin/foo-config)"

It works great. However, when I look at the journal for this service, the process name is sh instead of foo. Is there a way to lie about the process name using this idiom?

sourcejedi
  • 50,249
mwp
  • 276
  • Try adding something directly after the command argument, e.g. sh -ec "exec whatever" desired-name. It will be set as $0 for the shell. Not sure if it will carry through to where you want it but it's a good bet. – Wildcard Jun 13 '16 at 17:58
  • @Wildcard: Unfortunately, that did not work. – mwp Jun 13 '16 at 18:11

2 Answers2

10

Ah, this turned out to be much easier than I thought it would be. Found an answer here: https://unix.stackexchange.com/a/229525/11995!

    SyslogIdentifier=foo
mwp
  • 276
0

Have you considered using an environment file or variable to do your last-minute configuration instead of a command? Something like (untested):

Environment= ARGS=--whatever
EnvironmentFile=-/etc/foo/foo.config
ExecStart=/usr/bin/foo $ARGS

That seems more in line with the 'systemd way'.

Lee-Man
  • 257
  • I agree that this approach would be better; unfortunately, I'm trying to wrap something that works a certain way, and I don't have much control over it. Specifically, foo-config does some critical parsing of the config file to generate command-line arguments. This parsing needs to happen at run time to capture any subsequent changes to the config file. Is there a way to do something like Environment=ARGS=$(/usr/bin/foo-config)? – mwp Jun 13 '16 at 18:15
  • In that case (still not sure I agree), you might want to create your own shell script with the same name, e.g. /usr/local/bin/foo. This script could call foo-config and then ultimately /usr/bin/foo? (Again, not tested.) – Lee-Man Jun 13 '16 at 18:18