summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2017-10-19 18:23:31 +0300
committerAndrei Belov <defan@nginx.com>2017-10-19 18:23:31 +0300
commiteabe25d98e6805221025daf7bc60d881af1af6b1 (patch)
tree23a72fc526122de22909c62bb06af95d7c5572da
parentc8a8a7c2120e276777f97dcee6d489788417792a (diff)
downloadunit-eabe25d98e6805221025daf7bc60d881af1af6b1.tar.gz
unit-eabe25d98e6805221025daf7bc60d881af1af6b1.tar.bz2
Introduced rpm packages building tools.
-rw-r--r--docs/Makefile2
-rw-r--r--docs/changes.xml39
-rw-r--r--pkg/Makefile17
-rw-r--r--pkg/rpm/Makefile137
-rw-r--r--pkg/rpm/Makefile.go63
-rw-r--r--pkg/rpm/Makefile.php49
-rw-r--r--pkg/rpm/Makefile.python49
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.example-go-app20
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.example-go-config15
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.example-php-app1
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.example-php-config17
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.example-python-app16
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.example-python-config17
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.example.config39
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.init116
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.loadconfig.sh25
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.saveconfig.sh24
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.service14
-rw-r--r--pkg/rpm/rpmbuild/SOURCES/unit.sysconf1
-rw-r--r--pkg/rpm/unit.module.spec.in90
-rw-r--r--pkg/rpm/unit.spec.in182
21 files changed, 932 insertions, 1 deletions
diff --git a/docs/Makefile b/docs/Makefile
index c53ae895..b5494fd2 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -5,7 +5,7 @@ UNIT= unit-$(VER)
DEST= ../build
XSLS?= xslscript.pl
-PACKAGES= unit
+PACKAGES= unit unit-php unit-python unit-go
all: changes changelogs
diff --git a/docs/changes.xml b/docs/changes.xml
index 51b99d41..09358398 100644
--- a/docs/changes.xml
+++ b/docs/changes.xml
@@ -5,6 +5,45 @@
<change_log title="unit">
+<changes apply="unit-go" ver="0.2" rev="1"
+ date="2017-10-19" time="18:00:00 +0300"
+ packager="Andrei Belov &lt;defan@nginx.com&gt;">
+
+<change>
+<para>
+Initial release of Go module for NGINX Unit.
+</para>
+</change>
+
+</changes>
+
+
+<changes apply="unit-python" ver="0.2" rev="1"
+ date="2017-10-19" time="18:00:00 +0300"
+ packager="Andrei Belov &lt;defan@nginx.com&gt;">
+
+<change>
+<para>
+Initial release of Python module for NGINX Unit.
+</para>
+</change>
+
+</changes>
+
+
+<changes apply="unit-php" ver="0.2" rev="1"
+ date="2017-10-19" time="18:00:00 +0300"
+ packager="Andrei Belov &lt;defan@nginx.com&gt;">
+
+<change>
+<para>
+Initial release of PHP module for NGINX Unit.
+</para>
+</change>
+
+</changes>
+
+
<changes apply="unit" ver="0.2" rev="1"
date="2017-10-19" time="18:00:00 +0300"
packager="Andrei Belov &lt;defan@nginx.com&gt;">
diff --git a/pkg/Makefile b/pkg/Makefile
new file mode 100644
index 00000000..4500684d
--- /dev/null
+++ b/pkg/Makefile
@@ -0,0 +1,17 @@
+#!/usr/bin/make
+
+VERSION ?= $(shell grep 'define NXT_VERSION' ../src/nxt_main.h \
+ | sed -e 's/^.*"\(.*\)".*/\1/')
+
+RELEASE ?= 1
+
+default:
+ @echo "available targets: rpm"
+
+rpm:
+ @cd rpm && VERSION=$(VERSION) RELEASE=$(RELEASE) make all
+
+clean:
+ @cd rpm && make clean
+
+.PHONY: default rpm clean
diff --git a/pkg/rpm/Makefile b/pkg/rpm/Makefile
new file mode 100644
index 00000000..2a839444
--- /dev/null
+++ b/pkg/rpm/Makefile
@@ -0,0 +1,137 @@
+#!/usr/bin/make
+
+DEFAULT_VERSION := $(shell grep 'define NXT_VERSION' ../../src/nxt_main.h \
+ | sed -e 's/^.*"\(.*\)".*/\1/')
+
+DEFAULT_RELEASE := 1
+
+VERSION ?= $(DEFAULT_VERSION)
+RELEASE ?= $(DEFAULT_RELEASE)
+
+BUILD_DEPENDS = libxml2 libxslt rpm-build rpmlint
+
+MODULES=
+-include Makefile.*
+
+CONFIGURE_ARGS=\
+ --prefix=/usr \
+ --state=%{_sharedstatedir}/unit \
+ --control="unix:/var/run/control.unit.sock" \
+ --pid=/var/run/unit.pid \
+ --log=/var/log/unit.log \
+ --tests
+
+export CR=\\n
+
+default:
+ @echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs clean"
+
+all: check-build-depends unit modules
+
+modules: $(addprefix unit-, $(MODULES))
+
+specs: $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
+
+check-build-depends:
+ @{ \
+ not_installed= ; \
+ for pkg in $(BUILD_DEPENDS); do \
+ rpm -qi $${pkg} >/dev/null 2>&1 ; \
+ if [ $$? -ne 0 ]; then \
+ not_installed="$${not_installed} $${pkg}" ; \
+ fi ; \
+ done ; \
+ if test -n "$${not_installed}" ; then \
+ echo "" >&2 ; \
+ echo "The following packages are required in order to proceed:" >&2 ; \
+ echo "" >&2 ; \
+ echo $${not_installed} >&2 ; \
+ echo "" >&2 ; \
+ exit 1 ; \
+ fi \
+ }
+
+rpmbuild/SPECS:
+ mkdir -p rpmbuild/SPECS
+
+rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
+ cat unit.spec.in | \
+ sed -e "s#%%VERSION%%#$(VERSION)#g" \
+ -e "s#%%RELEASE%%#$(RELEASE)#g" \
+ -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
+ > rpmbuild/SPECS/unit.spec
+ cd ../../docs && make ../build/unit.rpm-changelog
+ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
+ cat ../../build/unit.rpm-changelog | sed -e \
+ "s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
+ >> rpmbuild/SPECS/unit.spec
+else
+ cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
+endif
+
+rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
+ cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
+ --transform "s#^#unit-$(VERSION)/#" \
+ LICENSE NOTICE CHANGES README configure auto src test
+
+unit: rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
+ @echo "===> Building $@ package" ; \
+ rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
+ ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
+
+rpmlint:
+ find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
+
+rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
+ @echo "===> Creating $@"
+ @{ \
+ set -e ; \
+ i=100 ; \
+ sources= ; \
+ for src in $(MODULE_SOURCES_$*); do \
+ s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
+ sources="$${sources}\n$${s}" ; \
+ i=$$(($${i}+1)) ; \
+ done ; \
+ pkgname=$(shell echo $@ | cut -d '/' -f 3 | cut -d '.' -f 1) ; \
+ definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+ preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+ files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+ post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+ cat unit.module.spec.in | sed \
+ -e "s#%%NAME%%#$${pkgname}#g" \
+ -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
+ -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
+ -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
+ -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
+ -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
+ -e "s#%%MODULE_SOURCES%%#$${sources}#g" \
+ -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
+ -e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
+ -e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
+ -e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
+ -e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
+ -e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
+ -e "s#%%MODULE_FILES%%#$${files}#g" \
+ -e "s#%%MODULE_POST%%#$${post}#g" \
+ > $@.tmp ; \
+ }
+ cd ../../docs && make ../build/unit-$*.rpm-changelog
+ cat ../../build/unit-$*.rpm-changelog | sed -e \
+ "s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
+ >> $@.tmp
+ mv $@.tmp $@
+
+unit-%: rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
+ @echo "===> Building $@ package" ; \
+ rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
+ ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
+
+clean:
+ rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
+ rm -f rpmbuild/SOURCES/unit-*.tar.gz unit
+ find . -maxdepth 1 -type l -delete
+
+.PHONY: default all modules specs check-build-depends rpmlint clean
+
+.SECONDARY:
diff --git a/pkg/rpm/Makefile.go b/pkg/rpm/Makefile.go
new file mode 100644
index 00000000..9dfbca77
--- /dev/null
+++ b/pkg/rpm/Makefile.go
@@ -0,0 +1,63 @@
+MODULES+= go
+
+MODULE_SUMMARY_go= Go module for NGINX Unit
+
+MODULE_VERSION_go= $(VERSION)
+MODULE_RELEASE_go= 1
+
+MODULE_CONFARGS_go= go --go-path=%{goroot}
+MODULE_MAKEARGS_go= go
+MODULE_INSTARGS_go= go-install
+
+MODULE_SOURCES_go= unit.example-go-app \
+ unit.example-go-config
+
+BUILD_DEPENDS+= golang
+
+define MODULE_DEFINITIONS_go
+%define goroot %(go env GOROOT)
+%define goos %(go env GOOS)
+%define goarch %(go env GOARCH)
+
+BuildRequires: golang
+endef
+export MODULE_DEFINITIONS_go
+
+define MODULE_PREINSTALL_go
+QA_SKIP_BUILD_ROOT=1
+export QA_SKIP_BUILD_ROOT
+
+%{__mkdir} -p %{buildroot}%{_datadir}/doc/unit-go/examples/go-app
+%{__install} -m 644 -p %{SOURCE100} \
+ %{buildroot}%{_datadir}/doc/unit-go/examples/go-app/let-my-people.go
+%{__install} -m 644 -p %{SOURCE101} \
+ %{buildroot}%{_datadir}/doc/unit-go/examples/unit.config
+endef
+export MODULE_PREINSTALL_go
+
+define MODULE_FILES_go
+%dir %{goroot}/src/unit
+%{goroot}/src/unit/*
+%{goroot}/pkg/%{goos}_%{goarch}/unit.a
+endef
+export MODULE_FILES_go
+
+define MODULE_POST_go
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_go) has been installed.
+
+To check the sample app, run these commands:
+
+ go build -o /tmp/go-app /usr/share/doc/unit-go/examples/go-app/let-my-people.go
+ sudo service unit start
+ sudo service unit loadconfig /usr/share/doc/unit-go/examples/unit.config
+ curl http://localhost:8500/
+
+Online documentation is available at https://unit.nginx.org
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_go
diff --git a/pkg/rpm/Makefile.php b/pkg/rpm/Makefile.php
new file mode 100644
index 00000000..dcaee2a8
--- /dev/null
+++ b/pkg/rpm/Makefile.php
@@ -0,0 +1,49 @@
+MODULES+= php
+
+MODULE_SUMMARY_php= PHP module for NGINX Unit
+
+MODULE_VERSION_php= $(VERSION)
+MODULE_RELEASE_php= 1
+
+MODULE_CONFARGS_php= php
+MODULE_MAKEARGS_php= php
+MODULE_INSTARGS_php= php-install
+
+MODULE_SOURCES_php= unit.example-php-app \
+ unit.example-php-config
+
+BUILD_DEPENDS+= php-devel php-embedded
+
+define MODULE_PREINSTALL_php
+%{__mkdir} -p %{buildroot}%{_datadir}/doc/unit-php/examples/phpinfo-app
+%{__install} -m 644 -p %{SOURCE100} \
+ %{buildroot}%{_datadir}/doc/unit-php/examples/phpinfo-app/index.php
+%{__install} -m 644 -p %{SOURCE101} \
+ %{buildroot}%{_datadir}/doc/unit-php/examples/unit.config
+endef
+export MODULE_PREINSTALL_php
+
+define MODULE_FILES_php
+%{_libdir}/unit/modules/*
+%{_libdir}/unit/debug-modules/*
+endef
+export MODULE_FILES_php
+
+define MODULE_POST_php
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_php) has been installed.
+
+To check out the sample app, run these commands:
+
+ sudo service unit start
+ sudo service unit loadconfig /usr/share/doc/unit-php/examples/unit.config
+ curl http://localhost:8300/
+
+Online documentation is available at https://unit.nginx.org
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_php
diff --git a/pkg/rpm/Makefile.python b/pkg/rpm/Makefile.python
new file mode 100644
index 00000000..b954744e
--- /dev/null
+++ b/pkg/rpm/Makefile.python
@@ -0,0 +1,49 @@
+MODULES+= python
+
+MODULE_SUMMARY_python= Python module for NGINX Unit
+
+MODULE_VERSION_python= $(VERSION)
+MODULE_RELEASE_python= 1
+
+MODULE_CONFARGS_python= python
+MODULE_MAKEARGS_python= python
+MODULE_INSTARGS_python= python-install
+
+MODULE_SOURCES_python= unit.example-python-app \
+ unit.example-python-config
+
+BUILD_DEPENDS+= python-devel
+
+define MODULE_PREINSTALL_python
+%{__mkdir} -p %{buildroot}%{_datadir}/doc/unit-python/examples/python-app
+%{__install} -m 644 -p %{SOURCE100} \
+ %{buildroot}%{_datadir}/doc/unit-python/examples/python-app/wsgi.py
+%{__install} -m 644 -p %{SOURCE101} \
+ %{buildroot}%{_datadir}/doc/unit-python/examples/unit.config
+endef
+export MODULE_PREINSTALL_python
+
+define MODULE_FILES_python
+%{_libdir}/unit/modules/*
+%{_libdir}/unit/debug-modules/*
+endef
+export MODULE_FILES_python
+
+define MODULE_POST_python
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_python) has been installed.
+
+To check the sample app, run these commands:
+
+ sudo service unit start
+ sudo service unit loadconfig /usr/share/doc/unit-python/examples/unit.config
+ curl http://localhost:8400/
+
+Online documentation is available at https://unit.nginx.org
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_python
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.example-go-app b/pkg/rpm/rpmbuild/SOURCES/unit.example-go-app
new file mode 100644
index 00000000..ef2568ec
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.example-go-app
@@ -0,0 +1,20 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "unit"
+)
+
+func handler(w http.ResponseWriter, r *http.Request) {
+ w.Header().Add("Content-Type", "text/plain");
+
+ fmt.Fprintf(w, "Method : %s\n", r.Method)
+ fmt.Fprintf(w, "URL : %s\n", r.URL.Path)
+ fmt.Fprintf(w, "Host : %s\n", r.Host)
+}
+
+func main() {
+ http.HandleFunc("/", handler)
+ unit.ListenAndServe("8000", nil)
+}
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.example-go-config b/pkg/rpm/rpmbuild/SOURCES/unit.example-go-config
new file mode 100644
index 00000000..d6a2a8a0
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.example-go-config
@@ -0,0 +1,15 @@
+{
+ "applications": {
+ "example_go": {
+ "type": "go",
+ "user": "nobody",
+ "executable": "/tmp/go-app"
+ }
+ },
+
+ "listeners": {
+ "*:8500": {
+ "application": "example_go"
+ }
+ }
+}
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.example-php-app b/pkg/rpm/rpmbuild/SOURCES/unit.example-php-app
new file mode 100644
index 00000000..147cebcd
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.example-php-app
@@ -0,0 +1 @@
+<?php phpinfo(); ?>
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.example-php-config b/pkg/rpm/rpmbuild/SOURCES/unit.example-php-config
new file mode 100644
index 00000000..026b8f20
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.example-php-config
@@ -0,0 +1,17 @@
+{
+ "applications": {
+ "example_php": {
+ "type": "php",
+ "user": "nobody",
+ "workers": 2,
+ "root": "/usr/share/doc/unit-php/examples/phpinfo-app",
+ "index": "index.php"
+ }
+ },
+
+ "listeners": {
+ "*:8300": {
+ "application": "example_php"
+ }
+ }
+}
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.example-python-app b/pkg/rpm/rpmbuild/SOURCES/unit.example-python-app
new file mode 100644
index 00000000..756de77e
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.example-python-app
@@ -0,0 +1,16 @@
+import os
+import datetime
+import sys
+
+def application(environ, start_response):
+ output = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
+ output += "\n\nPython: "
+ output += sys.version
+ output += "\n\nENV Variables:\n\n"
+ for param in os.environ.keys():
+ output += param
+ output += "\t"
+ output += os.environ[param]
+ output += "\n"
+ start_response('200 OK', [('Content-type', 'text/plain')])
+ return output.encode('utf8')
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.example-python-config b/pkg/rpm/rpmbuild/SOURCES/unit.example-python-config
new file mode 100644
index 00000000..e0d8c439
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.example-python-config
@@ -0,0 +1,17 @@
+{
+ "applications": {
+ "example_python": {
+ "type": "python",
+ "user": "nobody",
+ "workers": 2,
+ "path": "/usr/share/doc/unit-python/examples/python-app",
+ "module": "wsgi"
+ }
+ },
+
+ "listeners": {
+ "*:8400": {
+ "application": "example_python"
+ }
+ }
+}
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.example.config b/pkg/rpm/rpmbuild/SOURCES/unit.example.config
new file mode 100644
index 00000000..99918022
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.example.config
@@ -0,0 +1,39 @@
+{
+ "applications": {
+ "example_php": {
+ "type": "php",
+ "user": "nobody",
+ "workers": 2,
+ "root": "/usr/share/doc/unit-php/examples/phpinfo-app",
+ "index": "index.php"
+ },
+
+ "example_python": {
+ "type": "python",
+ "user": "nobody",
+ "workers": 2,
+ "path": "/usr/share/doc/unit-python/examples/python-app",
+ "module": "wsgi"
+ },
+
+ "example_go": {
+ "type": "go",
+ "user": "nobody",
+ "executable": "/tmp/go-app"
+ }
+ },
+
+ "listeners": {
+ "*:8300": {
+ "application": "example_php"
+ },
+
+ "*:8400": {
+ "application": "example_python"
+ },
+
+ "*:8500": {
+ "application": "example_go"
+ }
+ }
+}
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.init b/pkg/rpm/rpmbuild/SOURCES/unit.init
new file mode 100644
index 00000000..b871ef32
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.init
@@ -0,0 +1,116 @@
+#!/bin/sh
+#
+# unitd NGINX Unit
+#
+# chkconfig: - 86 14
+# description: NGINX Unit
+
+### BEGIN INIT INFO
+# Provides: unitd
+# Required-Start: $local_fs $network $named $syslog
+# Required-Stop: $local_fs $network $named $syslog
+# Default-Start:
+# Default-Stop: 0 1 2 3 4 5 6
+# Short-Description: NGINX Unit
+# Description: NGINX Unit
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+exec="/usr/sbin/unitd"
+prog="unitd"
+config="/etc/unit/unit.conf"
+
+if [ -n "$2" ]; then
+ config=$2
+fi
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+lockfile=/var/lock/subsys/$prog
+
+start() {
+ [ -x $exec ] || exit 5
+ echo -n $"Starting $prog: "
+ daemon $exec $UNITD_OPTIONS
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && touch $lockfile
+ return $retval
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ killproc $prog
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && rm -f $lockfile
+ return $retval
+}
+
+restart() {
+ stop
+ start
+}
+
+rh_status() {
+ status $prog
+}
+
+rh_status_q() {
+ rh_status &>/dev/null
+}
+
+
+case "$1" in
+ start)
+ rh_status_q && exit 0
+ $1
+ ;;
+ stop)
+ rh_status_q || exit 0
+ $1
+ ;;
+ restart)
+ $1
+ ;;
+ reload|force-reload)
+ echo "Not implemented." >&2
+ exit 1
+ ;;
+ status)
+ rh_status
+ ;;
+ condrestart|try-restart)
+ rh_status_q || exit 0
+ restart
+ ;;
+ saveconfig)
+ curl -sS --unix-socket /var/run/control.unit.sock localhost >${config}.new
+ if [ $? -ne 0 ]; then
+ echo "Could not retreive configuration" >&2
+ rm -f ${config}.new
+ exit 1
+ fi
+ mv ${config}.new ${config}
+ echo "The following configuration has been saved to ${config}:"
+ cat ${config}
+ ;;
+ loadconfig)
+ if [ ! -e ${config} ]; then
+ echo "Could not find ${config} for loading" >&2
+ exit 1
+ fi
+ echo "Loading configuration from ${config}..."
+ curl -sS -X PUT --data-binary @${config} --unix-socket /var/run/control.unit.sock localhost
+ if [ $? -ne 0 ]; then
+ echo "Loading failed!" >&2
+ exit 1
+ fi
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|saveconfig|loadconfig}"
+ exit 2
+esac
+exit $?
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.loadconfig.sh b/pkg/rpm/rpmbuild/SOURCES/unit.loadconfig.sh
new file mode 100644
index 00000000..3dd90740
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.loadconfig.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Legacy action script for "service unit loadconfig"
+
+CONFIG=/etc/unit/config
+
+if [ -n "$1" ] ; then
+ CONFIG=$1
+fi
+
+if [ ! -e ${CONFIG} ]; then
+ echo "Could not find ${CONFIG} for loading" >&2
+ exit 1
+fi
+
+echo "Loading configuration from ${CONFIG}..."
+
+curl -sS -X PUT --data-binary @${CONFIG} --unix-socket /var/run/control.unit.sock localhost
+
+if [ $? -ne 0 ]; then
+ echo "Loading failed!" >&2
+ exit 1
+fi
+
+exit 0
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.saveconfig.sh b/pkg/rpm/rpmbuild/SOURCES/unit.saveconfig.sh
new file mode 100644
index 00000000..dbed9a81
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.saveconfig.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# Legacy action script for "service unit saveconfig"
+
+CONFIG=/etc/unit/config
+
+if [ -n "$1" ] ; then
+ CONFIG=$1
+fi
+
+curl -sS --unix-socket /var/run/control.unit.sock localhost >${CONFIG}.new
+
+if [ $? -ne 0 ]; then
+ echo "Could not retreive configuration" >&2
+ rm -f ${CONFIG}.new
+ exit 1
+fi
+
+mv ${CONFIG}.new ${CONFIG}
+
+echo "The following configuration has been saved to ${CONFIG}:"
+cat ${CONFIG}
+
+exit 0
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.service b/pkg/rpm/rpmbuild/SOURCES/unit.service
new file mode 100644
index 00000000..93663c58
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=NGINX Unit
+Wants=network-online.target
+After=network-online.target
+
+[Service]
+Type=forking
+PIDFile=/run/unit.pid
+EnvironmentFile=-/etc/sysconfig/unitd
+ExecStart=/usr/sbin/unitd $UNITD_OPTIONS
+ExecReload=
+
+[Install]
+WantedBy=multi-user.target
diff --git a/pkg/rpm/rpmbuild/SOURCES/unit.sysconf b/pkg/rpm/rpmbuild/SOURCES/unit.sysconf
new file mode 100644
index 00000000..436b164a
--- /dev/null
+++ b/pkg/rpm/rpmbuild/SOURCES/unit.sysconf
@@ -0,0 +1 @@
+UNITD_OPTIONS="--log /var/log/unitd.log --pid /run/unitd.pid"
diff --git a/pkg/rpm/unit.module.spec.in b/pkg/rpm/unit.module.spec.in
new file mode 100644
index 00000000..cb4e2e6c
--- /dev/null
+++ b/pkg/rpm/unit.module.spec.in
@@ -0,0 +1,90 @@
+# distribution specific definitions
+%define bdir %{_builddir}/%{name}-%{version}
+
+%%MODULE_DEFINITIONS%%
+
+%if 0%{?rhel} == 7
+%define dist .el7
+%endif
+
+%define unit_version %%UNIT_VERSION%%
+%define unit_release %%UNIT_RELEASE%%%{?dist}.ngx
+
+%define CONFIGURE_ARGS $(echo "%%CONFIGURE_ARGS%%")
+
+Name: %%NAME%%
+Summary: %%SUMMARY%%
+Version: %%VERSION%%
+Release: %%RELEASE%%%{?dist}.ngx
+License: ASL 2.0
+Vendor: Nginx Software, Inc.
+URL: https://unit.nginx.org/
+Packager: Nginx Software, Inc. <https://www.nginx.com>
+Group: System Environment/Daemons
+
+Source0: unit-%{version}.tar.gz
+%%MODULE_SOURCES%%
+
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+Requires: unit == %%UNIT_VERSION%%-%%UNIT_RELEASE%%%{?dist}.ngx
+
+%description
+NGINX Unit is a runtime and delivery environment for modern distributed
+applications. It runs the application code in multiple languages
+(PHP, Python, Go, etc.), and tightly couples it with traffic delivery
+in and out of the application. Take this application server and proxy
+directly in the cloud / container environments and fully control your app
+dynamically via an API.
+This package contains %%SUMMARY%%.
+
+%if 0%{?suse_version}
+%debug_package
+%endif
+
+%prep
+%setup -qcTn %{name}-%{unit_version}
+tar --strip-components=1 -zxf %{SOURCE0}
+
+%build
+./configure \
+ %{CONFIGURE_ARGS} \
+ --modules=%{_libdir}/unit/debug-modules \
+ --debug
+./configure %%MODULE_CONFARGS%%
+make %%MODULE_MAKEARGS%%
+%{__mv} build build-debug
+./configure \
+ %{CONFIGURE_ARGS} \
+ --modules=%{_libdir}/unit/modules
+./configure %%MODULE_CONFARGS%%
+make %%MODULE_MAKEARGS%%
+
+%install
+%{__rm} -rf %{buildroot}
+%{__mkdir} -p %{buildroot}%{_datadir}/doc/%%NAME%%
+%{__install} -m 644 -p NOTICE \
+ %{buildroot}%{_datadir}/doc/%%NAME%%/COPYRIGHT
+%%MODULE_PREINSTALL%%
+DESTDIR=%{buildroot} make %%MODULE_INSTARGS%%
+%{__rm} -rf build
+%{__mv} build-debug build
+DESTDIR=%{buildroot} make %%MODULE_INSTARGS%%
+
+%check
+
+%clean
+%{__rm} -rf %{buildroot}
+
+%post
+if [ $1 -eq 1 ]; then
+%%MODULE_POST%%
+fi
+
+%files
+%defattr(-,root,root,-)
+%dir %{_datadir}/doc/%%NAME%%
+%{_datadir}/doc/%%NAME%%/*
+%%MODULE_FILES%%
+
+%changelog
diff --git a/pkg/rpm/unit.spec.in b/pkg/rpm/unit.spec.in
new file mode 100644
index 00000000..94439be0
--- /dev/null
+++ b/pkg/rpm/unit.spec.in
@@ -0,0 +1,182 @@
+# distribution specific definitions
+%define use_systemd (0%{?rhel} && 0%{?rhel} >= 7) || (0%{?suse_version} == 1315)
+%define bdir %{_builddir}/%{name}-%{version}
+%define dotests 0
+
+%if ( 0%{?rhel} == 5 || 0%{?rhel} == 6 )
+Requires: initscripts >= 8.36
+%endif
+
+%if 0%{?rhel} == 7
+Requires: systemd
+BuildRequires: systemd-units
+%define dist .el7
+%endif
+
+%if 0%{?suse_version} == 1315
+BuildRequires: systemd
+Requires: systemd
+%endif
+
+%define CONFIGURE_ARGS $(echo "%%CONFIGURE_ARGS%%")
+
+Provides: nginx-unit
+
+Name: unit
+Summary: NGINX Unit
+Version: %%VERSION%%
+Release: %%RELEASE%%%{?dist}.ngx
+License: ASL 2.0
+Vendor: Nginx Software, Inc.
+URL: https://unit.nginx.org/
+Packager: Nginx Software, Inc. <https://www.nginx.com>
+Group: System Environment/Daemons
+
+Source0: unit-%{version}.tar.gz
+Source1: unit.service
+Source2: unit.init
+Source3: unit.sysconf
+Source4: unit.saveconfig.sh
+Source5: unit.loadconfig.sh
+Source6: unit.example.config
+
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+%description
+NGINX Unit is a runtime and delivery environment for modern distributed
+applications. It runs the application code in multiple languages
+(PHP, Python, Go, etc.), and tightly couples it with traffic delivery
+in and out of the application. Take this application server and proxy
+directly in the cloud / container environments and fully control your app
+dynamically via an API.
+
+%if 0%{?suse_version}
+%debug_package
+%endif
+
+%prep
+%setup -q
+
+%build
+./configure \
+ %{CONFIGURE_ARGS} \
+ --modules=%{_libdir}/unit/debug-modules \
+ --debug
+%{__make} %{?_smp_mflags}
+%{__mv} build build-debug
+./configure \
+ %{CONFIGURE_ARGS} \
+ --modules=%{_libdir}/unit/modules
+%{__make} %{?_smp_mflags}
+
+%install
+%{__rm} -rf %{buildroot}
+DESTDIR=%{buildroot} make unitd-install
+%{__install} -m755 %{bdir}/build-debug/unitd \
+ %{buildroot}%{_sbindir}/unitd-debug
+%{__mkdir} -p %{buildroot}%{_libdir}/unit/modules
+%{__mkdir} -p %{buildroot}%{_libdir}/unit/debug-modules
+%{__mkdir} -p %{buildroot}%{_sharedstatedir}/unit
+%{__mkdir} -p %{buildroot}%{_sysconfdir}/sysconfig
+%{__install} -m 644 -p %{SOURCE3} \
+ %{buildroot}%{_sysconfdir}/sysconfig/unit
+%{__mkdir} -p %{buildroot}%{_sysconfdir}/unit
+%{__mkdir} -p %{buildroot}%{_datadir}/doc/unit/examples
+%{__install} -m 644 -p %{SOURCE6} \
+ %{buildroot}%{_datadir}/doc/unit/examples/example.config
+%{__install} -m 644 -p CHANGES \
+ %{buildroot}%{_datadir}/doc/unit/
+%{__install} -m 644 -p NOTICE \
+ %{buildroot}%{_datadir}/doc/unit/COPYRIGHT
+%{__install} -m 644 -p README \
+ %{buildroot}%{_datadir}/doc/unit/
+
+# init scripts
+%if %{use_systemd}
+%{__rm} -rf %{buildroot}%{_initrddir}/
+%{__install} -p -D -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/unit.service
+%{__mkdir} -p %{buildroot}%{_libexecdir}/initscripts/legacy-actions/unit
+%{__install} -m755 %SOURCE4 \
+ %{buildroot}%{_libexecdir}/initscripts/legacy-actions/unit/saveconfig
+%{__install} -m755 %SOURCE5 \
+ %{buildroot}%{_libexecdir}/initscripts/legacy-actions/unit/loadconfig
+%else
+%{__mkdir} -p %{buildroot}%{_initrddir}
+%{__install} -p -D -m 0755 %{SOURCE2} %{buildroot}%{_initrddir}/unit
+%endif
+
+QA_SKIP_BUILD_ROOT=1
+export QA_SKIP_BUILD_ROOT
+
+%check
+%if %{dotests}
+cd %{bdir} && make tests && ./build/tests
+%endif
+
+%clean
+%{__rm} -rf %{buildroot}
+
+%post
+if [ $1 -eq 1 ]; then
+%if %{use_systemd}
+ /usr/bin/systemctl preset unit.service >/dev/null 2>&1 ||:
+%else
+ /sbin/chkconfig --add unit
+%endif
+ cat <<BANNER
+----------------------------------------------------------------------
+
+Thank you for installing NGINX Unit!
+
+Additional modules are available in standalone packages.
+To see the available modules, run "yum list available unit-\*".
+
+Online documentation is available at https://unit.nginx.org/
+
+----------------------------------------------------------------------
+BANNER
+fi
+
+%preun
+if [ $1 -eq 0 ]; then
+%if %{use_systemd}
+ /usr/bin/systemctl --no-reload disable unit.service >/dev/null 2>&1 ||:
+ /usr/bin/systemctl stop unit.service >/dev/null 2>&1 ||:
+%else
+ /sbin/service unit stop >/dev/null 2>&1
+ /sbin/chkconfig --del unit
+%endif
+fi
+
+%postun
+%if %{use_systemd}
+/usr/bin/systemctl daemon-reload >/dev/null 2>&1 ||:
+%endif
+if [ $1 -ge 1 ]; then
+%if %{use_systemd}
+ /usr/bin/systemctl try-restart unit.service >/dev/null 2>&1 ||:
+%else
+ /sbin/service unit condrestart >/dev/null 2>&1 ||:
+%endif
+fi
+
+%files
+%defattr(-,root,root,-)
+%attr(0755,root,root) %{_sbindir}/unitd
+%attr(0755,root,root) %{_sbindir}/unitd-debug
+%config(noreplace) %{_sysconfdir}/sysconfig/unit
+%dir %{_sysconfdir}/unit
+%if %{use_systemd}
+%{_unitdir}/unit.service
+%dir %{_libexecdir}/initscripts/legacy-actions/unit
+%{_libexecdir}/initscripts/legacy-actions/unit/*
+%else
+%{_initrddir}/unit
+%endif
+%dir %{_datadir}/doc/unit
+%{_datadir}/doc/unit/*
+%dir %{_libdir}/unit/modules
+%dir %{_libdir}/unit/debug-modules
+%dir %{_sharedstatedir}/unit
+
+%changelog