0

When I run the following part in a bash script it works:

/usr/bin/java \
-Dspring.index.ignore=true \
--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED \
--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED \
--illegal-access=permit \
-jar /home/x/my.jar \
--spring.config.additional-location=/home/x/config.yml

However if I modify it slightly to use it as a part of a systemd-service:

ExecStart=/usr/bin/java \
-Dspring.index.ignore=true \
--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED \
--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED \
--illegal-access=permit \
-jar /home/x/my.jar \
--spring.config.additional-location=/home/x/config.yml

It shows me:

● my.service - my
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

 Unknown lvalue '--illegal-access' in section 'Service'
 Missing '='.
 Ignoring unknown escape sequences: "\"
 Unknown lvalue '--add-exports' in section 'Service'
 Unknown lvalue '--add-exports' in section 'Service'
 Unknown lvalue '--add-exports' in section 'Service'
 Unknown lvalue '--add-exports' in section 'Service'
 Unknown lvalue '--add-exports' in section 'Service'
 Unknown lvalue '--illegal-access' in section 'Service'
 Missing '='.

What is the right syntax for this? I was so sure that simple bash should work here.

P.S. Just noticed if I place everything in one line, it works. However it would be great to know how to keep everything on multiple lines.

3
  • Did you try just putting it all on one line and removing the backslashes?
    – muru
    Aug 12, 2020 at 11:46
  • Backslashes are documented as usable to merge lines; are you sure they are all present, and all the very last character on their line? Aug 12, 2020 at 11:48
  • Why don't you make an executable file out of your java -jar command, my.sh for example and then ExecStart=/home/x/my.sh
    – Krackout
    Aug 12, 2020 at 13:56

1 Answer 1

1

I was so sure that simple bash should work here.

bash is not a generic term for shell script, and the value of the ExecStart setting of a service unit is not shell script at all, let alone Bourne Again shell script. Many people over the years thinking that they can put shell script here, transposed from actual shell scripts or shell command-line input, has resulted in the systemd manual eventually being quite explicit about this. See the "Command lines" section of man systemd.service.

The manual states only that a trailing backslash merges lines. A backslash with whitespace characters (CR, SPC, et al.) between it and the end of the line is (of course) not a trailing one. Thus all of the subsequent lines become (malformed or invalid) further key+value settings.

Read the systemd.service manual and understand the rules for what you are actually using here. It is not shell script, and you should not be working with the assumption that it is and that you can just treat it as such, even if that approach gets lucky from time to time.

Further reading

2
  • Of course. But sometimes it's not enough time to understand any detail and you do something based on your intuition.
    – ka3ak
    Aug 12, 2020 at 14:05
  • I see. The line "-jar /home/x/my.jar \" caused the problem. I splitted it in two lines.
    – ka3ak
    Aug 12, 2020 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .