[packages/hhvm] add -fcgi package containing initscript to start as fcgi server

glen glen at pld-linux.org
Fri Jan 3 13:42:31 CET 2014


commit 2347c3aecbf936cd8846236867289d535b65f1a3
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Fri Jan 3 12:41:52 2014 +0000

    add -fcgi package containing initscript to start as fcgi server

 hhvm-fcgi.init      | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hhvm-fcgi.sysconfig |  33 +++++++++++
 hhvm.spec           |  35 +++++++++++-
 3 files changed, 224 insertions(+), 1 deletion(-)
---
diff --git a/hhvm.spec b/hhvm.spec
index 78d938c..32254cc 100644
--- a/hhvm.spec
+++ b/hhvm.spec
@@ -7,7 +7,7 @@
 Summary:	Virtual Machine, Runtime, and JIT for PHP
 Name:		hhvm
 Version:	2.3.2
-Release:	0.8
+Release:	0.19
 License:	PHP 3.01
 Group:		Development/Languages
 Source0:	https://github.com/facebook/hhvm/archive/HHVM-%{version}.tar.gz
@@ -17,6 +17,8 @@ Source1:	http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
 # Source1-md5:	a00e037e4d3f9e4fe9893e8a2d27918c
 Source2:	https://github.com/facebook/folly/archive/4d6d659/folly-0.1-4d6d659.tar.gz
 # Source2-md5:	2e7c941f737c8e0a449b8116e7615656
+Source3:	%{name}-fcgi.init
+Source4:	%{name}-fcgi.sysconfig
 Source100:	get-source.sh
 Patch0:		cmake-missing-library.patch
 Patch1:		libevent14.patch
@@ -138,6 +140,17 @@ webserver and the "mod_php" extension). HHVM can also be used together
 with a FastCGI-based webserver, and work is in progress to make HHVM
 work smoothly with Apache.
 
+%package fcgi
+Summary:	Init script to start HHVM as FastCGI daemon
+Group:		Development/Languages/PHP
+Requires:	%{name} = %{version}-%{release}
+Provides:	php(fcgi)
+Requires(post,preun):	/sbin/chkconfig
+Requires:	rc-scripts
+
+%description fcgi
+Init script to start HHVM as FastCGI daemon
+
 %package program
 Summary:	/usr/bin/php symlink
 Summary(pl.UTF-8):	Dowiązanie symboliczne /usr/bin/php
@@ -261,6 +274,11 @@ ln -s hhvm $RPM_BUILD_ROOT%{_bindir}/hphp
 install -d $RPM_BUILD_ROOT%{_datadir}/%{name}/hdf
 cp -p hphp/doc/mime.hdf $RPM_BUILD_ROOT%{_datadir}/%{name}/hdf/static.mime-types.hdf
 
+# install fastcgi initscript
+install -d $RPM_BUILD_ROOT/etc/{sysconfig,rc.d/init.d}
+cp -p %{SOURCE3} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}-fcgi
+cp -p %{SOURCE4} $RPM_BUILD_ROOT/etc/sysconfig/%{name}-fcgi
+
 # install our libevent for now
 install -d $RPM_BUILD_ROOT%{_libdir}
 libtool --mode=install install -p libevent/libevent.la $RPM_BUILD_ROOT%{_libdir}
@@ -308,6 +326,16 @@ rm -rf $RPM_BUILD_ROOT
 %post	-p /sbin/ldconfig
 %postun	-p /sbin/ldconfig
 
+%post fcgi
+/sbin/chkconfig --add %{name}-fcgi
+%service %{name}-fcgi restart
+
+%preun fcgi
+if [ "$1" = "0" ]; then
+	%service -q %{name}-fcgi stop
+	/sbin/chkconfig --del %{name}-fcgi
+fi
+
 %files
 %defattr(644,root,root,755)
 %doc README.md hphp/NEWS
@@ -320,6 +348,11 @@ rm -rf $RPM_BUILD_ROOT
 %dir %{_datadir}/%{name}/hdf
 %{_datadir}/%{name}/hdf/static.mime-types.hdf
 
+%files fcgi
+%defattr(644,root,root,755)
+%attr(754,root,root) /etc/rc.d/init.d/%{name}-fcgi
+%config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name}-fcgi
+
 %files program
 %defattr(644,root,root,755)
 %attr(755,root,root) %{_bindir}/php
diff --git a/hhvm-fcgi.init b/hhvm-fcgi.init
new file mode 100755
index 0000000..ca1de3d
--- /dev/null
+++ b/hhvm-fcgi.init
@@ -0,0 +1,157 @@
+#!/bin/sh
+#
+# hhvm-fcgi -- startup script for HHVM FastCGI
+#
+# chkconfig:	345 80 20
+#
+# description:  Starts The HHVM FastCGI Daemon
+# processname:	hhvm-fcgi
+# config:	/etc/hhvm/server.hdf
+# pidfile:	/var/run/hhvm/hhvm-fcgi.pid
+#
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get network config
+. /etc/sysconfig/network
+
+# Check that networking is up.
+if is_yes "${NETWORKING}"; then
+	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+		msg_network_down "HHVM FastCGI Daemon"
+		exit 1
+	fi
+else
+	exit 0
+fi
+
+# Set defaults
+# Default values. This values can be overwritten in '/etc/sysconfig/hhvm-fcgi'
+DAEMON="/usr/bin/hhvm"
+NAME="hhvm"
+CONFIG_FILE="/etc/hhvm/server.hdf"
+RUN_AS_USER="http"
+LISTEN_PORT="9000"
+ADDITIONAL_ARGS=""
+
+# Get service config - may override defaults
+[ -f /etc/sysconfig/hhvm-fcgi ] && . /etc/sysconfig/hhvm-fcgi
+
+PIDFILE="/var/run/hhvm/hhvm-fcgi.pid"
+DAEMON_ARGS="--config ${CONFIG_FILE} \
+--user ${RUN_AS_USER} \
+--mode daemon \
+-vServer.Type=fastcgi \
+-vServer.Port=${LISTEN_PORT} \
+-vPidFile=${PIDFILE} \
+${ADDITIONAL_ARGS}"
+
+# configtest itself
+# must return non-zero if check failed
+# output is discarded if checkconfig is ran without details
+configtest() {
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test
+}
+
+# wrapper for configtest
+checkconfig() {
+	local details=${1:-0}
+
+	if [ $details = 1 ]; then
+		# run config test and display report (status action)
+		show "Checking %s configuration" "HHVM FastCGI Daemon"; busy
+		local out
+		out=$(configtest 2>&1)
+		RETVAL=$?
+		if [ $RETVAL = 0 ]; then
+			ok
+		else
+			fail
+		fi
+		[ "$out" ] && echo >&2 "$out"
+	else
+		# run config test and abort with nice message if failed
+		# (for actions checking status before action).
+		configtest >/dev/null 2>&1
+		RETVAL=$?
+		if [ $RETVAL != 0 ]; then
+			show "Checking %s configuration" "HHVM FastCGI Daemon"; fail
+			nls 'Configuration test failed. See details with %s "checkconfig"' $0
+			exit $RETVAL
+		fi
+	fi
+}
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/hhvm-fcgi ]; then
+		msg_already_running "HHVM FastCGI Daemon"
+		return
+	fi
+
+	checkconfig
+	msg_starting "HHVM FastCGI Daemon"
+	daemon --pidfile $PIDFILE $DAEMON $DAEMON_ARGS
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/hhvm-fcgi
+}
+
+stop() {
+	if [ ! -f /var/lock/subsys/hhvm-fcgi ]; then
+		msg_not_running "HHVM FastCGI Daemon"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "HHVM FastCGI Daemon"
+	killproc --pidfile $PIDFILE $NAME -TERM
+	RETVAL=$?
+	rm -f /var/lock/subsys/hhvm-fcgi
+}
+
+condrestart() {
+	if [ ! -f /var/lock/subsys/hhvm-fcgi ]; then
+		msg_not_running "HHVM FastCGI Daemon"
+		RETVAL=$1
+		return
+	fi
+
+	checkconfig
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	checkconfig
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  force-reload)
+	condrestart 7
+	;;
+  checkconfig|configtest)
+	checkconfig 1
+	;;
+  status)
+	status --pidfile $PIDFILE hhvm-fcgi hhvm
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
+	exit 3
+esac
+
+exit $RETVAL
diff --git a/hhvm-fcgi.sysconfig b/hhvm-fcgi.sysconfig
new file mode 100644
index 0000000..9b4f829
--- /dev/null
+++ b/hhvm-fcgi.sysconfig
@@ -0,0 +1,33 @@
+## This is a configuration file for /etc/init.d/hhvm-fastcgi.
+## Overwrite start up configuration of the hhvm-fastcgi service.
+##
+## This file is sourced by /bin/sh from /etc/init.d/hhvm-fastcgi.
+
+## Configuration file location.
+## Default: "/etc/hhvm/server.hdf"
+## Examples:
+##   "/etc/hhvm/conf.d/fastcgi.hdf" Load configuration file from Debian/Ubuntu conf.d style location
+#CONFIG_FILE="/etc/hhvm/server.hdf"
+
+## User to run the service as.
+## Default: "http"
+## Examples:
+##   "hhvm"   Custom 'hhvm' user
+##   "nobody" RHEL/CentOS 'www-data' equivalent
+#RUN_AS_USER="http"
+
+## Listen port of service.
+## This is useful if the port is used by an other service like PHP-FPM.
+## Default: "9000"
+#LISTEN_PORT="9000"
+
+## Add additional arguments to the hhvm service start up.
+## Default: ""
+## Examples:
+##   "-vLog.Level=Debug"                Enable debug log level
+##   "-vServer.DefaultDocument=app.php" Change the default document
+#ADDITIONAL_ARGS=""
+
+## PID file location.
+## Default: "/var/run/hhvm/hhvm-fcgi.pid"
+#PIDFILE="/var/run/hhvm/hhvm-fcgi.pid
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/hhvm.git/commitdiff/2347c3aecbf936cd8846236867289d535b65f1a3



More information about the pld-cvs-commit mailing list