mirror of https://dev.ccchb.de/ccchb/ansible.git
Improve s6-rc rc.d script
* Deduplicate path literals * Pass live directory to s6-rc invocations Changes #31
This commit is contained in:
parent
050fb34846
commit
803ebdbded
|
@ -5,6 +5,13 @@
|
||||||
# REQUIRE: NETWORKING daemon
|
# REQUIRE: NETWORKING daemon
|
||||||
# KEYWORD: shutdown
|
# KEYWORD: shutdown
|
||||||
|
|
||||||
|
etc_dir="{{ s6_etc_dir }}"
|
||||||
|
scan_dir="{{ s6_scan_dir }}"
|
||||||
|
live_dir="{{ s6_live_dir }}"
|
||||||
|
|
||||||
|
EX_UNAVAILABLE=69
|
||||||
|
EX_CONFIG=78
|
||||||
|
|
||||||
. /etc/rc.subr
|
. /etc/rc.subr
|
||||||
|
|
||||||
export PATH="$PATH:/usr/local/bin:/usr/local/sbin"
|
export PATH="$PATH:/usr/local/bin:/usr/local/sbin"
|
||||||
|
@ -27,7 +34,7 @@ s6_wait()
|
||||||
{
|
{
|
||||||
local i=0
|
local i=0
|
||||||
|
|
||||||
while ! s6-svscanctl -z /run/service 2>/dev/null; do
|
while ! s6-svscanctl -z "$scan_dir" 2>/dev/null; do
|
||||||
if [ $i -ge $s6_timeout ]; then
|
if [ $i -ge $s6_timeout ]; then
|
||||||
echo "Timeout waiting for s6-svscan." >&2
|
echo "Timeout waiting for s6-svscan." >&2
|
||||||
return 1
|
return 1
|
||||||
|
@ -48,19 +55,19 @@ s6_wait()
|
||||||
|
|
||||||
s6_rc_init()
|
s6_rc_init()
|
||||||
{
|
{
|
||||||
if [ ! -e /run/s6-rc ]; then
|
if [ ! -e "$live_dir" ]; then
|
||||||
s6-rc-init /run/service
|
s6-rc-init -l "$live_dir" "$scan_dir"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
s6_rc_up()
|
s6_rc_up()
|
||||||
{
|
{
|
||||||
s6-rc -v 2 -u -t $up_timeout change enabled
|
s6-rc -l "$live_dir" -v 2 -u -t "$up_timeout" change enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
s6_rc_down()
|
s6_rc_down()
|
||||||
{
|
{
|
||||||
s6-rc -v 2 -d -a -t $down_timeout change
|
s6-rc -l "$live_dir" -v 2 -d -a -t "$down_timeout" change
|
||||||
}
|
}
|
||||||
|
|
||||||
s6_rc_start()
|
s6_rc_start()
|
||||||
|
@ -82,16 +89,26 @@ s6_rc_reload()
|
||||||
{
|
{
|
||||||
local uuid="$(uuidgen)"
|
local uuid="$(uuidgen)"
|
||||||
|
|
||||||
cd /etc/s6-rc
|
cd "$etc_dir"
|
||||||
echo "Compiling new s6-rc service database."
|
echo "Compiling the s6-rc service definitions into a services database: $etc_dir/service -> $etc_dir/.compiled.$uuid."
|
||||||
s6-rc-compile -v 2 ".compiled.$uuid" service
|
if ! s6-rc-compile -v 2 ".compiled.$uuid" service; then
|
||||||
|
echo "Failed to compile the service definitions into a services database." >&2
|
||||||
|
return $EX_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
if s6-rc-update -v 2 -t $update_timeout "/etc/s6-rc/.compiled.$uuid"; then
|
echo "Updating the running s6-rc service manager to the latest compiled services database: $etc_dir/.compiled.$uuid."
|
||||||
|
if s6-rc-update -l "$live_dir" -v 2 -t $update_timeout "$etc_dir/.compiled.$uuid"; then
|
||||||
|
echo "Marking the running services database as selected default configuration: .compiled.$uuid -> compiled."
|
||||||
ln -shf ".compiled.$uuid" compiled
|
ln -shf ".compiled.$uuid" compiled
|
||||||
echo "Updated s6-rc service database."
|
|
||||||
|
|
||||||
echo "Deleting old service databases."
|
echo "Deleting stale services databases."
|
||||||
find -s . -mindepth 1 -maxdepth 1 -type d -name '.compiled.*' -not -name ".compiled.$uuid" -print0 | xargs -0 rm -r
|
if ! find -s . -mindepth 1 -maxdepth 1 -type d -name '.compiled.*' -not -name ".compiled.$uuid" -print0 | xargs -0 rm -r; then
|
||||||
|
echo "Failed to delete stale services databases." >&2
|
||||||
|
return $EX_CONFIG
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Failed to update the running s6-rc manager to the latest service database." >&2
|
||||||
|
return $EX_CONFIG
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,19 +116,20 @@ s6_rc_status()
|
||||||
{
|
{
|
||||||
local result=0
|
local result=0
|
||||||
|
|
||||||
if s6-svscanctl -z /run/service 2>/dev/null; then
|
# Check if s6-svscan is responsive by asking it to invoke its reaper (almost a NOP)
|
||||||
echo "The s6-svscan supervisor is responsible."
|
if s6-svscanctl -z "$scan_dir" 2>/dev/null; then
|
||||||
|
echo "The s6-svscan supervisor is responsive."
|
||||||
else
|
else
|
||||||
echo "The s6-svscan supervisor is unavailable."
|
echo "The s6-svscan supervisor is unavailable."
|
||||||
result=1
|
result=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e /run/s6-rc ]; then
|
if [ -e "$live_dir" ]; then
|
||||||
echo "The s6-rc service manager is initialized."
|
echo "The s6-rc service manager has been initialized."
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "These services are currently active:"
|
echo "These services are currently active:"
|
||||||
s6-rc -a list
|
s6-rc -l "$live_dir" -a list
|
||||||
else
|
else
|
||||||
echo "The s6-rc service manager is uninitalized."
|
echo "The s6-rc service manager is uninitalized."
|
||||||
result=1
|
result=1
|
||||||
|
|
Loading…
Reference in New Issue