I have been trying to get a service file setup for our software so that it can be started and stopped. When I manually run the commands, the server starts normal. I next took this an implemented this into a bash script and it also starts normal. The bash script:
#!/bin/bash
/bin/cd /opt/software/test/; source software_env.sh
export TEST_APP="/opt/software/testapp"
/bin/cd /opt/sotware/test/bin/; startserver
I tried to just implement those commands into a system file, but cannot seem to get it write. So the next thing I tried was to leave the bash script and call it from a system file that looked like:
[Unit]
Description=Test Service
[Service]
Type=forking
ExecStart=/opt/software/test/test.startup
[Install]
WantedBy=multi-user.target
I have also tried setting the servive type as Type=simple but that also does not work.
I can successfully start the server by running the bash script via cron at reboot, but if there is a way to get that bash script into a service file that is ultimately what I am looking to do.
The difficulty appears to be getting the source and export to work properly in the unit file. I also noticed some strange behavior when I was getting the bash script to work, that running: source /opt/software/test/software_env.sh instead of /bin/cd /opt/software/test/; source software_env.sh does not work.
The error from systemd reguardless of the different techniques to try to get it to run have all given this error.
test.service - Test service
Loaded: bad-setting (Reason: Unit test.service has a bad unit file setting.)
Active: failed (Result: exit-code)
Main PID: 2778 (code=exited, status)
Thank you for any and all suggestions.
test.startupthe same as the bash script you posted, or is it something different? Are you trying to run source and export in the service file directly or intest.startup?/opt/software/testdirectory. The export command does not care where it is run from. And I did also double check that there is not a separate source file inside the directory where it works.export TEST_APP-...should beexport TEST_APP=..., right?export TEST_APP=..., in terms of the specifics, the error message when I try to start it as a service just says failed with no other useful information. But if I instead just run the bash script it all works as expected. I wasn't sure if there might be a way to run source and export inside the unit file instead, I could not find anything online indicating how to properly do that.Loaded: bad-setting (Reason: Unit test.service has a bad unit file setting.)Could you add the output of:systemd-analyze verify test.service? It should give you more info about what is wrong... Most likely a problem with access permissions or no execute bits set on the script used inExecStart=.