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" SuccessExitStatus=143 User=gs3 Group=gs3 [Install] WantedBy=multi-user.target Thanks
On Thu, Sep 24, 2015 at 09:36:59AM +1200, Clint Dilks wrote:> # 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"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. -- Jonathan Billings <billings at negate.org>
On 9/23/2015 2:58 PM, Jonathan Billings wrote:> 1.) why 'cd /greenstone/gs3 && ant start' when you could just run > '/greenstone/gs3/ant start'.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. -- john r pierce, recycling bits in santa cruz
Hi Jonathan, Thanks for the feedback 2.) You're going through a lot of effort to generate a pidfile, when> it's completely unnecesary for systemd services. > > I tried not using a pidfile initially and this that case things wouldstart 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"