PHP FCGI startup with systemd

Date: 2016-07-04
#!/bin/bash 
# -xv
#

service=php-cgi-config
pid=/var/run/php-fastcgi.pid
action=$1

fcgi=/usr/bin/spawn-fcgi
php=/usr/bin/php-cgi
phpcfg=/etc/php

ip=127.0.0.1
port=9000
children=2
user=http
group=http

function s_start() 
{
	s_stop	
	$fcgi -a $ip -p $port -P $pid -C $children -u $user -g $group -- $php -c $phpcfg
}

function s_stop() 
{
	if [ -e "$pid" ]; then
		kill -TERM $(cat $pid)
	fi
}


function main() {

	if [ "$action" == "start" ]; then	
		echo Starting $service
		s_start
	fi

	if [ "$action" == "stop" ]; then
		echo Stopping $service
		s_stop
	fi
	echo Finished
}

main
[Unit]
Description=PHP CGI server
After=syslog.target network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/configscripts/php-cgi-setup.sh start
ExecStop=/etc/configscripts/php-cgi-setup.sh stop

[Install]
WantedBy=multi-user.target
2210cookie-checkPHP FCGI startup with systemd