How can I use spaces in systemd command line arguments?

前端 未结 7 1420
情话喂你
情话喂你 2021-01-17 11:52

I have a systemd unit with spaces in an argument

ExecStart=command --argument=\"text text\"

It seems that systemd does not recognize the do

7条回答
  •  抹茶落季
    2021-01-17 12:12

    Systemd service file supports this

    Environment="TEST=one word"
    Environment="TEST2=second word"
    
    ExecStartPre=-/bin/echo start pre
    ExecStartPre=/bin/echo start pre mandatory
    ExecStart=/bin/echo started : ${TEST} $TEST2
    ExecStartPost=-/bin/echo start post
    ExecStartPost=/bin/echo start post mandatory
    ExecStop=/bin/echo stop
    ExecStopPost=-/bin/echo stop post
    ExecStopPost=/bin/echo stop post mandatory
    ExecReload=/bin/echo reload
    

    log :

    Mar 09 21:39:47 gitlab-runner-1 echo[30286]: start pre
    Mar 09 21:39:47 gitlab-runner-1 echo[30288]: start pre mandatory
    Mar 09 21:39:47 gitlab-runner-1 echo[30295]: started : one word second word
    Mar 09 21:39:47 gitlab-runner-1 echo[30296]: start post
    Mar 09 21:39:47 gitlab-runner-1 echo[30297]: start post mandatory
    Mar 09 21:39:47 gitlab-runner-1 echo[30298]: stop
    Mar 09 21:39:47 gitlab-runner-1 echo[30299]: stop post
    Mar 09 21:39:47 gitlab-runner-1 echo[30300]: stop post mandatory
    

    But you may actually want to set this if the app needs to read the whole string as 2 arguments, each argument between "" (not tested)

    ExecStart=command "$ARG1" "$ARG2"
    

提交回复
热议问题