From 6267fca680f20c5669fda38a467ebe112ef01482 Mon Sep 17 00:00:00 2001 From: Jonathan Steffan Date: Fri, 9 Aug 2013 11:28:28 -0600 Subject: [PATCH] Add conditionals to assist in backporting nginx to non-systemd distros. --- nginx-1.4.2.tar.gz.asc | 11 ++++ nginx.init | 144 +++++++++++++++++++++++++++++++++++++++++ nginx.spec | 56 ++++++++++++++-- nginx.sysconfig | 4 ++ sources | 1 - 5 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 nginx-1.4.2.tar.gz.asc create mode 100644 nginx.init create mode 100644 nginx.sysconfig diff --git a/nginx-1.4.2.tar.gz.asc b/nginx-1.4.2.tar.gz.asc new file mode 100644 index 0000000..8f588d2 --- /dev/null +++ b/nginx-1.4.2.tar.gz.asc @@ -0,0 +1,11 @@ +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.13 (FreeBSD) + +iQEcBAABAgAGBQJR5pgsAAoJEFIKmZOhwFL4EpAH/jwNVReYdC7UprxfrWQQCMGb +SnDJwLycynEtJuexviVl6w/bLkvVYRVrF9zxWEgaqymVjdp9f/AkJgwNlGsVaz4K +T11WuLGK1kZc6LvKZSZVsU6fbxYnkjbnpd2Uo47k+aLHfMMFZ5vtoEdxN5ANxu7A +8AP1r9+n9h5VOYt59IuyPmPn/Q7zPo/tK+snHv2UOupFutcjXe/44eKHpVM8iAnV ++O0so5wuAmbYVatA6/mu1HyWGrFId4qOH/RJeHb+OmGO6gU1QFB3SNe8EgKd4okl +3HepqhhRrJFxfN3mg7qoraHwMhT/ajUWUFcWtJuSEfVCSIPGVpAcTON8EqnplSA= +=HR/R +-----END PGP SIGNATURE----- diff --git a/nginx.init b/nginx.init new file mode 100644 index 0000000..094fc65 --- /dev/null +++ b/nginx.init @@ -0,0 +1,144 @@ +#!/bin/sh +# +# nginx - this script starts and stops the nginx daemon +# +# chkconfig: - 85 15 +# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ +# proxy and IMAP/POP3 proxy server +# processname: nginx +# config: /etc/nginx/nginx.conf +# config: /etc/sysconfig/nginx +# pidfile: /var/run/nginx.pid + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Check that networking is up. +[ "$NETWORKING" = "no" ] && exit 0 + +nginx="/usr/sbin/nginx" +prog=$(basename $nginx) + +sysconfig="/etc/sysconfig/$prog" +lockfile="/var/lock/subsys/nginx" +pidfile="/var/run/${prog}.pid" + +NGINX_CONF_FILE="/etc/nginx/nginx.conf" + +[ -f $sysconfig ] && . $sysconfig + + +start() { + [ -x $nginx ] || exit 5 + [ -f $NGINX_CONF_FILE ] || exit 6 + echo -n $"Starting $prog: " + daemon $nginx -c $NGINX_CONF_FILE + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping $prog: " + killproc -p $pidfile $prog + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + configtest_q || return 6 + stop + start +} + +reload() { + configtest_q || return 6 + echo -n $"Reloading $prog: " + killproc -p $pidfile $prog -HUP + echo +} + +configtest() { + $nginx -t -c $NGINX_CONF_FILE +} + +configtest_q() { + $nginx -t -q -c $NGINX_CONF_FILE +} + +rh_status() { + status $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + +# Upgrade the binary with no downtime. +upgrade() { + local oldbin_pidfile="${pidfile}.oldbin" + + configtest_q || return 6 + echo -n $"Upgrading $prog: " + killproc -p $pidfile $prog -USR2 + retval=$? + sleep 1 + if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then + killproc -p $oldbin_pidfile $prog -QUIT + success $"$prog online upgrade" + echo + return 0 + else + failure $"$prog online upgrade" + echo + return 1 + fi +} + +# Tell nginx to reopen logs +reopen_logs() { + configtest_q || return 6 + echo -n $"Reopening $prog logs: " + killproc -p $pidfile $prog -USR1 + retval=$? + echo + return $retval +} + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart|configtest|reopen_logs) + $1 + ;; + force-reload|upgrade) + rh_status_q || exit 7 + upgrade + ;; + reload) + rh_status_q || exit 7 + $1 + ;; + status|status_q) + rh_$1 + ;; + condrestart|try-restart) + rh_status_q || exit 7 + restart + ;; + *) + echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}" + exit 2 +esac diff --git a/nginx.spec b/nginx.spec index af35dbf..93c30a6 100644 --- a/nginx.spec +++ b/nginx.spec @@ -17,7 +17,7 @@ Name: nginx Epoch: 1 Version: 1.4.2 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A high performance web server and reverse proxy server Group: System Environment/Daemons @@ -33,6 +33,8 @@ Source11: nginx.logrotate Source12: nginx.conf Source13: nginx-upgrade Source14: nginx-upgrade.8 +Source15: nginx.init +Source16: nginx.sysconfig Source100: index.html Source101: poweredby.png Source102: nginx-logo.png @@ -54,17 +56,24 @@ BuildRequires: pcre-devel BuildRequires: perl-devel BuildRequires: perl(ExtUtils::Embed) BuildRequires: zlib-devel -BuildRequires: systemd Requires: GeoIP Requires: gd Requires: openssl Requires: pcre Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version)) Requires(pre): shadow-utils +Provides: webserver + +%if 0%{?fedora} >= 16 +BuildRequires: systemd Requires(post): systemd Requires(preun): systemd Requires(postun): systemd -Provides: webserver +%else +Requires(post): chkconfig +Requires(preun): chkconfig, initscripts +Requires(postun): initscripts +%endif %description Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and @@ -94,8 +103,13 @@ export DESTDIR=%{buildroot} --http-fastcgi-temp-path=%{nginx_home_tmp}/fastcgi \ --http-uwsgi-temp-path=%{nginx_home_tmp}/uwsgi \ --http-scgi-temp-path=%{nginx_home_tmp}/scgi \ +%if 0%{?fedora} >= 16 --pid-path=/run/nginx.pid \ --lock-path=/run/lock/subsys/nginx \ +%else + --pid-path=%{_localstatedir}/run/nginx.pid \ + --lock-path=%{_localstatedir}/lock/subsys/nginx \ +%endif --user=%{nginx_user} \ --group=%{nginx_group} \ --with-file-aio \ @@ -138,9 +152,16 @@ find %{buildroot} -type f -name .packlist -exec rm -f '{}' \; find %{buildroot} -type f -name perllocal.pod -exec rm -f '{}' \; find %{buildroot} -type f -empty -exec rm -f '{}' \; find %{buildroot} -type f -iname '*.so' -exec chmod 0755 '{}' \; - +%if 0%{?fedora} >= 16 install -p -D -m 0644 %{SOURCE10} \ %{buildroot}%{_unitdir}/nginx.service +%else +install -p -D -m 0755 %{SOURCE15} \ + %{buildroot}%{_initrddir}/nginx +install -p -D -m 0644 %{SOURCE16} \ + %{buildroot}%{_sysconfdir}/sysconfig/nginx +%endif + install -p -D -m 0644 %{SOURCE11} \ %{buildroot}%{_sysconfdir}/logrotate.d/nginx @@ -174,7 +195,13 @@ getent passwd %{nginx_user} > /dev/null || \ exit 0 %post +%if 0%{?fedora} >= 16 %systemd_post nginx.service +%else +if [ $1 -eq 1 ]; then + /sbin/chkconfig --add %{name} +fi +%endif if [ $1 -eq 2 ]; then # Make sure these directories are not world readable. chmod 700 %{nginx_home} @@ -183,10 +210,23 @@ if [ $1 -eq 2 ]; then fi %preun +%if 0%{?fedora} >= 16 %systemd_preun nginx.service +%else +if [ $1 -eq 0 ]; then + /sbin/service %{name} stop >/dev/null 2>&1 + /sbin/chkconfig --del %{name} +fi +%endif %postun +%if 0%{?fedora} >= 16 %systemd_postun nginx.service +%else +if [ $1 -eq 2 ]; then + /sbin/service %{name} upgrade || : +fi +%endif %files %doc LICENSE CHANGES README @@ -196,7 +236,12 @@ fi %{_mandir}/man3/nginx.3pm* %{_mandir}/man8/nginx.8* %{_mandir}/man8/nginx-upgrade.8* +%if 0%{?fedora} >= 16 %{_unitdir}/nginx.service +%else +%{_initrddir}/nginx +%config(noreplace) %{_sysconfdir}/sysconfig/nginx +%endif %dir %{nginx_confdir} %dir %{nginx_confdir}/conf.d %config(noreplace) %{nginx_confdir}/fastcgi.conf @@ -224,6 +269,9 @@ fi %changelog +* Fri Aug 09 2013 Jonathan Steffan - 1:1.4.2-3 +- Add in conditionals to build for non-systemd targets + * Sat Aug 03 2013 Petr Pisar - 1:1.4.2-2 - Perl 5.18 rebuild diff --git a/nginx.sysconfig b/nginx.sysconfig new file mode 100644 index 0000000..8ba359b --- /dev/null +++ b/nginx.sysconfig @@ -0,0 +1,4 @@ +# Configuration file for the nginx service + +# set this to the location of the nginx configuration file +NGINX_CONF_FILE=/etc/nginx/nginx.conf diff --git a/sources b/sources index dce5b01..ce0dde4 100644 --- a/sources +++ b/sources @@ -1,2 +1 @@ 5053bacc7df548890f1c93735bddc81e nginx-1.4.2.tar.gz -10fde144b356c0a847f29bef0f611f78 nginx-1.4.2.tar.gz.asc