initial commit
This commit is contained in:
10
sh/.gitignore
vendored
Normal file
10
sh/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
functions.sh
|
||||
gendepends.sh
|
||||
rc-functions.sh
|
||||
openrc-run.sh
|
||||
cgroup-release-agent.sh
|
||||
init.sh
|
||||
init-early.sh
|
||||
rc-cgroup.sh
|
||||
migrate-to-run.sh
|
||||
binfmt.sh
|
||||
35
sh/Makefile
Normal file
35
sh/Makefile
Normal file
@@ -0,0 +1,35 @@
|
||||
DIR= ${LIBEXECDIR}/sh
|
||||
SRCS= init.sh.in functions.sh.in gendepends.sh.in \
|
||||
openrc-run.sh.in rc-functions.sh.in ${SRCS-${OS}}
|
||||
INC= rc-mount.sh functions.sh rc-functions.sh runit.sh s6.sh \
|
||||
start-stop-daemon.sh supervise-daemon.sh
|
||||
BIN= gendepends.sh init.sh openrc-run.sh ${BIN-${OS}}
|
||||
|
||||
INSTALLAFTER= _installafter
|
||||
|
||||
MK= ../mk
|
||||
include ${MK}/os.mk
|
||||
|
||||
SRCS-FreeBSD=
|
||||
BIN-FreeBSD=
|
||||
|
||||
SRCS-Linux= binfmt.sh.in cgroup-release-agent.sh.in init-early.sh.in \
|
||||
migrate-to-run.sh.in rc-cgroup.sh.in
|
||||
BIN-Linux= binfmt.sh cgroup-release-agent.sh init-early.sh migrate-to-run.sh \
|
||||
rc-cgroup.sh
|
||||
|
||||
SRCS-NetBSD=
|
||||
BIN-NetBSD=
|
||||
|
||||
include ${MK}/scripts.mk
|
||||
|
||||
%.sh: %.sh${SFX}
|
||||
${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
|
||||
|
||||
_installafter:
|
||||
${INSTALL} -d ${DESTDIR}/${INITDIR}
|
||||
@# Put functions.sh into init for backwards compat
|
||||
ln -snf ${LIBEXECDIR}/sh/functions.sh ${DESTDIR}/${INITDIR} || exit $$?
|
||||
|
||||
check test::
|
||||
./runtests.sh
|
||||
90
sh/binfmt.sh.in
Normal file
90
sh/binfmt.sh.in
Normal file
@@ -0,0 +1,90 @@
|
||||
#!@SHELL@
|
||||
# This is a reimplementation of the systemd binfmt.d code to register
|
||||
# misc binary formats with the kernel.
|
||||
#
|
||||
# See the binfmt.d manpage as well:
|
||||
# http://0pointer.de/public/systemd-man/binfmt.d.html
|
||||
# This script should match the manpage as of 2015/03/31
|
||||
|
||||
# Copyright (c) 2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
apply_file() {
|
||||
[ $# -lt 1 ] && return 0
|
||||
FILE="$1"
|
||||
LINENUM=0
|
||||
|
||||
### FILE FORMAT ###
|
||||
# See https://www.kernel.org/doc/Documentation/binfmt_misc.txt
|
||||
while read -r line; do
|
||||
LINENUM=$(( LINENUM+1 ))
|
||||
case $line in
|
||||
\#*) continue ;;
|
||||
\;*) continue ;;
|
||||
esac
|
||||
|
||||
echo "${line}" > /proc/sys/fs/binfmt_misc/register
|
||||
rc=$?
|
||||
if [ $rc -ne 0 ]; then
|
||||
printf "binfmt: invalid entry on line %d of \`%s'\n" \
|
||||
"$LINENUM" "$FILE" >&2
|
||||
error=1
|
||||
fi
|
||||
done <$FILE
|
||||
return $rc
|
||||
}
|
||||
|
||||
[ -e /proc/sys/fs/binfmt_misc/register ] || exit 0
|
||||
error=0
|
||||
if [ $# -gt 0 ]; then
|
||||
while [ $# -gt 0 ]; do
|
||||
apply_file "$1"
|
||||
shift
|
||||
done
|
||||
else
|
||||
# The hardcoding of these paths is intentional; we are following the
|
||||
# systemd spec.
|
||||
binfmt_dirs='/usr/lib/binfmt.d/ /run/binfmt.d/ /etc/binfmt.d/'
|
||||
binfmt_basenames=''
|
||||
binfmt_d=''
|
||||
|
||||
# Build a list of sorted unique basenames
|
||||
# directories declared later in the binfmt_d list will override earlier
|
||||
# directories, on a per file basename basis.
|
||||
# `/run/binfmt.d/foo.conf' supersedes `/usr/lib/binfmt.d/foo.conf'.
|
||||
# `/run/binfmt.d/foo.conf' will always be read after `/etc/binfmt.d/bar.conf'
|
||||
for d in ${binfmt_dirs} ; do
|
||||
[ -d $d ] && for f in ${d}/*.conf ; do
|
||||
case "${f##*/}" in
|
||||
systemd.conf|systemd-*.conf) continue;;
|
||||
esac
|
||||
[ -e $f ] && binfmt_basenames="${binfmt_basenames}\n${f##*/}"
|
||||
done # for f in ${d}
|
||||
done # for d in ${binfmt_dirs}
|
||||
binfmt_basenames="$(printf "${binfmt_basenames}\n" | sort -u )"
|
||||
|
||||
for b in $binfmt_basenames ; do
|
||||
real_f=''
|
||||
for d in $binfmt_dirs ; do
|
||||
f=${d}/${b}
|
||||
[ -e "${f}" ] && real_f=$f
|
||||
done
|
||||
[ -e "${real_f}" ] && binfmt_d="${binfmt_d} ${real_f}"
|
||||
done
|
||||
|
||||
# loop through the gathered fragments, sorted globally by filename.
|
||||
# `/run/binfmt.d/foo.conf' will always be read after `/etc/binfmt.d/bar.conf'
|
||||
for FILE in $binfmt_d ; do
|
||||
apply_file "$FILE"
|
||||
done
|
||||
fi
|
||||
|
||||
exit $error
|
||||
|
||||
# vim: set ts=2 sw=2 sts=2 noet ft=sh:
|
||||
19
sh/cgroup-release-agent.sh.in
Normal file
19
sh/cgroup-release-agent.sh.in
Normal file
@@ -0,0 +1,19 @@
|
||||
#!@SHELL@
|
||||
# This is run by the kernel after the last task is removed from a
|
||||
# control group in the openrc hierarchy.
|
||||
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
cgroup=/sys/fs/cgroup/openrc
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
||||
if [ -d ${cgroup}/"$1" ]; then
|
||||
rmdir ${cgroup}/"$1"
|
||||
fi
|
||||
124
sh/functions.sh.in
Normal file
124
sh/functions.sh.in
Normal file
@@ -0,0 +1,124 @@
|
||||
# Allow any sh script to work with einfo functions and friends
|
||||
# We also provide a few helpful functions for other programs to use
|
||||
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
RC_GOT_FUNCTIONS="yes"
|
||||
|
||||
eindent()
|
||||
{
|
||||
: $(( EINFO_INDENT = ${EINFO_INDENT:-0} + 2 ))
|
||||
[ "$EINFO_INDENT" -gt 40 ] && EINFO_INDENT=40
|
||||
export EINFO_INDENT
|
||||
}
|
||||
|
||||
eoutdent()
|
||||
{
|
||||
: $(( EINFO_INDENT = ${EINFO_INDENT:-0} - 2 ))
|
||||
[ "$EINFO_INDENT" -lt 0 ] && EINFO_INDENT=0
|
||||
return 0
|
||||
}
|
||||
|
||||
yesno()
|
||||
{
|
||||
[ -z "$1" ] && return 1
|
||||
|
||||
# Check the value directly so people can do:
|
||||
# yesno ${VAR}
|
||||
case "$1" in
|
||||
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
|
||||
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
|
||||
esac
|
||||
|
||||
# Check the value of the var so people can do:
|
||||
# yesno VAR
|
||||
# Note: this breaks when the var contains a double quote.
|
||||
local value=
|
||||
eval value=\"\$$1\"
|
||||
case "$value" in
|
||||
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
|
||||
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
|
||||
*) vewarn "\$$1 is not set properly"; return 1;;
|
||||
esac
|
||||
}
|
||||
|
||||
rc_runlevel()
|
||||
{
|
||||
rc-status --runlevel
|
||||
}
|
||||
|
||||
_sanitize_path()
|
||||
{
|
||||
local IFS=":" p= path=
|
||||
for p in $PATH; do
|
||||
case "$p" in
|
||||
@LIBEXECDIR@/bin|@LIBEXECDIR@/sbin);;
|
||||
@BINDIR@|@SBINDIR@|/usr/bin|/usr/sbin);;
|
||||
@PKG_PREFIX@/bin|@PKG_PREFIX@/sbin);;
|
||||
@LOCAL_PREFIX@/bin|@LOCAL_PREFIX@/sbin);;
|
||||
*) path="$path${path:+:}$p";;
|
||||
esac
|
||||
done
|
||||
echo "$path"
|
||||
}
|
||||
|
||||
# Allow our scripts to support zsh
|
||||
if [ -n "$ZSH_VERSION" ]; then
|
||||
emulate sh
|
||||
NULLCMD=:
|
||||
alias -g '${1+"$@"}'='"$@"'
|
||||
setopt NO_GLOB_SUBST
|
||||
fi
|
||||
|
||||
# Make a sane PATH
|
||||
_PREFIX=@PREFIX@
|
||||
_PKG_PREFIX=@PKG_PREFIX@
|
||||
_LOCAL_PREFIX=@LOCAL_PREFIX@
|
||||
_LOCAL_PREFIX=${_LOCAL_PREFIX:-/usr/local}
|
||||
_PATH=@LIBEXECDIR@/bin
|
||||
case "$_PREFIX" in
|
||||
"$_PKG_PREFIX"|"$_LOCAL_PREFIX") ;;
|
||||
*) _PATH="$_PATH:$_PREFIX/bin:$_PREFIX/sbin";;
|
||||
esac
|
||||
_PATH="$_PATH":/bin:/sbin:/usr/bin:/usr/sbin
|
||||
|
||||
if [ -n "$_PKG_PREFIX" ]; then
|
||||
_PATH="$_PATH:$_PKG_PREFIX/bin:$_PKG_PREFIX/sbin"
|
||||
fi
|
||||
if [ -n "$_LOCAL_PREFIX" ]; then
|
||||
_PATH="$_PATH:$_LOCAL_PREFIX/bin:$_LOCAL_PREFIX/sbin"
|
||||
fi
|
||||
_path="$(_sanitize_path "$PATH")"
|
||||
PATH="$_PATH${_path:+:}$_path" ; export PATH
|
||||
unset _sanitize_path _PREFIX _PKG_PREFIX _LOCAL_PREFIX _PATH _path
|
||||
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
--nocolor|--nocolour|-C)
|
||||
EINFO_COLOR="NO" ; export EINFO_COLOR
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then
|
||||
if [ -z "$GOOD" ]; then
|
||||
eval $(eval_ecolors)
|
||||
fi
|
||||
else
|
||||
# We need to have shell stub functions so our init scripts can remember
|
||||
# the last ecmd
|
||||
for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \
|
||||
vebegin veend veinfo vewarn vewend; do
|
||||
eval "$_e() { local _r; command $_e \"\$@\"; _r=\$?; \
|
||||
EINFO_LASTCMD=$_e; export EINFO_LASTCMD ; return \$_r; }"
|
||||
done
|
||||
unset _e
|
||||
fi
|
||||
129
sh/gendepends.sh.in
Normal file
129
sh/gendepends.sh.in
Normal file
@@ -0,0 +1,129 @@
|
||||
#!@SHELL@
|
||||
# Shell wrapper to list our dependencies
|
||||
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
. @LIBEXECDIR@/sh/functions.sh
|
||||
. @LIBEXECDIR@/sh/rc-functions.sh
|
||||
|
||||
config() {
|
||||
[ -n "$*" ] && echo "$RC_SVCNAME config $*" >&3
|
||||
}
|
||||
need() {
|
||||
[ -n "$*" ] && echo "$RC_SVCNAME ineed $*" >&3
|
||||
}
|
||||
use() {
|
||||
[ -n "$*" ] && echo "$RC_SVCNAME iuse $*" >&3
|
||||
}
|
||||
want() {
|
||||
[ -n "$*" ] && echo "$RC_SVCNAME iwant $*" >&3
|
||||
}
|
||||
before() {
|
||||
[ -n "$*" ] && echo "$RC_SVCNAME ibefore $*" >&3
|
||||
}
|
||||
after() {
|
||||
[ -n "$*" ] && echo "$RC_SVCNAME iafter $*" >&3
|
||||
}
|
||||
provide() {
|
||||
[ -n "$*" ] && echo "$RC_SVCNAME iprovide $*" >&3
|
||||
}
|
||||
keyword() {
|
||||
local c x
|
||||
set -- $*
|
||||
while [ -n "$*" ]; do
|
||||
case "$1" in
|
||||
-containers) x="$(_get_containers)" ;;
|
||||
!-containers) x="$(_get_containers_remove)" ;;
|
||||
*) x=$1 ;;
|
||||
esac
|
||||
c="${c}${x} "
|
||||
shift
|
||||
done
|
||||
[ -n "$c" ] && echo "$RC_SVCNAME keyword $c" >&3
|
||||
}
|
||||
depend() {
|
||||
:
|
||||
}
|
||||
|
||||
_done_dirs=
|
||||
for _dir in \
|
||||
@SYSCONFDIR@/init.d \
|
||||
@PKG_PREFIX@/etc/init.d \
|
||||
@LOCAL_PREFIX@/etc/init.d
|
||||
do
|
||||
[ -d "$_dir" ] || continue
|
||||
|
||||
# Don't do the same dir twice
|
||||
for _d in $_done_dirs; do
|
||||
[ "$_d" = "$_dir" ] && continue 2
|
||||
done
|
||||
unset _d
|
||||
_done_dirs="$_done_dirs $_dir"
|
||||
|
||||
cd "$_dir"
|
||||
for RC_SERVICE in *; do
|
||||
[ -x "$RC_SERVICE" -a -f "$RC_SERVICE" ] || continue
|
||||
|
||||
# Only generate dependencies for OpenRC scripts
|
||||
read one two three <"$RC_SERVICE"
|
||||
case "$one" in
|
||||
\#*/openrc-run) ;;
|
||||
\#*/runscript) ;;
|
||||
\#!)
|
||||
case "$two" in
|
||||
*/openrc-run) ;;
|
||||
*/runscript) ;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
unset one two three
|
||||
|
||||
RC_SVCNAME=${RC_SERVICE##*/} ; export RC_SVCNAME
|
||||
|
||||
# Compat
|
||||
SVCNAME=$RC_SVCNAME ; export SVCNAME
|
||||
|
||||
(
|
||||
# Save stdout in fd3, then remap it to stderr
|
||||
exec 3>&1 1>&2
|
||||
|
||||
_rc_c=${RC_SVCNAME%%.*}
|
||||
if [ -n "$_rc_c" -a "$_rc_c" != "$RC_SVCNAME" ]; then
|
||||
if [ -e "$_dir/../conf.d/$_rc_c" ]; then
|
||||
. "$_dir/../conf.d/$_rc_c"
|
||||
fi
|
||||
fi
|
||||
unset _rc_c
|
||||
|
||||
if [ -e "$_dir/../conf.d/$RC_SVCNAME" ]; then
|
||||
. "$_dir/../conf.d/$RC_SVCNAME"
|
||||
fi
|
||||
|
||||
[ -e @SYSCONFDIR@/rc.conf ] && . @SYSCONFDIR@/rc.conf
|
||||
if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
|
||||
for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
|
||||
[ -e "$_f" ] && . "$_f"
|
||||
done
|
||||
fi
|
||||
|
||||
if . "$_dir/$RC_SVCNAME"; then
|
||||
echo "$RC_SVCNAME" >&3
|
||||
_depend
|
||||
fi
|
||||
)
|
||||
done
|
||||
done
|
||||
57
sh/init-early.sh.Linux.in
Normal file
57
sh/init-early.sh.Linux.in
Normal file
@@ -0,0 +1,57 @@
|
||||
#!@SHELL@
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
: ${CONSOLE:=/dev/console}
|
||||
: ${RC_LIBEXECDIR:=@LIBEXECDIR@}
|
||||
|
||||
service_present()
|
||||
{
|
||||
local p="@SYSCONFDIR@/runlevels/$1/$2"
|
||||
# fail if the file doesn't exist
|
||||
[ ! -e "$p" ] && return 1
|
||||
# succeed if $RC_SYS empty, can't check further, assume script will run
|
||||
[ -z "$RC_SYS" ] && return 0
|
||||
# fail if file contains "-$RC_SYS", because then it won't run
|
||||
egrep -qi "^[[:space:]]*keyword[[:space:]].*-$RC_SYS\>" "$p" && return 1
|
||||
# succeed otherwise
|
||||
return 0
|
||||
}
|
||||
|
||||
if [ -e "$RC_LIBEXECDIR"/console/unicode ]; then
|
||||
termencoding="%G"
|
||||
kmode="-u"
|
||||
else
|
||||
termencoding="(K"
|
||||
kmode="-a"
|
||||
fi
|
||||
|
||||
# Try and set a font and as early as we can
|
||||
if service_present "$RC_DEFAULTLEVEL" consolefont ||
|
||||
service_present "$RC_BOOTLEVEL" consolefont; then
|
||||
printf "\033%s" "$termencoding" >"$CONSOLE" 2>/dev/null
|
||||
if [ -r "$RC_LIBEXECDIR"/console/font ] && \
|
||||
command -v setfont > /dev/null 2>&1; then
|
||||
[ -c "$CONSOLE" ] && cons="-C $CONSOLE"
|
||||
setfont $cons "$RC_LIBEXECDIR"/console/font 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try and set a keyboard map as early as possible
|
||||
if service_present "$RC_DEFAULTLEVEL" keymaps ||
|
||||
service_present "$RC_BOOTLEVEL" keymaps; then
|
||||
kbd_mode $kmode -C "$CONSOLE" 2>/dev/null
|
||||
if [ -r "$RC_LIBEXECDIR"/console/keymap ]; then
|
||||
loadkeys -q "$RC_LIBEXECDIR"/console/keymap 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# Ensure we exit 0 so the boot continues
|
||||
exit 0
|
||||
65
sh/init.sh.BSD.in
Normal file
65
sh/init.sh.BSD.in
Normal file
@@ -0,0 +1,65 @@
|
||||
#!@SHELL@
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
# This basically mounts $svcdir as a ramdisk, but preserving its content
|
||||
# which allows us to run depscan.sh
|
||||
# FreeBSD has a nice ramdisk - we don't set a size as we should always
|
||||
# be fairly small and we unmount them after the boot level is done anyway
|
||||
# NOTE we don't set a size for Linux either
|
||||
# FreeBSD-7 supports tmpfs now :)
|
||||
mount_svcdir()
|
||||
{
|
||||
if ! fstabinfo --mount "$RC_SVCDIR"; then
|
||||
if ! mount -t tmpfs -o rw,noexec,nosuid none \
|
||||
"$RC_SVCDIR" 2>/dev/null
|
||||
then
|
||||
mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0
|
||||
newfs -b 4096 -i 1024 -n /dev/md0
|
||||
mount -o rw,noexec,nosuid /dev/md0 "$RC_SVCDIR"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
. "$RC_LIBEXECDIR"/sh/functions.sh
|
||||
[ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf"
|
||||
if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
|
||||
for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
|
||||
[ -r "$_f" ] && . "$_f"
|
||||
done
|
||||
fi
|
||||
|
||||
# Disable devd until we need it
|
||||
if [ -z "$RC_SYS" -a "$RC_UNAME" = "FreeBSD" ]; then
|
||||
sysctl hw.bus.devctl_disable=1 >/dev/null
|
||||
fi
|
||||
|
||||
# mount $RC_SVCDIR as something we can write to if it's not rw
|
||||
# On vservers, / is always rw at this point, so we need to clean out
|
||||
# the old service state data
|
||||
: ${RC_LIBEXECDIR:=@LIBEXECDIR@}
|
||||
: ${RC_SVCDIR:=@LIBEXECDIR@/init.d}
|
||||
case "$(openrc --sys)" in
|
||||
OPENVZ|VSERVER) rm -rf "$RC_SVCDIR"/*;;
|
||||
*) if mountinfo --quiet "$RC_SVCDIR"; then
|
||||
rm -rf "$RC_SVCDIR"/*
|
||||
else
|
||||
mount_svcdir
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
retval=$?
|
||||
|
||||
if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
|
||||
cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
|
||||
fi
|
||||
|
||||
echo sysinit >"$RC_SVCDIR"/softlevel
|
||||
exit $retval
|
||||
42
sh/init.sh.GNU-kFreeBSD.in
Normal file
42
sh/init.sh.GNU-kFreeBSD.in
Normal file
@@ -0,0 +1,42 @@
|
||||
#!@SHELL@
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
if [ ! -d /run ]; then
|
||||
ebegin "Creating /run"
|
||||
mkdir -p /run
|
||||
eend $?
|
||||
fi
|
||||
|
||||
if [ -L $RC_SVCDIR ]; then
|
||||
rm $RC_SVCDIR
|
||||
fi
|
||||
|
||||
ebegin "Mounting /run"
|
||||
if ! fstabinfo --mount /run; then
|
||||
mount -t tmpfs -o mode=0755,noexec,nosuid,size=10% tmpfs /run
|
||||
if [ $? != 0 ]; then
|
||||
eerror "Unable to mount tmpfs on /run."
|
||||
eerror "Can't continue."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
eend
|
||||
|
||||
ebegin "Creating $RC_SVCDIR"
|
||||
mkdir -p $RC_SVCDIR
|
||||
eend $?
|
||||
|
||||
if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
|
||||
cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
|
||||
fi
|
||||
|
||||
echo sysinit >"$RC_SVCDIR"/softlevel
|
||||
exit 0
|
||||
44
sh/init.sh.GNU.in
Normal file
44
sh/init.sh.GNU.in
Normal file
@@ -0,0 +1,44 @@
|
||||
#!@SHELL@
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
if [ ! -d /run ]; then
|
||||
ebegin "Creating /run"
|
||||
mkdir -p /run
|
||||
eend $?
|
||||
fi
|
||||
|
||||
if [ -L $RC_SVCDIR ]; then
|
||||
rm $RC_SVCDIR
|
||||
fi
|
||||
|
||||
if ! mountinfo -q /run; then
|
||||
ebegin "Mounting /run"
|
||||
if ! fstabinfo --mount /run; then
|
||||
mount -t tmpfs -o mode=0755,no-suid,size=10% tmpfs /run
|
||||
if [ $? != 0 ]; then
|
||||
eerror "Unable to mount tmpfs on /run."
|
||||
eerror "Can't continue."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
eend
|
||||
fi
|
||||
|
||||
ebegin "Creating $RC_SVCDIR"
|
||||
mkdir -p $RC_SVCDIR
|
||||
eend $?
|
||||
|
||||
if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
|
||||
cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
|
||||
fi
|
||||
|
||||
echo sysinit >"$RC_SVCDIR"/softlevel
|
||||
exit 0
|
||||
105
sh/init.sh.Linux.in
Normal file
105
sh/init.sh.Linux.in
Normal file
@@ -0,0 +1,105 @@
|
||||
#!@SHELL@
|
||||
# Copyright (c) 1999-2007 Gentoo Foundation
|
||||
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
||||
# Released under the 2-clause BSD license.
|
||||
|
||||
. "$RC_LIBEXECDIR"/sh/functions.sh
|
||||
[ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf"
|
||||
if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
|
||||
for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
|
||||
[ -e "$_f" ] && . "$_f"
|
||||
done
|
||||
fi
|
||||
|
||||
# check for md5sum, and probably /usr too
|
||||
if command -v md5sum >/dev/null; then
|
||||
got_md5sum=true
|
||||
else
|
||||
eerror "md5sum is missing, which suggests /usr is not mounted"
|
||||
eerror "If you have separate /usr, it must be mounted by initramfs"
|
||||
eerror "If not, you should check coreutils is installed correctly"
|
||||
got_md5sum=false
|
||||
fi
|
||||
|
||||
# By default VServer already has /proc mounted, but OpenVZ does not!
|
||||
# However, some of our users have an old proc image in /proc
|
||||
# NFC how they managed that, but the end result means we have to test if
|
||||
# /proc actually works or not. We do this by comparing two reads of
|
||||
# /proc/self/environ for which we have set the variable VAR to two
|
||||
# different values. If the comparison comes back equal, we know that
|
||||
# /proc is not working.
|
||||
mountproc=true
|
||||
f=/proc/self/environ
|
||||
if [ -e $f ]; then
|
||||
if $got_md5sum && [ "$(VAR=a md5sum $f)" = "$(VAR=b md5sum $f)" ]; then
|
||||
eerror "You have cruft in /proc that should be deleted"
|
||||
else
|
||||
# If they don't have md5sum, this will fail in pretty ways if
|
||||
# /proc isn't really mounted. Oh well, their system is busted
|
||||
# anyway, and they get to keep the pieces.
|
||||
einfo "/proc is already mounted"
|
||||
mountproc=false
|
||||
fi
|
||||
fi
|
||||
unset f
|
||||
|
||||
if $mountproc; then
|
||||
ebegin "Mounting /proc"
|
||||
if ! fstabinfo --mount /proc; then
|
||||
mount -n -t proc -o noexec,nosuid,nodev proc /proc
|
||||
mount -n /proc -o remount,gid=26,hidepid=2
|
||||
fi
|
||||
eend $?
|
||||
fi
|
||||
|
||||
# /run is a new directory for storing volatile runtime data.
|
||||
# Read more about /run at https://lwn.net/Articles/436012
|
||||
sys="$(openrc --sys)"
|
||||
|
||||
if [ ! -d /run ]; then
|
||||
if [ "$sys" = VSERVER ]; then
|
||||
if [ -e /run ]; then
|
||||
rm -rf /run
|
||||
fi
|
||||
mkdir /run
|
||||
else
|
||||
eerror "The /run directory does not exist. Unable to continue."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$sys" = VSERVER ]; then
|
||||
rm -rf /run/*
|
||||
elif ! mountinfo -q /run; then
|
||||
ebegin "Mounting /run"
|
||||
rc=0
|
||||
if ! fstabinfo --mount /run; then
|
||||
mount -t tmpfs -o mode=0755,nodev,size=10% tmpfs /run
|
||||
rc=$?
|
||||
fi
|
||||
if [ $rc != 0 ]; then
|
||||
eerror "Unable to mount tmpfs on /run."
|
||||
eerror "Can't continue."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
checkpath -d $RC_SVCDIR
|
||||
checkpath -d -m 0775 -o root:uucp /run/lock
|
||||
|
||||
# Try to mount xenfs as early as possible, otherwise rc_sys() will always
|
||||
# return RC_SYS_XENU and will think that we are in a domU while it's not.
|
||||
if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then
|
||||
ebegin "Mounting xenfs"
|
||||
if ! fstabinfo --mount /proc/xen; then
|
||||
mount -n -t xenfs xenfs /proc/xen -o nosuid,nodev,noexec
|
||||
fi
|
||||
eend $?
|
||||
fi
|
||||
|
||||
if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
|
||||
cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
|
||||
fi
|
||||
|
||||
echo sysinit >"$RC_SVCDIR"/softlevel
|
||||
exit 0
|
||||
36
sh/migrate-to-run.sh.in
Normal file
36
sh/migrate-to-run.sh.in
Normal file
@@ -0,0 +1,36 @@
|
||||
#!@SHELL@
|
||||
# Copyright (c) 2012-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
. "@LIBEXECDIR@/sh/functions.sh"
|
||||
|
||||
if [ -e /run/openrc/softlevel ]; then
|
||||
einfo "The OpenRC dependency data has already been migrated."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d /run ]; then
|
||||
eerror "/run is not a directory."
|
||||
eerror "moving /run to /run.pre-openrc"
|
||||
mv /run /run.pre-openrc
|
||||
mkdir /run
|
||||
fi
|
||||
|
||||
rm -rf /run/openrc
|
||||
|
||||
if ! mountinfo -q -f tmpfs /run; then
|
||||
ln -s "@LIBEXECDIR@"/init.d /run/openrc
|
||||
else
|
||||
cp -a "@LIBEXECDIR@/init.d" /run/openrc
|
||||
rc-update -u
|
||||
fi
|
||||
|
||||
einfo "The OpenRC dependency data was migrated successfully."
|
||||
exit 0
|
||||
389
sh/openrc-run.sh.in
Normal file
389
sh/openrc-run.sh.in
Normal file
@@ -0,0 +1,389 @@
|
||||
#!@SHELL@
|
||||
# Shell wrapper for openrc-run
|
||||
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
verify_boot()
|
||||
{
|
||||
if [ ! -e ${RC_SVCDIR}/softlevel ]; then
|
||||
eerror "You are attempting to run an openrc service on a"
|
||||
eerror "system which openrc did not boot."
|
||||
eerror "You may be inside a chroot or you may have used"
|
||||
eerror "another initialization system to boot this system."
|
||||
eerror "In this situation, you will get unpredictable results!"
|
||||
eerror
|
||||
eerror "If you really want to do this, issue the following command:"
|
||||
eerror "touch ${RC_SVCDIR}/softlevel"
|
||||
exit 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
sourcex()
|
||||
{
|
||||
if [ "$1" = "-e" ]; then
|
||||
shift
|
||||
[ -e "$1" ] || return 1
|
||||
fi
|
||||
if ! . "$1"; then
|
||||
eerror "$RC_SVCNAME: error loading $1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
sourcex "@LIBEXECDIR@/sh/functions.sh"
|
||||
sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
|
||||
case $RC_SYS in
|
||||
PREFIX|CHROOT+UNSHARE) ;;
|
||||
*) sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh";;
|
||||
esac
|
||||
|
||||
# Support LiveCD foo
|
||||
if sourcex -e "/sbin/livecd-functions.sh"; then
|
||||
livecd_read_commandline
|
||||
fi
|
||||
|
||||
if [ -z "$1" -o -z "$2" ]; then
|
||||
eerror "$RC_SVCNAME: not enough arguments"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# So daemons know where to recall us if needed
|
||||
RC_SERVICE="$1" ; export RC_SERVICE
|
||||
shift
|
||||
|
||||
# Compat
|
||||
SVCNAME=$RC_SVCNAME ; export SVCNAME
|
||||
|
||||
# Dependency function
|
||||
config() {
|
||||
[ -n "$*" ] && echo "config $*"
|
||||
}
|
||||
need() {
|
||||
[ -n "$*" ] && echo "need $*"
|
||||
}
|
||||
use() {
|
||||
[ -n "$*" ] && echo "use $*"
|
||||
}
|
||||
want() {
|
||||
[ -n "$*" ] && echo "want $*"
|
||||
}
|
||||
before() {
|
||||
[ -n "$*" ] && echo "before $*"
|
||||
}
|
||||
after() {
|
||||
[ -n "$*" ] && echo "after $*"
|
||||
}
|
||||
provide() {
|
||||
[ -n "$*" ] && echo "provide $*"
|
||||
}
|
||||
keyword() {
|
||||
local c x
|
||||
set -- $*
|
||||
while [ -n "$*" ]; do
|
||||
case "$1" in
|
||||
-containers) x="$(_get_containers)" ;;
|
||||
!-containers) x="$(_get_containers_remove)" ;;
|
||||
*) x=$1 ;;
|
||||
esac
|
||||
c="${c}${x} "
|
||||
shift
|
||||
done
|
||||
[ -n "$c" ] && echo "keyword $c"
|
||||
}
|
||||
|
||||
# Describe the init script to the user
|
||||
describe()
|
||||
{
|
||||
if [ -n "$description" ]; then
|
||||
einfo "$description"
|
||||
else
|
||||
ewarn "No description for $RC_SVCNAME"
|
||||
fi
|
||||
|
||||
local svc= desc=
|
||||
for svc in ${extra_commands:-$opts} $extra_started_commands \
|
||||
$extra_stopped_commands; do
|
||||
eval desc=\$description_$svc
|
||||
if [ -n "$desc" ]; then
|
||||
einfo "$HILITE$svc$NORMAL: $desc"
|
||||
else
|
||||
ewarn "$HILITE$svc$NORMAL: no description"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Report status
|
||||
_status()
|
||||
{
|
||||
if service_stopping; then
|
||||
ewarn "status: stopping"
|
||||
return 4
|
||||
elif service_starting; then
|
||||
ewarn "status: starting"
|
||||
return 8
|
||||
elif service_inactive; then
|
||||
ewarn "status: inactive"
|
||||
return 16
|
||||
elif service_started; then
|
||||
if service_crashed; then
|
||||
eerror "status: crashed"
|
||||
return 32
|
||||
fi
|
||||
einfo "status: started"
|
||||
return 0
|
||||
else
|
||||
einfo "status: stopped"
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
# These functions select the appropriate function to call from the
|
||||
# supervisor modules
|
||||
default_start()
|
||||
{
|
||||
local func=ssd_start
|
||||
case "$supervisor" in
|
||||
runit) func=runit_start ;;
|
||||
s6) func=s6_start ;;
|
||||
supervise-daemon) func=supervise_start ;;
|
||||
?*)
|
||||
ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon"
|
||||
;;
|
||||
esac
|
||||
$func
|
||||
}
|
||||
|
||||
default_stop()
|
||||
{
|
||||
local func=ssd_stop
|
||||
case "$supervisor" in
|
||||
runit) func=runit_stop ;;
|
||||
s6) func=s6_stop ;;
|
||||
supervise-daemon) func=supervise_stop ;;
|
||||
?*)
|
||||
ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon"
|
||||
;;
|
||||
esac
|
||||
$func
|
||||
}
|
||||
|
||||
default_status()
|
||||
{
|
||||
local func=ssd_status
|
||||
case "$supervisor" in
|
||||
runit) func=runit_status ;;
|
||||
s6) func=s6_status ;;
|
||||
supervise-daemon) func=supervise_status ;;
|
||||
?*)
|
||||
ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon"
|
||||
;;
|
||||
esac
|
||||
$func
|
||||
}
|
||||
|
||||
# Template start / stop / status functions
|
||||
# package init scripts may override these, but the bodies are as minimal as
|
||||
# possible, so that the init scripts can creatively wrap default_*
|
||||
# functions.
|
||||
start()
|
||||
{
|
||||
default_start
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
default_stop
|
||||
}
|
||||
|
||||
status()
|
||||
{
|
||||
default_status
|
||||
}
|
||||
|
||||
# Start debug output
|
||||
yesno $RC_DEBUG && set -x
|
||||
|
||||
# Load configuration settings. First the global ones, then any
|
||||
# service-specific settings.
|
||||
sourcex -e "@SYSCONFDIR@/rc.conf"
|
||||
if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
|
||||
for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
|
||||
sourcex -e "$_f"
|
||||
done
|
||||
fi
|
||||
|
||||
_conf_d=${RC_SERVICE%/*}/../conf.d
|
||||
# If we're net.eth0 or openvpn.work then load net or openvpn config
|
||||
_c=${RC_SVCNAME%%.*}
|
||||
if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
|
||||
if ! sourcex -e "$_conf_d/$_c.$RC_RUNLEVEL"; then
|
||||
sourcex -e "$_conf_d/$_c"
|
||||
fi
|
||||
fi
|
||||
unset _c
|
||||
|
||||
# Overlay with our specific config
|
||||
if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then
|
||||
sourcex -e "$_conf_d/$RC_SVCNAME"
|
||||
fi
|
||||
unset _conf_d
|
||||
|
||||
# load service supervisor functions
|
||||
sourcex "@LIBEXECDIR@/sh/runit.sh"
|
||||
sourcex "@LIBEXECDIR@/sh/s6.sh"
|
||||
sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
|
||||
sourcex "@LIBEXECDIR@/sh/supervise-daemon.sh"
|
||||
|
||||
# Set verbose mode
|
||||
if yesno "${rc_verbose:-$RC_VERBOSE}"; then
|
||||
EINFO_VERBOSE=yes
|
||||
export EINFO_VERBOSE
|
||||
fi
|
||||
|
||||
for _cmd; do
|
||||
if [ "$_cmd" != status -a "$_cmd" != describe ]; then
|
||||
# Apply any ulimit defined
|
||||
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && \
|
||||
ulimit ${rc_ulimit:-$RC_ULIMIT}
|
||||
# Apply cgroups settings if defined
|
||||
if [ "$(command -v cgroup_add_service)" = \
|
||||
"cgroup_add_service" ]
|
||||
then
|
||||
if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup ]; then
|
||||
eerror "No permission to apply cgroup settings"
|
||||
break
|
||||
fi
|
||||
cgroup_add_service /sys/fs/cgroup/openrc
|
||||
cgroup_add_service /sys/fs/cgroup/systemd/system
|
||||
fi
|
||||
[ "$(command -v cgroup_set_limits)" = \
|
||||
"cgroup_set_limits" ] && \
|
||||
cgroup_set_limits
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Load our script
|
||||
sourcex "$RC_SERVICE"
|
||||
|
||||
eval "printf '%s\n' $required_dirs" | while read _d; do
|
||||
if [ -n "$_d" ] && [ ! -d "$_d" ]; then
|
||||
eerror "$RC_SVCNAME: \`$_d' is not a directory"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
[ $? -ne 0 ] && exit 1
|
||||
unset _d
|
||||
|
||||
eval "printf '%s\n' $required_files" | while read _f; do
|
||||
if [ -n "$_f" ] && [ ! -r "$_f" ]; then
|
||||
eerror "$RC_SVCNAME: \`$_f' is not readable"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
[ $? -ne 0 ] && exit 1
|
||||
unset _f
|
||||
|
||||
if [ -n "$opts" ]; then
|
||||
ewarn "Use of the opts variable is deprecated and will be"
|
||||
ewarn "removed in the future."
|
||||
ewarn "Please use extra_commands, extra_started_commands or extra_stopped_commands."
|
||||
fi
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
# Special case depend
|
||||
if [ "$1" = depend ]; then
|
||||
shift
|
||||
|
||||
# Enter the dir of the init script to fix the globbing
|
||||
# bug 412677
|
||||
cd ${RC_SERVICE%/*}
|
||||
_depend
|
||||
cd /
|
||||
continue
|
||||
fi
|
||||
# See if we have the required function and run it
|
||||
for _cmd in describe start stop status ${extra_commands:-$opts} \
|
||||
$extra_started_commands $extra_stopped_commands
|
||||
do
|
||||
if [ "$_cmd" = "$1" ]; then
|
||||
if [ "$(command -v "$1")" = "$1" ]; then
|
||||
# If we're in the background, we may wish to
|
||||
# fake some commands. We do this so we can
|
||||
# "start" ourselves from inactive which then
|
||||
# triggers other services to start which
|
||||
# depend on us.
|
||||
# A good example of this is openvpn.
|
||||
if yesno $IN_BACKGROUND; then
|
||||
for _cmd in $in_background_fake; do
|
||||
if [ "$_cmd" = "$1" ]; then
|
||||
shift
|
||||
continue 3
|
||||
fi
|
||||
done
|
||||
fi
|
||||
# Check to see if we need to be started before
|
||||
# we can run this command
|
||||
for _cmd in $extra_started_commands; do
|
||||
if [ "$_cmd" = "$1" ]; then
|
||||
if verify_boot && ! service_started; then
|
||||
eerror "$RC_SVCNAME: cannot \`$1' as it has not been started"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
# Check to see if we need to be stopped before
|
||||
# we can run this command
|
||||
for _cmd in $extra_stopped_commands; do
|
||||
if [ "$_cmd" = "$1" ]; then
|
||||
if verify_boot && ! service_stopped; then
|
||||
eerror "$RC_SVCNAME: cannot \`$1' as it has not been stopped"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
unset _cmd
|
||||
case $1 in
|
||||
start|stop|status) verify_boot;;
|
||||
esac
|
||||
if [ "$(command -v "$1_pre")" = "$1_pre" ]
|
||||
then
|
||||
"$1"_pre || exit $?
|
||||
fi
|
||||
"$1" || exit $?
|
||||
if [ "$(command -v "$1_post")" = "$1_post" ]
|
||||
then
|
||||
"$1"_post || exit $?
|
||||
fi
|
||||
[ "$(command -v cgroup_cleanup)" = "cgroup_cleanup" -a \
|
||||
"$1" = "stop" ] && \
|
||||
yesno "${rc_cgroup_cleanup}" && \
|
||||
cgroup_cleanup
|
||||
shift
|
||||
continue 2
|
||||
else
|
||||
if [ "$_cmd" = "start" -o "$_cmd" = "stop" ]
|
||||
then
|
||||
shift
|
||||
continue 2
|
||||
else
|
||||
eerror "$RC_SVCNAME: function \`$1' defined but does not exist"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
eerror "$RC_SVCNAME: unknown function \`$1'"
|
||||
exit 1
|
||||
done
|
||||
|
||||
exit 0
|
||||
154
sh/rc-cgroup.sh.in
Normal file
154
sh/rc-cgroup.sh.in
Normal file
@@ -0,0 +1,154 @@
|
||||
#!@SHELL@
|
||||
# Copyright (c) 2012-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
|
||||
description_cgroup_cleanup="Kill all processes in the cgroup"
|
||||
|
||||
cgroup_find_path()
|
||||
{
|
||||
local OIFS n name dir result
|
||||
[ -n "$1" ] || return 0
|
||||
OIFS="$IFS"
|
||||
IFS=":"
|
||||
while read n name dir; do
|
||||
[ "$name" = "$1" ] && result="$dir"
|
||||
done < /proc/1/cgroup
|
||||
IFS="$OIFS"
|
||||
echo $result
|
||||
}
|
||||
|
||||
cgroup_get_pids()
|
||||
{
|
||||
local p
|
||||
pids=
|
||||
while read p; do
|
||||
[ $p -eq $$ ] || pids="${pids} ${p}"
|
||||
done < /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks
|
||||
[ -n "$pids" ]
|
||||
}
|
||||
|
||||
cgroup_running()
|
||||
{
|
||||
[ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ]
|
||||
}
|
||||
|
||||
cgroup_set_values()
|
||||
{
|
||||
[ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0
|
||||
|
||||
local controller="$1" h=$(cgroup_find_path "$1")
|
||||
cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
|
||||
[ -d "$cgroup" ] || mkdir -p "$cgroup"
|
||||
|
||||
set -- $2
|
||||
local name val
|
||||
while [ -n "$1" -a "$controller" != "cpuacct" ]; do
|
||||
case "$1" in
|
||||
$controller.*)
|
||||
if [ -n "$name" -a -w "$cgroup/$name" -a -n "$val" ]; then
|
||||
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
|
||||
printf "%s" "$val" > "$cgroup/$name"
|
||||
fi
|
||||
name=$1
|
||||
val=
|
||||
;;
|
||||
*)
|
||||
[ -n "$val" ] &&
|
||||
val="$val $1" ||
|
||||
val="$1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if [ -n "$name" -a -w "$cgroup/$name" -a -n "$val" ]; then
|
||||
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
|
||||
printf "%s" "$val" > "$cgroup/$name"
|
||||
fi
|
||||
|
||||
if [ -w "$cgroup/tasks" ]; then
|
||||
veinfo "$RC_SVCNAME: adding to $cgroup/tasks"
|
||||
printf "%d" 0 > "$cgroup/tasks"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup_add_service()
|
||||
{
|
||||
# relocate starting process to the top of the cgroup
|
||||
# it prevents from unwanted inheriting of the user
|
||||
# cgroups. But may lead to a problems where that inheriting
|
||||
# is needed.
|
||||
for d in /sys/fs/cgroup/* ; do
|
||||
[ -w "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
|
||||
done
|
||||
|
||||
openrc_cgroup=/sys/fs/cgroup/openrc
|
||||
if [ -d "$openrc_cgroup" ]; then
|
||||
cgroup="$openrc_cgroup/$RC_SVCNAME"
|
||||
mkdir -p "$cgroup"
|
||||
[ -w "$cgroup/tasks" ] && printf "%d" 0 > "$cgroup/tasks"
|
||||
fi
|
||||
}
|
||||
|
||||
cgroup_set_limits()
|
||||
{
|
||||
local blkio="${rc_cgroup_blkio:-$RC_CGROUP_BLKIO}"
|
||||
[ -n "$blkio" ] && cgroup_set_values blkio "$blkio"
|
||||
|
||||
local cpu="${rc_cgroup_cpu:-$RC_CGROUP_CPU}"
|
||||
[ -n "$cpu" ] && cgroup_set_values cpu "$cpu"
|
||||
|
||||
local cpuacct="${rc_cgroup_cpuacct:-$RC_CGROUP_CPUACCT}"
|
||||
[ -n "$cpuacct" ] && cgroup_set_values cpuacct "$cpuacct"
|
||||
|
||||
local cpuset="${rc_cgroup_cpuset:-$RC_CGROUP_cpuset}"
|
||||
[ -n "$cpuset" ] && cgroup_set_values cpuset "$cpuset"
|
||||
|
||||
local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}"
|
||||
[ -n "$devices" ] && cgroup_set_values devices "$devices"
|
||||
|
||||
local hugetlb="${rc_cgroup_hugetlb:-$RC_CGROUP_HUGETLB}"
|
||||
[ -n "$hugetlb" ] && cgroup_set_values hugetlb "$hugetlb"
|
||||
|
||||
local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}"
|
||||
[ -n "$memory" ] && cgroup_set_values memory "$memory"
|
||||
|
||||
local net_cls="${rc_cgroup_net_cls:-$RC_CGROUP_NET_CLS}"
|
||||
[ -n "$net_cls" ] && cgroup_set_values net_cls "$net_cls"
|
||||
|
||||
local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}"
|
||||
[ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio"
|
||||
|
||||
local pids="${rc_cgroup_pids:-$RC_CGROUP_PIDS}"
|
||||
[ -n "$pids" ] && cgroup_set_values pids "$pids"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup_cleanup()
|
||||
{
|
||||
cgroup_running || return 0
|
||||
ebegin "starting cgroups cleanup"
|
||||
for sig in TERM QUIT INT; do
|
||||
cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
|
||||
for i in 0 1; do
|
||||
kill -s $sig $pids
|
||||
for j in 0 1 2; do
|
||||
cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
|
||||
sleep 1
|
||||
done
|
||||
done 2>/dev/null
|
||||
done
|
||||
cgroup_get_pids || { eend 0 "finished" ; return 0; }
|
||||
kill -9 $pids
|
||||
eend $(cgroup_running && echo 1 || echo 0) "fail to stop all processes"
|
||||
}
|
||||
168
sh/rc-functions.sh.in
Normal file
168
sh/rc-functions.sh.in
Normal file
@@ -0,0 +1,168 @@
|
||||
# Copyright (c) 2007 Gentoo Foundation
|
||||
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
||||
# Released under the 2-clause BSD license.
|
||||
|
||||
has_addon()
|
||||
{
|
||||
[ -e /@LIB@/rc/addons/"$1".sh -o -e /@LIB@/rcscripts/addons/"$1".sh ]
|
||||
}
|
||||
|
||||
_addon_warn()
|
||||
{
|
||||
eindent
|
||||
ewarn "$RC_SVCNAME uses addon code which is deprecated"
|
||||
ewarn "and may not be available in the future."
|
||||
eoutdent
|
||||
}
|
||||
|
||||
import_addon()
|
||||
{
|
||||
if [ -e /@LIB@/rc/addons/"$1".sh ]; then
|
||||
_addon_warn
|
||||
. /@LIB@/rc/addons/"$1".sh
|
||||
elif [ -e /@LIB@/rcscripts/addons/"$1".sh ]; then
|
||||
_addon_warn
|
||||
. /@LIB@/rcscripts/addons/"$1".sh
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
start_addon()
|
||||
{
|
||||
( import_addon "$1-start" )
|
||||
}
|
||||
|
||||
stop_addon()
|
||||
{
|
||||
( import_addon "$1-stop" )
|
||||
}
|
||||
|
||||
net_fs_list="afs ceph cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre
|
||||
ncpfs nfs nfs4 ocfs2 shfs smbfs"
|
||||
is_net_fs()
|
||||
{
|
||||
[ -z "$1" ] && return 1
|
||||
|
||||
# Check OS specific flags to see if we're local or net mounted
|
||||
mountinfo --quiet --netdev "$1" && return 0
|
||||
mountinfo --quiet --nonetdev "$1" && return 1
|
||||
|
||||
# Fall back on fs types
|
||||
local t=$(mountinfo --fstype "$1")
|
||||
for x in $net_fs_list $extra_net_fs_list; do
|
||||
[ "$x" = "$t" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
is_union_fs()
|
||||
{
|
||||
[ ! -x /sbin/unionctl ] && return 1
|
||||
unionctl "$1" --list >/dev/null 2>&1
|
||||
}
|
||||
|
||||
get_bootparam()
|
||||
{
|
||||
local match="$1"
|
||||
[ -z "$match" -o ! -r /proc/cmdline ] && return 1
|
||||
|
||||
set -- $(cat /proc/cmdline)
|
||||
while [ -n "$1" ]; do
|
||||
[ "$1" = "$match" ] && return 0
|
||||
case "$1" in
|
||||
gentoo=*)
|
||||
local params="${1##*=}"
|
||||
local IFS=, x=
|
||||
for x in $params; do
|
||||
[ "$x" = "$match" ] && return 0
|
||||
done
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
get_bootparam_value()
|
||||
{
|
||||
local match="$1" which_value="$2" sep="$3" result value
|
||||
if [ -n "$match" -a -r /proc/cmdline ]; then
|
||||
set -- $(cat /proc/cmdline)
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
$match=*)
|
||||
value="${1##*=}"
|
||||
case "$which_value" in
|
||||
all)
|
||||
[ -z "$sep" ] && sep=' '
|
||||
if [ -z "$result" ]; then
|
||||
result="$value"
|
||||
else
|
||||
result="${result}${sep}${value}"
|
||||
fi
|
||||
;;
|
||||
last)
|
||||
result="$value"
|
||||
;;
|
||||
*)
|
||||
result="$value"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
fi
|
||||
echo $result
|
||||
}
|
||||
|
||||
# Called from openrc-run.sh or gendepends.sh
|
||||
_get_containers() {
|
||||
local c
|
||||
case "${RC_UNAME}" in
|
||||
FreeBSD)
|
||||
c="-jail"
|
||||
;;
|
||||
Linux)
|
||||
c="-docker -lxc -openvz -rkt -chroot+unshare -uml -vserver"
|
||||
;;
|
||||
esac
|
||||
echo $c
|
||||
}
|
||||
|
||||
_get_containers_remove() {
|
||||
local c
|
||||
for x in $(_get_containers); do
|
||||
c="${c}!${x} "
|
||||
done
|
||||
echo $c
|
||||
}
|
||||
|
||||
_depend() {
|
||||
depend
|
||||
local _rc_svcname=$(shell_var "$RC_SVCNAME") _deptype= _depends=
|
||||
|
||||
# Add any user defined depends
|
||||
for _deptype in config:CONFIG need:NEED use:USE want:WANT \
|
||||
after:AFTER before:BEFORE \
|
||||
provide:PROVIDE keyword:KEYWORD; do
|
||||
IFS=:
|
||||
set -- $_deptype
|
||||
unset IFS
|
||||
eval _depends=\$rc_${_rc_svcname}_$1
|
||||
[ -z "$_depends" ] && eval _depends=\$rc_$1
|
||||
[ -z "$_depends" ] && eval _depends=\$RC_${_rc_svcname}_$2
|
||||
[ -z "$_depends" ] && eval _depends=\$RC_$2
|
||||
|
||||
$1 $_depends
|
||||
done
|
||||
}
|
||||
|
||||
# Add our sbin to $PATH
|
||||
case "$PATH" in
|
||||
"$RC_LIBEXECDIR"/sbin|"$RC_LIBEXECDIR"/sbin:*);;
|
||||
*) PATH="$RC_LIBEXECDIR/sbin:$PATH" ; export PATH ;;
|
||||
esac
|
||||
87
sh/rc-mount.sh
Normal file
87
sh/rc-mount.sh
Normal file
@@ -0,0 +1,87 @@
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
# Declare this here so that no formatting doesn't affect the embedded newline
|
||||
__IFS="
|
||||
"
|
||||
|
||||
# Handy function to handle all our unmounting needs
|
||||
# mountinfo is a C program to actually find our mounts on our supported OS's
|
||||
# We rely on fuser being present, so if it's not then don't unmount anything.
|
||||
# This isn't a real issue for the BSD's, but it is for Linux.
|
||||
do_unmount()
|
||||
{
|
||||
local cmd="$1" retval=0 retry= pids=-
|
||||
local f_opts="-m -c" f_kill="-s " mnt=
|
||||
if [ "$RC_UNAME" = "Linux" ]; then
|
||||
f_opts="-m"
|
||||
f_kill="-"
|
||||
fi
|
||||
|
||||
shift
|
||||
local IFS="$__IFS"
|
||||
set -- $(mountinfo "$@")
|
||||
unset IFS
|
||||
for mnt; do
|
||||
# Unmounting a shared mount can unmount other mounts, so
|
||||
# we need to check the mount is still valid
|
||||
mountinfo --quiet "$mnt" || continue
|
||||
# Ensure we interpret all characters properly.
|
||||
mnt=$(printf "$mnt")
|
||||
|
||||
case "$cmd" in
|
||||
umount)
|
||||
ebegin "Unmounting $mnt"
|
||||
;;
|
||||
*)
|
||||
ebegin "Remounting $mnt read only"
|
||||
;;
|
||||
esac
|
||||
|
||||
retry=4 # Effectively TERM, sleep 1, TERM, sleep 1, KILL, sleep 1
|
||||
while ! LC_ALL=C $cmd "$mnt" 2>/dev/null; do
|
||||
if command -v fuser >/dev/null 2>&1; then
|
||||
pids="$(timeout -k 10 -s KILL "${rc_fuser_timeout:-60}" \
|
||||
fuser $f_opts "$mnt" 2>/dev/null)"
|
||||
fi
|
||||
case " $pids " in
|
||||
*" $$ "*)
|
||||
eend 1 "failed because we are using" \
|
||||
"$mnt"
|
||||
retry=0;;
|
||||
" - ")
|
||||
eend 1
|
||||
retry=0;;
|
||||
" ")
|
||||
eend 1 "in use but fuser finds nothing"
|
||||
retry=0;;
|
||||
*)
|
||||
if [ $retry -le 0 ]; then
|
||||
eend 1
|
||||
else
|
||||
local sig="TERM"
|
||||
: $(( retry -= 1 ))
|
||||
[ $retry = 1 ] && sig="KILL"
|
||||
fuser $f_kill$sig -k $f_opts \
|
||||
"$mnt" >/dev/null 2>&1
|
||||
sleep 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
[ $retry -le 0 ] && break
|
||||
done
|
||||
if [ $retry -le 0 ]; then
|
||||
retval=1
|
||||
else
|
||||
eend 0
|
||||
fi
|
||||
done
|
||||
return $retval
|
||||
}
|
||||
52
sh/runit.sh
Normal file
52
sh/runit.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2016 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
# Released under the 2-clause BSD license.
|
||||
|
||||
runit_start()
|
||||
{
|
||||
local service_path service_link
|
||||
service_path="${runit_service:-/etc/sv/${RC_SVCNAME}}"
|
||||
if [ ! -d "${service_path}" ]; then
|
||||
eerror "Runit service ${service_path} not found"
|
||||
return 1
|
||||
fi
|
||||
service_link="${RC_SVCDIR}/sv/${service_path##*/}"
|
||||
ebegin "Starting ${name:-$RC_SVCNAME}"
|
||||
ln -snf "${service_path}" "${service_link}"
|
||||
sv start "${service_link}" > /dev/null 2>&1
|
||||
eend $? "Failed to start ${name:-$RC_SVCNAME}"
|
||||
}
|
||||
|
||||
runit_stop()
|
||||
{
|
||||
local service_path service_link
|
||||
service_path="${runit_service:-/etc/sv/${RC_SVCNAME}}"
|
||||
if [ ! -d "${service_path}" ]; then
|
||||
eerror "Runit service ${service_path} not found"
|
||||
return 1
|
||||
fi
|
||||
service_link="${RC_SVCDIR}/sv/${service_path##*/}"
|
||||
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
||||
sv stop "${service_link}" > /dev/null 2>&1 &&
|
||||
rm "${service_link}"
|
||||
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
|
||||
}
|
||||
|
||||
runit_status()
|
||||
{
|
||||
local service_path service_link
|
||||
service_path="${runit_service:-/etc/sv/${RC_SVCNAME}}"
|
||||
if [ ! -d "${service_path}" ]; then
|
||||
eerror "Runit service ${service_path} not found"
|
||||
return 1
|
||||
fi
|
||||
service_link="${RC_SVCDIR}/sv/${service_path##*/}"
|
||||
sv status "${service_link}"
|
||||
}
|
||||
34
sh/runtests.sh
Executable file
34
sh/runtests.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
# Copyright (c) 2008-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
: ${top_srcdir:=..}
|
||||
. $top_srcdir/test/setup_env.sh
|
||||
|
||||
ret=0
|
||||
|
||||
tret=0
|
||||
ebegin "Testing yesno()"
|
||||
for f in yes YES Yes true TRUE True 1 ; do
|
||||
if ! yesno $f; then
|
||||
: $(( tret += 1 ))
|
||||
echo "!$f!"
|
||||
fi
|
||||
done
|
||||
for f in no NO No false FALSE False 0 ; do
|
||||
if yesno $f; then
|
||||
: $(( tret += 1 ))
|
||||
echo "!$f!"
|
||||
fi
|
||||
done
|
||||
eend $tret
|
||||
: $(( ret += $tret ))
|
||||
|
||||
exit $ret
|
||||
58
sh/s6.sh
Normal file
58
sh/s6.sh
Normal file
@@ -0,0 +1,58 @@
|
||||
# Start / stop / status functions for s6 support
|
||||
|
||||
# Copyright (c) 2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
[ -z "${s6_service_path}" ] && s6_service_path="/var/svc.d/${RC_SVCNAME}"
|
||||
|
||||
s6_start()
|
||||
{
|
||||
if [ ! -d "${s6_service_path}" ]; then
|
||||
eerror "${s6_service_path} does not exist."
|
||||
return 1
|
||||
fi
|
||||
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
||||
ebegin "Starting ${name:-$RC_SVCNAME}"
|
||||
ln -sf "${s6_service_path}" "${s6_service_link}"
|
||||
s6-svscanctl -na "${RC_SVCDIR}"/s6-scan
|
||||
sleep 1.5
|
||||
s6-svc -u "${s6_service_link}"
|
||||
if [ -n "$s6_svwait_options_start" ]; then
|
||||
s6-svwait ${s6_svwait_options_start} "${s6_service_link}"
|
||||
fi
|
||||
sleep 1.5
|
||||
set -- $(s6-svstat "${s6_service_link}")
|
||||
[ "$1" = "up" ]
|
||||
eend $? "Failed to start ${name:-$RC_SVCNAME}"
|
||||
}
|
||||
|
||||
s6_stop()
|
||||
{
|
||||
if [ ! -d "${s6_service_path}" ]; then
|
||||
eerror "${s6_service_path} does not exist."
|
||||
return 1
|
||||
fi
|
||||
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
||||
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
||||
s6-svc -wD -d -T ${s6_service_timeout_stop:-10000} "${s6_service_link}"
|
||||
set -- $(s6-svstat "${s6_service_link}")
|
||||
[ "$1" = "down" ]
|
||||
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
|
||||
}
|
||||
|
||||
s6_status()
|
||||
{
|
||||
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
||||
if [ -L "${s6_service_link}" ]; then
|
||||
s6-svstat "${s6_service_link}"
|
||||
else
|
||||
_status
|
||||
fi
|
||||
}
|
||||
95
sh/start-stop-daemon.sh
Normal file
95
sh/start-stop-daemon.sh
Normal file
@@ -0,0 +1,95 @@
|
||||
# start / stop / status functions for start-stop-daemon
|
||||
|
||||
# Copyright (c) 2007-2015 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
ssd_start()
|
||||
{
|
||||
if [ -z "$command" ]; then
|
||||
ewarn "The command variable is undefined."
|
||||
ewarn "There is nothing for ${name:-$RC_SVCNAME} to start."
|
||||
ewarn "If this is what you intend, please write a start function."
|
||||
ewarn "This will become a failure in a future release."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local _background=
|
||||
ebegin "Starting ${name:-$RC_SVCNAME}"
|
||||
if yesno "${command_background}"; then
|
||||
if [ -z "${pidfile}" ]; then
|
||||
eend 1 "command_background option used but no pidfile specified"
|
||||
return 1
|
||||
fi
|
||||
if [ -n "${command_args_background}" ]; then
|
||||
eend 1 "command_background used with command_args_background"
|
||||
return 1
|
||||
fi
|
||||
_background="--background --make-pidfile"
|
||||
fi
|
||||
if yesno "$start_inactive"; then
|
||||
local _inactive=false
|
||||
service_inactive && _inactive=true
|
||||
mark_service_inactive
|
||||
fi
|
||||
#the eval call is necessary for cases like:
|
||||
# command_args="this \"is a\" test"
|
||||
# to work properly.
|
||||
eval start-stop-daemon --start \
|
||||
--exec $command \
|
||||
${chroot:+--chroot} $chroot \
|
||||
${procname:+--name} $procname \
|
||||
${pidfile:+--pidfile} $pidfile \
|
||||
${command_user+--user} $command_user \
|
||||
$_background $start_stop_daemon_args \
|
||||
-- $command_args $command_args_background
|
||||
if eend $? "Failed to start ${name:-$RC_SVCNAME}"; then
|
||||
service_set_value "command" "${command}"
|
||||
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
|
||||
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
|
||||
[ -n "${procname}" ] && service_set_value "procname" "${procname}"
|
||||
return 0
|
||||
fi
|
||||
if yesno "$start_inactive"; then
|
||||
if ! $_inactive; then
|
||||
mark_service_stopped
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
ssd_stop()
|
||||
{
|
||||
local _progress=
|
||||
local startcommand="$(service_get_value "command")"
|
||||
local startchroot="$(service_get_value "chroot")"
|
||||
local startpidfile="$(service_get_value "pidfile")"
|
||||
local startprocname="$(service_get_value "procname")"
|
||||
command="${startcommand:-$command}"
|
||||
chroot="${startchroot:-$chroot}"
|
||||
pidfile="${startpidfile:-$pidfile}"
|
||||
procname="${startprocname:-$procname}"
|
||||
[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
|
||||
yesno "${command_progress}" && _progress=--progress
|
||||
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
||||
start-stop-daemon --stop \
|
||||
${retry:+--retry} $retry \
|
||||
${command:+--exec} $command \
|
||||
${procname:+--name} $procname \
|
||||
${pidfile:+--pidfile} $chroot$pidfile \
|
||||
${stopsig:+--signal} $stopsig \
|
||||
${_progress}
|
||||
|
||||
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
|
||||
}
|
||||
|
||||
ssd_status()
|
||||
{
|
||||
_status
|
||||
}
|
||||
61
sh/supervise-daemon.sh
Normal file
61
sh/supervise-daemon.sh
Normal file
@@ -0,0 +1,61 @@
|
||||
# start / stop / status functions for supervise-daemon
|
||||
|
||||
# Copyright (c) 2016 The OpenRC Authors.
|
||||
# See the Authors file at the top-level directory of this distribution and
|
||||
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
||||
#
|
||||
# This file is part of OpenRC. It is subject to the license terms in
|
||||
# the LICENSE file found in the top-level directory of this
|
||||
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
||||
# This file may not be copied, modified, propagated, or distributed
|
||||
# except according to the terms contained in the LICENSE file.
|
||||
|
||||
supervise_start()
|
||||
{
|
||||
if [ -z "$command" ]; then
|
||||
ewarn "The command variable is undefined."
|
||||
ewarn "There is nothing for ${name:-$RC_SVCNAME} to start."
|
||||
return 1
|
||||
fi
|
||||
|
||||
ebegin "Starting ${name:-$RC_SVCNAME}"
|
||||
# The eval call is necessary for cases like:
|
||||
# command_args="this \"is a\" test"
|
||||
# to work properly.
|
||||
eval supervise-daemon --start \
|
||||
${chroot:+--chroot} $chroot \
|
||||
${pidfile:+--pidfile} $pidfile \
|
||||
${respawn_delay:+--respawn-delay} $respawn_delay \
|
||||
${respawn_max:+--respawn-max} $respawn_max \
|
||||
${respawn_period:+--respawn-period} $respawn_period \
|
||||
${command_user+--user} $command_user \
|
||||
$supervise_daemon_args \
|
||||
$command \
|
||||
-- $command_args $command_args_foreground
|
||||
rc=$?
|
||||
if [ $rc = 0 ]; then
|
||||
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
|
||||
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
|
||||
fi
|
||||
eend $rc "failed to start ${name:-$RC_SVCNAME}"
|
||||
}
|
||||
|
||||
supervise_stop()
|
||||
{
|
||||
local startchroot="$(service_get_value "chroot")"
|
||||
local startpidfile="$(service_get_value "pidfile")"
|
||||
chroot="${startchroot:-$chroot}"
|
||||
pidfile="${startpidfile:-$pidfile}"
|
||||
[ -n "$pidfile" ] || return 0
|
||||
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
||||
supervise-daemon --stop \
|
||||
${pidfile:+--pidfile} $chroot$pidfile \
|
||||
${stopsig:+--signal} $stopsig
|
||||
|
||||
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
|
||||
}
|
||||
|
||||
supervise_status()
|
||||
{
|
||||
_status
|
||||
}
|
||||
Reference in New Issue
Block a user