augeas
augeas copied to clipboard
systemd lens: augparse fails on Environment= with whitespaces
Hello,
I need to hand over some environment variables to my service that is started via systemd. The unit-file is to be managed via an Augeas lens in Puppet. Sadly one of my environment variables contains whitespace and this is where the lens fails. I tried to resolve the issue myself, but Augeas syntax proves to be somewhat harder to learn ;-)
The unit-file is below.
The culprit is the line:
Environment=APPLICATION_NAME=Spring Boot Test App
I get the error:
# augparse test_systemd.aug
test_systemd.aug:62.0-.29:exception thrown in test
test_systemd.aug:62.5-.25:exception: Get did not match entire input
Lens: /usr/share/augeas/lenses/dist/inifile.aug:497.25-.43:
Error encountered at 24:0 (673 characters into string)
<ar\n\n# Your application name\n|=|Environment=APPLICATION_NAME>
If I change the line to:
Environment=APPLICATION_NAME=SpringBootTestApp
it works and augparse confirms a valid file.
I tried escaping the string with single-ticks and double-quotes but nothing helped.
Is there a way to format it in a syntax-conform way? Or does the lens need to be changed? As environment variables with whitespaces are accepted by systemd. And I see no reason why the Augeas lens should fail on them.
System details: Debian Jessie 8.6 augeas-lenses 1.2.0-0.2+deb8u1 augeas-tools 1.2.0-0.2+deb8u1 libaugeas0 1.2.0-0.2+deb8u1 As the /usr/share/augeas/lenses/dist/systemd.aug file on Debian differs a little bit from the one on GitHub I also used the latest from GitHub. But the error still exists.
Unit file for reference:
[Unit]
Description=Jar-Service on 127.0.0.1:8080
After=syslog.target network.target
[Service]
User=username
Group=groupname
WorkingDirectory=/home/username/
Restart=always
# IP jar should bind to
Environment=APPLICATION_IP=127.0.0.1
# Port jar should bind to
Environment=APPLICATION_PORT=8080
# Your application name
Environment=APPLICATION_NAME=Spring Boot Test App
# Logfile path/name
Environment=APPLICATION_LOG=/home/username/logs/application-8080.log
# Path to .jar to start
ExecStart=/usr/bin/java -jar /home/username/gs-spring-boot-0.1.0.jar
[Install]
WantedBy=multi-user.target
If I change the line to: Environment=APPLICATION_NAME=SpringBootTestApp it works and augparse confirms a valid file.
I tried escaping the string with single-ticks and double-quotes but nothing helped.
Is there a way to format it in a syntax-conform way?
Augeas (and systemd) can parse spaces in environment variables when quoted in this way:
Environment="APPLICATION_NAME=Spring Boot Test App"
Edit: introduced in 5226ae7, Augeas 1.3.0.
Or does the lens need to be changed? As environment variables with whitespaces are accepted by systemd. And I see no reason why the Augeas lens should fail on them.
Correct, it's a bug in the lens if systemd accepts this syntax. f64d8bc did fix support for FOO="bar"
but only when the value didn't contain spaces.
Augeas (and systemd) can parse spaces in environment variables when quoted in this way: Environment="APPLICATION_NAME=Spring Boot Test App"
If I do that, I get:
# augparse test_systemd.aug
Syntax error in lens definition
test_systemd.aug:9.11-26.16:syntax error, unexpected UIDENT, expecting $end
test_systemd.aug:syntax error
my test_systemd.aug file is basically just:
(*
Module: Test_Systemd
Provides unit tests and examples for the <Systemd> lens.
*)
module Test_Systemd =
(* Variable: desc *)
let desc = "[Unit]
(... The Unit file from above ...)
[Install]
WantedBy=multi-user.target
"
test Systemd.lns get desc = ?
Correct, it's a bug in the lens if systemd accepts this syntax. f64d8bc did fix support for FOO="bar" but only when the value didn't contain spaces.
So, do I need to do any additional actions that this will be fixed by someone? Or is this issue enough?
If I do that, I get:
# augparse test_systemd.aug Syntax error in lens definition test_systemd.aug:9.11-26.16:syntax error, unexpected UIDENT, expecting $end test_systemd.aug:syntax error
There's probably a syntax error in the test file, but it's hard to say for sure as the failing bit (line 9-26) is not from your comment.
I'd probably guess that you need to escape quotes because it's in a quoted value in the test file. The real file obviously will not need escaped quotes.
So, do I need to do any additional actions that this will be fixed by someone? Or is this issue enough?
No, unless you want to fix it. I'll leave this open and hopefully it'll be fixed one day.
I'd probably guess that you need to escape quotes because it's in a quoted value in the test file. The real file obviously will not need escaped quotes.
Doh.. Yes. Forgot the escaping.. And yes, I removed some comments and sensitive company stuff. Switched exactly to the unit-file I provided above from now on. But even with that file and the escaped quoting, I get the same error:
# augparse test_systemd2.aug
test_systemd2.aug:39.0-.29:exception thrown in test
test_systemd2.aug:39.5-.25:exception: Get did not match entire input
Lens: /usr/share/augeas/lenses/dist/inifile.aug:497.25-.43:
Error encountered at 18:0 (321 characters into string)
<80\n\n# Your application name\n|=|Environment="APPLICATION_NAM>
Complete file is now:
(*
Module: Test_Systemd2
Provides unit tests and examples for the <Systemd> lens.
*)
module Test_Systemd2 =
(* Variable: desc *)
let desc = "[Unit]
Description=Jar-Service on 127.0.0.1:8080
After=syslog.target network.target
[Service]
User=username
Group=groupname
WorkingDirectory=/home/username/
Restart=always
# IP jar should bind to
Environment=APPLICATION_IP=127.0.0.1
# Port jar should bind to
Environment=APPLICATION_PORT=8080
# Your application name
Environment=\"APPLICATION_NAME=Spring Boot Test App\"
# Logfile path/name
Environment=APPLICATION_LOG=/home/username/logs/application-8080.log
# Path to .jar to start
ExecStart=/usr/bin/java -jar /home/username/gs-spring-boot-0.1.0.jar
[Install]
WantedBy=multi-user.target
"
test Systemd.lns get desc = ?
Is that with 1.2.0 still, or the lens from master? I made an edit earlier to add that the quoting support was in 1.3.0 or higher.
Yes, that was the Debian-Lens again, using the one from GitHub works. No errors. And arguments are recognized.
Good, so I will change the systemd lens to the one from GitHub and quote the string. Works for me :-)
{ "#comment" = "Your application name" }
{ "Environment"
{ "APPLICATION_NAME" = "Spring Boot Test App" }
Cool ! Is there anything else that needs to be done here or can we close this issue ?
@lutter support for parsing Environment=FOO="bar baz"
needs adding to Systemd.
After commit d438f523de4e7ed012897de53cd9340d6728cf98 the syntax Environment=FOO="bar baz"
should be supported.