aboutsummaryrefslogtreecommitdiffstats
path: root/community
diff options
context:
space:
mode:
Diffstat (limited to 'community')
-rw-r--r--community/unit/APKBUILD90
-rw-r--r--community/unit/unit.confd22
-rw-r--r--community/unit/unit.initd88
-rw-r--r--community/unit/unit.logrotate7
-rw-r--r--community/unit/unit.pre-install6
5 files changed, 213 insertions, 0 deletions
diff --git a/community/unit/APKBUILD b/community/unit/APKBUILD
new file mode 100644
index 0000000000..05c7de4cda
--- /dev/null
+++ b/community/unit/APKBUILD
@@ -0,0 +1,90 @@
+# Contributor: André Klitzing <aklitzing@gmail.com>
+# Contributor: Jakub Jirutka <jakub@jirutka.cz>
+# Maintainer: André Klitzing <aklitzing@gmail.com>
+pkgname=unit
+pkgver=1.1
+pkgrel=0
+pkgdesc="NGINX Unit is a dynamic web application server"
+url="https://unit.nginx.org/"
+# armhf, x86: tests fail (https://github.com/nginx/unit/issues/118)
+arch="all !armhf !x86"
+license="Apache-2.0"
+_phpver=7
+makedepends="perl-dev php$_phpver-dev php$_phpver-embed python3-dev ruby-dev"
+install="$pkgname.pre-install"
+subpackages="$pkgname-openrc"
+source="https://unit.nginx.org/download/$pkgname-$pkgver.tar.gz
+ $pkgname.initd
+ $pkgname.confd
+ $pkgname.logrotate"
+builddir="$srcdir/$pkgname-$pkgver"
+
+for _mod in perl php$_phpver python3 ruby; do
+ subpackages="$subpackages $pkgname-$_mod:_module"
+done
+
+_modules_dir="/usr/lib/unit/modules"
+
+build() {
+ cd "$builddir"
+
+ # Needed for building perl module.
+ export CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
+
+ ./configure \
+ --prefix="/usr" \
+ --state="/var/lib/unit" \
+ --control="unix:/run/control.unit.sock" \
+ --pid="/run/unit.pid" \
+ --log="/var/log/unit.log" \
+ --modules="$_modules_dir" \
+ --user=unit \
+ --group=unit \
+ --tests
+ ./configure perl
+ ./configure php --module=php$_phpver --config=php-config$_phpver
+ ./configure python --config=python3-config
+ ./configure ruby
+
+ make
+ make tests
+}
+
+check() {
+ cd "$builddir"
+
+ ./build/tests
+
+ # FIXME: Some tests are broken.
+ #make install DESTDIR=".dest"
+ #./test/run.py
+}
+
+package() {
+ cd "$builddir"
+
+ make unitd-install DESTDIR="$pkgdir"
+
+ install -D -m 755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
+ install -D -m 644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
+ install -D -m 644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname
+}
+
+openrc() {
+ default_openrc
+ depends="curl"
+}
+
+_module() {
+ local modname=${subpkgname#$pkgname-}
+ pkgdesc="$modname module for NGINX Unit"
+ depends="$pkgname=$pkgver-r$pkgrel"
+
+ cd "$builddir"
+ make $modname-install DESTDIR="$subpkgdir"
+}
+
+sha512sums="89460e96d775df7f0c9d66011b59ca45ebe99e1e9e194f1800824ee1a3ae9c3f0207c9c749d34c250560ded6f1c3ad5b66fadcb3ffb2c62c5a6f5115944cea1f unit-1.1.tar.gz
+a835b83284d7bd4afb445dd93c84e2c6dd5906f137784ff3189edc82c3f14f07c5de00681125924138e3ac420cc849cc93e52cabbd6b550ded09d055d30e091c unit.initd
+f85112726dfcace2b6d94b10669615fef517f5aa10ac858890dd9f5c868a6e2569500f7411f758fcb24c98c9630760d36a74bd33ea510ab0f8ca8cd6cb1fb1e8 unit.confd
+723e465162dfdb31881680200221542add414e54ef4f4f1fc57e91b7b57777dfb21c2eee4727ecbba0c1943bb77a2597cc0225b16e334c38258c296d15b1df74 unit.logrotate"
diff --git a/community/unit/unit.confd b/community/unit/unit.confd
new file mode 100644
index 0000000000..bf3bf15856
--- /dev/null
+++ b/community/unit/unit.confd
@@ -0,0 +1,22 @@
+# Configuration for /etc/init.d/unit
+
+# Address of the control API socket.
+# If you want to use saveconfig and loadconfig (see below),
+# it must be a unix socket.
+#control_socket="unix:/run/unit.control.sock"
+
+# Path of the log file.
+#logfile="/var/log/unit.log"
+
+# Path of the state directory.
+#statedir="/var/lib/unit"
+
+# Path where the init script will save Unit's configuration when you run
+# `rc-service unit saveconfig` or load the configuration on loadconfig.
+#config_file="/etc/unit/config.json"
+
+# Load configuration from $config_file on start (if exists)?
+#config_load_on_start="no"
+
+# Save configuration to $config_file on stop?
+#config_save_on_stop="no"
diff --git a/community/unit/unit.initd b/community/unit/unit.initd
new file mode 100644
index 0000000000..d3db4ffd64
--- /dev/null
+++ b/community/unit/unit.initd
@@ -0,0 +1,88 @@
+#!/sbin/openrc-run
+
+extra_started_commands="loadconfig saveconfig"
+
+description="NGINX Unit"
+description_loadconfig="Load saved configuration"
+description_saveconfig="Save configuration to file"
+
+: ${control_socket:="unix:/run/control.unit.sock"}
+: ${logfile:="/var/log/unit.log"}
+: ${statedir:="/var/lib/unit"}
+: ${config_file:="/etc/unit/unit.conf"}
+: ${config_load_on_start:="no"}
+: ${config_save_on_stop:="no"}
+
+command="/usr/sbin/unitd"
+command_args="
+ --no-daemon
+ --log $logfile
+ --control $control_socket
+ $command_args"
+command_background="yes"
+pidfile="/run/$RC_SVCNAME.pid"
+
+depend() {
+ need net
+ use dns logger netmount
+}
+
+start_post() {
+ if yesno "$config_load_on_start" && [ -f "$config_file" ]; then
+ check_control_socket || return 1
+ ewaitfile 5 "${control_socket#unix:}" || return 1
+ loadconfig || return 1
+ fi
+}
+
+stop_pre() {
+ if yesno "$config_save_on_stop"; then
+ saveconfig
+ fi
+}
+
+saveconfig() {
+ ebegin "Saving configuration to $config_file"
+
+ check_control_socket || return 1
+ checkpath -d "${config_file%/*}" || return 1
+
+ local tmpfile=$(mktemp)
+ curl -sS --unix-socket "${control_socket#unix:}" localhost > "$tmpfile" || {
+ rm -f "$tmpfile"
+ eend 1 "Could not retrieve configuration"
+ return 1
+ }
+ cat "$tmpfile" > "$config_file" && rm -f "$tmpfile"
+ eend $?
+}
+
+loadconfig() {
+ ebegin "Loading configuration from $config_file"
+
+ check_control_socket || return 1
+
+ if ! [ -f "$config_file" ]; then
+ eend 1 "File $config_file does not exist"
+ return 1
+ fi
+
+ local resp=$(curl -sS -X PUT --data-binary "@$config_file" \
+ --write-out "\nHTTP_CODE:%{http_code}\n" \
+ --unix-socket "${control_socket#unix:}" localhost)
+
+ if [ "$(echo "$resp" | sed -n 's/^HTTP_CODE:\(\d\).*/\1/p')" -ne 2 ]; then
+ eend 1 "Unable to load configuration"
+ echo "$resp" | sed '/^HTTP_CODE:/d' >&2
+ return 1
+ fi
+ eend 0
+}
+
+check_control_socket() {
+ case "$control_socket" in
+ unix:*) return 0;;
+ esac
+ eerror "control_socket must be a unix socket when using saveconfig or loadconfig"
+ return 1
+}
diff --git a/community/unit/unit.logrotate b/community/unit/unit.logrotate
new file mode 100644
index 0000000000..d8e5aae504
--- /dev/null
+++ b/community/unit/unit.logrotate
@@ -0,0 +1,7 @@
+/var/log/unit.log {
+ compress
+ copytruncate
+ missingok
+ notifempty
+ sharedscripts
+}
diff --git a/community/unit/unit.pre-install b/community/unit/unit.pre-install
new file mode 100644
index 0000000000..9674c8d671
--- /dev/null
+++ b/community/unit/unit.pre-install
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+addgroup -S unit 2>/dev/null
+adduser -S -D -H -h /var/lib/unit -s /sbin/nologin -G unit -g "NGINX Unit" unit 2>/dev/null
+
+exit 0