Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use spaces in systemd command line arguments?

Tags:

systemd

I have a systemd unit with spaces in an argument

ExecStart=command --argument="text text"

It seems that systemd does not recognize the double or single quotes and it splits up the argument into two arguments. Any idea how I can prevent that? I am using systemd v218 within CoreOS.

like image 720
Wolfgang Avatar asked Mar 05 '15 15:03

Wolfgang


People also ask

Which is the correct way of handling arguments with spaces?

11. Which is the correct way of handling arguments with spaces? Explanation: One can use either single or double quotes to handle command line argument with spaces in-between.

What is ExecStart in Systemd?

This option is mandatory for services where Type=dbus . ExecStart. The commands and arguments executed when the service starts. ExecStartPre, ExecStartPost. Additional commands that are executed before or after the command in ExecStart .

How do I check my Systemd service status?

To check a service's status, use the systemctl status service-name command. I like systemd's status because of the detail given. For example, in the above listing, you see the full path to the unit file, the status, the start command, and the latest status changes.


2 Answers

systemd only seems to recognize quotes which fully wrap arguments; i.e.

ExecStart=command "--argument=text text"

works but

ExecStart=command --argument="text text"

does not. I just ran into this issue and filed #624 about it.

like image 87
Tgr Avatar answered Oct 08 '22 14:10

Tgr


This is actually surprisingly difficult to do, unfortunately. I stole this info from this answer. The only way to do it is to put your arguments in an environment file and then use them as variables as such (like in /etc/.progconfig):

ARG1=text
ARG2=text

Then import the environment file before running your command:

EnvironmentFile=/etc/.progconf
ExecStart = command $ARG1 $ARG2
like image 27
nico Avatar answered Oct 08 '22 12:10

nico