[SOLVED] systemd: daemon ignores any command line parameter

This forum is for discussion about general software issues.

[SOLVED] systemd: daemon ignores any command line parameter

Postby MilanKnizek » Sat Jan 24, 2015 7:54 pm

Hello,

enjoying some trouble time with systemd: when I run daemon binary from CLI, then everything works as expected. When I create service file for systemd and start it, it seems to work properly, but the daemon does not honor any of the command line parameters and continues with defaults. Tested on Raspberry Pi model B+ (ARM), basic installation. I am new to Pi, but kind of an old timer with Arch on x86.

First example is when /usr/bin/ebusd is started in terminal (the /etcWRONG/ebusd path is there for purpose, so that I can see if it is parsed or not by the daemon):

$this->bbcode_second_pass_code('', '$ sudo /usr/bin/ebusd --configpath /etcWRONG/ebusd --logfile /var/log/ebusd-remote/ebusd.log --dumpfile /var/log/ebusd-remote/ebusd.dump --dumpsize 100000 --dump')

$this->bbcode_second_pass_code('', '$ ps aux | grep /usr/bin/ebusd
root 5832 0.0 0.2 38392 1080 ? Ssl 11:23 0:00 /usr/bin/ebusd --configpath /etcWRONG/ebusd --logfile /var/log/ebusd-remote/ebusd.log --dumpfile /var/log/ebusd-remote/ebusd.dump --dumpsize 100000 --dump')

Everything is great: ebusd complains about missing file/element, because the path /etcWRONG/ebusd does not exist and also the log file is in the defined path.

$this->bbcode_second_pass_code('', '$ cat /var/log/ebusd-remote/ebusd.log
2015-01-24 11:23:09.646 [bas event] ebusd started
2015-01-24 11:23:09.647 [bas trace] path to ebus configuration files: /etcWRONG/ebusd
2015-01-24 11:23:09.648 [bas error] error reading templates: ERR: file/element not found or not readable
2015-01-24 11:23:09.648 [bas error] error reading config files: ERR: file/element not found or not readable')

Now is the time for systemd:

$this->bbcode_second_pass_code('', '$ cat ebusd.service
[Unit]
Description=Communication interface to the energy bus (ebus)
After=local-fs.target
ConditionPathExists=/var/log

[Service]
Type=forking
EnvironmentFile=-/etc/conf.d/ebusd
ExecStart=/usr/bin/ebusd ${EBUSD_ARGS}
PIDFile=/run/ebusd.pid

[Install]
WantedBy=multi-user.target')

The parameters of the process are the same:

$this->bbcode_second_pass_code('', '$ ps aux | grep /usr/bin/ebusd
root 5774 0.0 0.2 46584 1260 ? Ssl 10:47 0:00 /usr/bin/ebusd --configpath /etcWRONG/ebusd --logfile /var/log/ebusd-remote/ebusd.log --dumpfile /var/log/ebusd-remote/ebusd.dump --dumpsize 100000 --dump')

However, the config path is ignored, the log file is ignored:

$this->bbcode_second_pass_code('', '$ cat /var/log/ebusd.log
2015-01-24 10:47:39.898 [bas event] ebusd started
2015-01-24 10:47:39.899 [bas trace] path to ebus configuration files: /etc/ebusd
2015-01-24 10:47:39.935 [bas trace] read templates
2015-01-24 10:47:39.938 [bas trace] read config files
2015-01-24 10:47:39.939 [bas event] message DB: 4
2015-01-24 10:47:39.940 [bas event] updates DB: 0
2015-01-24 10:47:39.940 [bas event] polling DB: 0')

/usr/bin/ebusd forks itself to the background, hence the Type=forking.

Anybody has an idea, what's wrong?
Last edited by MilanKnizek on Sun Jan 25, 2015 11:41 am, edited 1 time in total.
MilanKnizek
 
Posts: 4
Joined: Sat Jan 24, 2015 7:44 pm

Re: systemd: daemon ignores any command line parameter

Postby pepedog » Sat Jan 24, 2015 8:23 pm

Is that minus sign supposed to be there?
EnvironmentFile=-/etc/conf.d/ebusd
And what is in that file?
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: systemd: daemon ignores any command line parameter

Postby MilanKnizek » Sun Jan 25, 2015 8:48 am

The minus sign is to "test existence of the file" - it is sourced only when it exists.

$this->bbcode_second_pass_code('', '$ cat /etc/conf.d/ebusd
# /etc/conf.d/ebusd: config file for ebusd.service
# Options to pass to the ebusd.
# See the ebusd -h for more info.

#EBUSD_ARGS="--device /dev/ttyUSB0"
EBUSD_ARGS="--configpath /etcWRONG/ebusd --logfile /var/log/ebusd-remote/ebusd.log --dumpfile /var/log/ebusd-remote/ebusd.dump --dumpsize 100000 --dump"')

I can avoid sourcing the env file and typing the params directly to ebusd.service file: the outcome is the same (i.e. params are shown in /proc/PID/cmdline but ignored).

I will try to test on x86 to see if there is a difference in behaviour.

EDIT: the bug/feature takes place also on x86_64, hence I'll move back to Arch Linux forums to get further ideas.
MilanKnizek
 
Posts: 4
Joined: Sat Jan 24, 2015 7:44 pm

Re: systemd: daemon ignores any command line parameter

Postby MilanKnizek » Sun Jan 25, 2015 11:41 am

Problem is solved now. The unit file must use $EBUSD_ARGS and not ${EBUSD_ARGS}.

This seems to be a feature of systemd:

$this->bbcode_second_pass_quote('', 'B')asic environment variable substitution is supported. Use "${FOO}" as part of a word, or as a word of its own, on the command line, in which case it will be replaced by the value of the environment variable including all whitespace it contains, resulting in a single argument. Use "$FOO" as a separate word on the command line, in which case it will be replaced by the value of the environment variable split at whitespace resulting in zero or more arguments. For this type of expansion, quotes and respected when splitting into words, and afterwards removed.
MilanKnizek
 
Posts: 4
Joined: Sat Jan 24, 2015 7:44 pm


Return to General

Who is online

Users browsing this forum: No registered users and 27 guests