I'm on Debian 8 and I need to set JAVA_HOME in my service. I'm putting this is a script so it needs to query the system first as its not always going to be the same. From command line the ExecStart line works fine but not when I put it in this service. I receive:Aug 12 17:03:16 debian jsvc[6761]: Invalid option -fAug 12 17:03:16 debian jsvc[6761]: Cannot parse command line argumentsAug 12 17:03:16 debian systemd[1]: App1.service: control process exited, code=exited status=1Aug 12 17:03:16 debian systemd[1]: Failed to start App1.-- Subject: Unit App1.service has failedMy Service: [Unit]Description=App1After=syslog.target[Service]ExecStart=/usr/bin/jsvc -user root -home ${readlink -f /usr/bin/java | sed s:bin/java::} -cp /usr/share/java/commons-daemon.jar:/usr/local/app1.jar -pidfile /var/run/app1 -pidfileType=forking
Setting Environment in systemd
debian;systemd
Your exec line will be split on spaces and each word passed as an arg to the command. The simplest solution for you is to enclose the entire command in single quotes and add /bin/bash -c in front of it:ExecStart=/bin/bash -c 'exec /usr/bin/jsvc -user ... -pidfile'Use -cv initially so you can see in the logs what line was passed. I also presume you want $() not ${}, which systemd will not be expanding.