diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2018-05-07 14:19:58 +0200 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2018-05-07 14:32:55 +0200 |
commit | f9bbb80e53c08d47ef2120b1e8e60e12f9c8f038 (patch) | |
tree | d2204c4d2d0a32e40d793fa8de71d5a5c120a130 /testing | |
parent | 831ba5bb1c17ad245490643e73b0ce57e0ac585d (diff) | |
download | aports-f9bbb80e53c08d47ef2120b1e8e60e12f9c8f038.tar.bz2 aports-f9bbb80e53c08d47ef2120b1e8e60e12f9c8f038.tar.xz |
testing/unit: add init script
Diffstat (limited to 'testing')
-rw-r--r-- | testing/unit/APKBUILD | 25 | ||||
-rw-r--r-- | testing/unit/unit.confd | 22 | ||||
-rw-r--r-- | testing/unit/unit.initd | 88 | ||||
-rw-r--r-- | testing/unit/unit.logrotate | 7 | ||||
-rw-r--r-- | testing/unit/unit.pre-install | 6 |
5 files changed, 145 insertions, 3 deletions
diff --git a/testing/unit/APKBUILD b/testing/unit/APKBUILD index f0af7583b2..ad49406cf8 100644 --- a/testing/unit/APKBUILD +++ b/testing/unit/APKBUILD @@ -10,8 +10,12 @@ arch="all" license="Apache-2.0" _phpver=7 makedepends="perl-dev php$_phpver-dev php$_phpver-embed python3-dev ruby-dev" -subpackages="" -source="https://unit.nginx.org/download/$pkgname-$pkgver.tar.gz" +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 @@ -33,6 +37,8 @@ build() { --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 @@ -55,7 +61,17 @@ check() { 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() { @@ -67,4 +83,7 @@ _module() { make $modname-install DESTDIR="$subpkgdir" } -sha512sums="89460e96d775df7f0c9d66011b59ca45ebe99e1e9e194f1800824ee1a3ae9c3f0207c9c749d34c250560ded6f1c3ad5b66fadcb3ffb2c62c5a6f5115944cea1f unit-1.1.tar.gz" +sha512sums="89460e96d775df7f0c9d66011b59ca45ebe99e1e9e194f1800824ee1a3ae9c3f0207c9c749d34c250560ded6f1c3ad5b66fadcb3ffb2c62c5a6f5115944cea1f unit-1.1.tar.gz +a835b83284d7bd4afb445dd93c84e2c6dd5906f137784ff3189edc82c3f14f07c5de00681125924138e3ac420cc849cc93e52cabbd6b550ded09d055d30e091c unit.initd +f85112726dfcace2b6d94b10669615fef517f5aa10ac858890dd9f5c868a6e2569500f7411f758fcb24c98c9630760d36a74bd33ea510ab0f8ca8cd6cb1fb1e8 unit.confd +723e465162dfdb31881680200221542add414e54ef4f4f1fc57e91b7b57777dfb21c2eee4727ecbba0c1943bb77a2597cc0225b16e334c38258c296d15b1df74 unit.logrotate" diff --git a/testing/unit/unit.confd b/testing/unit/unit.confd new file mode 100644 index 0000000000..bf3bf15856 --- /dev/null +++ b/testing/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/testing/unit/unit.initd b/testing/unit/unit.initd new file mode 100644 index 0000000000..d3db4ffd64 --- /dev/null +++ b/testing/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/testing/unit/unit.logrotate b/testing/unit/unit.logrotate new file mode 100644 index 0000000000..d8e5aae504 --- /dev/null +++ b/testing/unit/unit.logrotate @@ -0,0 +1,7 @@ +/var/log/unit.log { + compress + copytruncate + missingok + notifempty + sharedscripts +} diff --git a/testing/unit/unit.pre-install b/testing/unit/unit.pre-install new file mode 100644 index 0000000000..9674c8d671 --- /dev/null +++ b/testing/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 |