Introduced deb packages building tools.

This commit is contained in:
Andrei Belov
2017-10-19 18:23:32 +03:00
parent eabe25d98e
commit 156877f3c9
39 changed files with 1367 additions and 3 deletions

30
pkg/deb/debian/control Normal file
View File

@@ -0,0 +1,30 @@
Source: unit
Section: admin
Priority: extra
Maintainer: Andrei Belov <defan@nginx.com>
Build-Depends: debhelper (>= 9),
linux-libc-dev
Standards-Version: 3.9.5
Homepage: https://unit.nginx.org
Package: unit
Section: admin
Architecture: any
Depends: lsb-base,
${misc:Depends}, ${shlibs:Depends}
Description: NGINX Unit
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.
Package: unit-dbg
Section: debug
Architecture: any
Priority: extra
Depends: unit (= ${binary:Version}),
${misc:Depends}
Description: NGINX Unit (debug symbols)
This package contains the debugging symbols for NGINX Unit.

21
pkg/deb/debian/copyright Normal file
View File

@@ -0,0 +1,21 @@
NGINX Unit.
Copyright 2017 NGINX, Inc.
Copyright 2017 Igor Sysoev
Copyright 2017 Valentin V. Bartenev
Copyright 2017 Max Romanov
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
/usr/share/common-licenses/Apache-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

4
pkg/deb/debian/dirs Normal file
View File

@@ -0,0 +1,4 @@
usr/sbin
etc/unit
usr/lib/unit
var/lib/unit

105
pkg/deb/debian/rules.in Normal file
View File

@@ -0,0 +1,105 @@
#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
BUILDDIR_unit = $(CURDIR)/debian/build-unit
BUILDDIR_unit_debug = $(CURDIR)/debian/build-unit-debug
INSTALLDIR = $(CURDIR)/debian/unit
BASEDIR = $(CURDIR)
DOTESTS = 0
config.env.%:
dh_testdir
mkdir -p $(BUILDDIR_$*)
cp -Pa $(CURDIR)/auto $(BUILDDIR_$*)/
cp -Pa $(CURDIR)/configure $(BUILDDIR_$*)/
cp -Pa $(CURDIR)/src $(BUILDDIR_$*)/
cp -Pa $(CURDIR)/test $(BUILDDIR_$*)/
touch $@
configure.unit: config.env.unit
cd $(BUILDDIR_unit) && \
./configure \
%%CONFIGURE_ARGS%% \
--modules=/usr/lib/unit/modules
touch $@
configure.unit_debug: config.env.unit_debug
cd $(BUILDDIR_unit_debug) && \
./configure \
%%CONFIGURE_ARGS%% \
--modules=/usr/lib/unit/debug-modules \
--debug
touch $@
build-arch.%: configure.%
dh_testdir
$(MAKE) -C $(BUILDDIR_$*)
ifeq ($(DOTESTS), 1)
$(MAKE) -C $(BUILDDIR_$*) tests
endif
touch $@
do.tests: build
dh_testdir
ifeq ($(DOTESTS), 1)
cd $(BUILDDIR_unit) && ./build/tests
cd $(BUILDDIR_unit_debug) && ./build/tests
endif
touch $@
build-indep:
dh_testdir
touch $@
build-arch: build-arch.unit build-arch.unit_debug
dh_testdir
touch $@
build: build-arch build-indep
dh_testdir
touch $@
clean:
dh_testdir
dh_testroot
dh_clean
find $(CURDIR) -maxdepth 1 -size 0 -delete
install: build do.tests
dh_testdir
dh_testroot
dh_prep
dh_installdirs
dh_installinit
dh_installlogrotate
cd $(BUILDDIR_unit) && DESTDIR=$(INSTALLDIR) make install
install -m 755 $(BUILDDIR_unit_debug)/build/unitd $(INSTALLDIR)/usr/sbin/unitd-debug
mkdir -p $(INSTALLDIR)/usr/share/doc/unit/examples
install -m 644 debian/unit.example.config $(INSTALLDIR)/usr/share/doc/unit/examples/example.config
install -m 644 CHANGES $(INSTALLDIR)/usr/share/doc/unit/
install -m 644 README $(INSTALLDIR)/usr/share/doc/unit/
binary-indep: build install
dh_testdir
dh_testroot
dh_installdocs
dh_installchangelogs
dh_link
dh_strip --dbg-package=unit-dbg
dh_shlibdeps
dh_compress
dh_fixperms
dh_installdeb
dh_perl
dh_gencontrol
dh_md5sums
dh_builddeb
binary-arch: install
binary: binary-indep binary-arch
.PHONY: clean binary-indep binary-arch binary install build

View File

@@ -0,0 +1 @@
DAEMON_ARGS="--log /var/log/unit.log --pid /run/unit.pid"

View File

@@ -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)
}

View File

@@ -0,0 +1 @@
<?php phpinfo(); ?>

View File

@@ -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')

View File

@@ -0,0 +1,39 @@
{
"applications": {
"example_php": {
"type": "php",
"user": "nobody",
"workers": 2,
"root": "/usr/share/doc/unit/examples/php-app",
"index": "index.php"
},
"example_python": {
"type": "python",
"user": "nobody",
"workers": 2,
"path": "/usr/share/doc/unit/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"
}
}
}

104
pkg/deb/debian/unit.init Normal file
View File

@@ -0,0 +1,104 @@
#!/bin/sh
#
# unitd NGINX Unit
#
### BEGIN INIT INFO
# Provides: unitd
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: NGINX Unit
# Description: NGINX Unit
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/unitd
NAME=unitd
DESC=unitd
CONFIG=/etc/unit/config
[ -r /etc/default/${NAME} ] && . /etc/default/${NAME}
if [ -n "$2" ]; then
CONFIG=$2
fi
#includes lsb functions
. /lib/lsb/init-functions
test -f $DAEMON || exit 0
umask 022
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --start --quiet --pidfile /run/$NAME.pid \
--exec $DAEMON -- $DAEMON_ARGS; then
log_end_msg 0
else
log_end_msg 1
fi
;;
status)
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
if start-stop-daemon --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON; then
log_end_msg 0
else
log_end_msg 1
fi
;;
reload|force-reload)
echo "Not implemented." >&2
exit 1
;;
restart)
log_action_begin_msg "Restarting $DESC" "$NAME"
start-stop-daemon --stop --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON || true
sleep 1
if start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_ARGS; then
log_end_msg 0
else
log_end_msg 1
fi
;;
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: /etc/init.d/$NAME {start|status|stop|restart|reload|force-reload|saveconfig|loadconfig}" >&2
exit 1
;;
esac
exit 0

11
pkg/deb/debian/unit.postinst Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -e
if [ "$1" != "configure" ]; then
exit 0
fi
#DEBHELPER#
exit 0

View File

@@ -0,0 +1,34 @@
#!/bin/sh
set -e
case "$1" in
install)
cat <<BANNER
----------------------------------------------------------------------
Thank you for installing NGINX Unit!
Additional modules are available in standalone packages.
To see the available modules, run: apt search --names-only '^unit-'
Online documentation is available at https://unit.nginx.org/
----------------------------------------------------------------------
BANNER
;;
upgrade)
;;
abort-upgrade)
;;
*)
echo "preinst called with unknown argument \`$1'" >&2
exit 0
;;
esac
#DEBHELPER#
exit 0

View File

@@ -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/default/unit
ExecStart=/usr/sbin/unitd $DAEMON_ARGS
ExecReload=
[Install]
WantedBy=multi-user.target