Help With Systemd
Hi
I am trying to get Greenstone3 http://www.greenstone.org/download to work with systemd. So far I have come up with the following which works but feels more like a hack than a solution. Does anyone have any suggestions on how to do this better ?
# cat /etc/tmpfiles.d/greenstone3.conf d /run/greenstone3 0755 gs3 gs3 –
# cat /etc/systemd/system/greenstone3.service
# Systemd unit file for Greenstone 3
[Unit]
Description=Greenstone 3 Server After=syslog.target network.target
[Service]
Type=forking PIDFile=/run/greenstone3/greenstone3.pid Environment=PATH=/usr/apache-ant-1.9.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
ExecStart=/usr/bin/bash -c “cd /greenstone/gs3/ && ant start ;
/usr/sbin/pidof java | awk ‘{print $1}’ > /run/greenstone3/greenstone3.pid”
SuccessExitStatus3
User=gs3
Group=gs3
[Install]
WantedBy=multi-user.target
Thanks
6 thoughts on - Help With Systemd
2 Comments here:
1.) why ‘cd /greenstone/gs3 && ant start’ when you could just run
‘/greenstone/gs3/ant start’.
2.) You’re going through a lot of effort to generate a pidfile, when it’s completely unnecesary for systemd services.
You could probably replace the ExecStart with:
ExecStart=/greenstone/gs3/ant start
… and get rid of the PIDFile.
thats *not* equivalent, unless ant is in /greenstone/gs3 *and* . is in the path, and even then, ant looks for build.xml in the current path when its invoked, so the cd /path/to/build/ is appropriate.
Hi Jonathan,
Thanks for the feedback
2.) You’re going through a lot of effort to generate a pidfile, when start up and run correctly for a short period but then systemd would put the service into a failed state and kill it off. Based on the documentation below I believe that systemd was “guessing” the Main PID wrong, and so thought the service was dead and killing off all child processes.
“GuessMainPID
Takes a boolean value that specifies whether systemd should try to guess the main PID of a service if it cannot be determined reliably. This option is ignored unless Type=forking is set and PIDFile= is unset because for the other types or with an explicitly configured PID file, the main PID is always known. The guessing algorithm might come to incorrect conclusions if a daemon consists of more than one process. If the main PID cannot be determined, failure detection and automatic restarting of a service will not work reliably. Defaults to yes”
Mind you I only work with ant very rarely but what should work is this:
/path/to/ant -buildfile /greenstone/gs3/build,xml -Dbasedir=/greenstone/gs3
Regards,
Dennis
How about Type=oneshot and RemainAfterExit=yes?
—
Jonathan Billings
Dennis your suggestion works well so for the moment I am going with
# Systemd unit file for Greenstone 3
[Unit]
Description=Greenstone 3 Server After=syslog.target network.target
[Service]
Type=forking Environment=PATH=/usr/apache-ant-1.9.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
ExecStart=/usr/apache-ant-1.9.6/bin/ant -buildfile
/greenstone/gs3/build.xml -Dbasedir=/greenstone/gs3 start ExecStop=/usr/apache-ant-1.9.6/bin/ant -buildfile
/greenstone/gs3/build.xml -Dbasedir=/greenstone/gs3 stop
SuccessExitStatus3
User=gs3
Group=gs3
[Install]
WantedBy=multi-user.target
Thanks to everyone who commented :)