From 5c4392984fe203b2551b75de7ab0e7fe411001fc Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Wed, 20 Oct 2010 20:22:16 +0200 Subject: [PATCH] runit: introduced runit-run and runit-log-run helping wrappers --- .../overlay.d/runit/D%libdir_runit-run.in.txt | 55 +++++++++++++++++++ .../runit/D%sbindir_runit-log-run.sh | 42 ++++++++++++++ .../overlay.d/runit/D%sbindir_runit-run.sh | 34 ++++++++++++ base/runit/runit.conf | 2 + 4 files changed, 133 insertions(+) create mode 100644 base/runit/overlay.d/runit/D%libdir_runit-run.in.txt create mode 100644 base/runit/overlay.d/runit/D%sbindir_runit-log-run.sh create mode 100644 base/runit/overlay.d/runit/D%sbindir_runit-run.sh diff --git a/base/runit/overlay.d/runit/D%libdir_runit-run.in.txt b/base/runit/overlay.d/runit/D%libdir_runit-run.in.txt new file mode 100644 index 000000000..c907403d1 --- /dev/null +++ b/base/runit/overlay.d/runit/D%libdir_runit-run.in.txt @@ -0,0 +1,55 @@ +# vim: set ft=sh: +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: package/.../runit/overlay.d/runit/D%libdir_runit-run.in.txt +# Copyright (C) 2010 The OpenSDE Project +# +# More information can be found in the files COPYING and README. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. A copy of the +# GNU General Public License can be found in the file COPYING. +# --- SDE-COPYRIGHT-NOTE-END --- + +usage() { +cat <&2 +usage: $0 + ln -s $0 ; +EOT +exit 1 +} + +progname() { + case "$1" in + /*) echo "$1" ;; + */*) echo "$(cd "${1%/*}"; pwd)/${1##*/}" ;; + *) if [ "$PWD" = / ]; then + echo "/$1" + else + echo "$PWD/$1" + fi ;; + esac +} + +case "$0" in +D_sbindir/${TEMPLATE:-runit-run}) + # Sha-Bang'ed + [ $# -gt 0 ] || usage + + if [ -s "$1" ] && ${SHELL:-sh} -n "$1"; then + PROGNAME="$(progname "$1")"; shift + SCRIPT=yes + else + echo "$PROGNAME: invalid script" >&2 + exit 1 + fi + ;; +*) + # symlinked + PROGNAME="$(progname "$0")" + SCRIPT= +esac + +cd "${PROGNAME%/*}" diff --git a/base/runit/overlay.d/runit/D%sbindir_runit-log-run.sh b/base/runit/overlay.d/runit/D%sbindir_runit-log-run.sh new file mode 100644 index 000000000..d7666bb7b --- /dev/null +++ b/base/runit/overlay.d/runit/D%sbindir_runit-log-run.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: package/.../runit/overlay.d/runit/D%sbindir_runit-log-run.sh +# Copyright (C) 2010 The OpenSDE Project +# +# More information can be found in the files COPYING and README. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. A copy of the +# GNU General Public License can be found in the file COPYING. +# --- SDE-COPYRIGHT-NOTE-END --- + +TEMPLATE=log-run +. D_libdir/runit-run.in + +set -e + +# Variables to override +# +SVID="$(pwd | sed -ne 's|.*/\([^/]\+\)/log$|\1|p')" +LOGUSER=log +LOGDIR="${SVID:+/var/log/$SVID}" + +SVLOGD_OPT=-t + +[ -z "$SCRIPT" ] || . "$PROGNAME" + +# Detect SVID if needed +[ -n "$SVID" ] || die "$PWD: invalid log/run dir" + +# Detect LOGDIR if needed +[ -n "$LOGDIR" ] || LOGDIR="/var/log/$SVID" +[ -d "$LOGDIR/" ] || mkdir -p "$LOGDIR" +chown "${LOGUSER:-log}" "$LOGDIR" + +# ./main -> $LOGDIR +[ -d "main/" ] || ln -s "$LOGDIR" "main" + +exec setuidgid "${LOGUSER:-log}" svlogd ${SVLOGD_OPT} main/ diff --git a/base/runit/overlay.d/runit/D%sbindir_runit-run.sh b/base/runit/overlay.d/runit/D%sbindir_runit-run.sh new file mode 100644 index 000000000..6cefea3e2 --- /dev/null +++ b/base/runit/overlay.d/runit/D%sbindir_runit-run.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: package/.../runit/overlay.d/runit/D%sbindir_runit-run.sh +# Copyright (C) 2010 The OpenSDE Project +# +# More information can be found in the files COPYING and README. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. A copy of the +# GNU General Public License can be found in the file COPYING. +# --- SDE-COPYRIGHT-NOTE-END --- +# +# to be used as symlink to /etc/runit/runit-run or #!/etc/runit/runit-run + +exec 2>&1 + +. D_libdir/runit-run.in + +set -e + +SVID="${PWD##*/}" +RUN= + +[ -z "$SCRIPT" ] || . "$PROGNAME" + +if [ -n "$RUN" ]; then + exec "$RUN" +else + echo "$PROGNAME: no daemon to RUN defined" >&2 + exit 1 +fi diff --git a/base/runit/runit.conf b/base/runit/runit.conf index 3cbba73fd..201cfac70 100644 --- a/base/runit/runit.conf +++ b/base/runit/runit.conf @@ -97,6 +97,8 @@ EOT fi + overlay_apply "$confdir/overlay.d/runit" + ln -sfv forced_reboot $pkg_djb_commanddir/forced_poweroff # Emulate daemontools if not present using chpst