I modified unit files according to your post:
[Unit]
Description=My Portal Service
After=network.target
[Service]
SyslogIdentifier=my-portal
Environment=SERVICE_NAME=my-portal
Environment=PATH_TO_TARGET=/opt/apps/egp/stage/my-portal/target
ExecStart=/usr/bin/env java -jar ${PATH_TO_TARGET}/${SERVICE_NAME}.jar server ${PATH_TO_TARGET}/${SERVICE_NAME}.yml
[Install]
WantedBy=multi-user.target
I also run command:
systemctl daemon-reload
to reload systemd manager configuration.
All is working fine - I can successfully start, stop and see the status of the service using:
systemctl start my-portal
systemctl status my-portal -l
systemctl stop my-portal
And after I fix the problem with Java env variables - I will run this command:
systemctl enable service-name
to start service (services- 5 in total) on boot.
The problem I have is setting Java env variables. I tried various versions: adding them in .bash_profile and using source command,then writing Java env in separate javaenv.sh file in /etc/profile.d folder:
export JAVA_HOME=/opt/jdk1.7.0_80
export PATH=/opt/jdk1.7.0_80/bin:$PATH
Gave permission:
chmod +x /etc/profile.d/javaenv.sh
and modified unit file adding ${JAVA_HOME}/bin in ExecStart line... It does not finding Java. I had the same problem before, when I was using sh scripts getting the error:
nohup: failed to run command ‘java’: No such file or directory
I read many posts on that issue - but cannot find the solution to set Java variables in one place and use them in other units or script files as ${JAVA_HOME} variables.
Where to set Java env variables to be used in various places permanently without logging?