Improve /app/restart_services.sh
This commit is contained in:
@@ -6,37 +6,32 @@ svc_path() (
|
|||||||
realpath -e -s "$@"
|
realpath -e -s "$@"
|
||||||
)
|
)
|
||||||
|
|
||||||
_bundles="$(
|
is_a_longrun() {
|
||||||
find '/etc/s6-overlay/s6-rc.d' -mindepth 2 -maxdepth 2 \
|
if [ 'longrun' = "$(/command/s6-rc-db type "$1")" ]
|
||||||
-name 'type' \
|
then
|
||||||
-execdir grep -F -q -e bundle '{}' ';' \
|
return 0
|
||||||
-printf '%P\n' | \
|
fi
|
||||||
sed -e 's,/type$,,' ;
|
return 1
|
||||||
)"
|
}
|
||||||
is_a_bundle() {
|
only_longruns() {
|
||||||
local bundle
|
local service
|
||||||
for bundle in ${_bundles}
|
for service in "$@"
|
||||||
do
|
do
|
||||||
if [ "$1" = "${bundle}" ]
|
if is_a_longrun "${service}"
|
||||||
then
|
then
|
||||||
return 0
|
printf -- '%s\n' "${service}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ 0 -eq $# ]
|
if [ 0 -eq $# ]
|
||||||
then
|
then
|
||||||
set -- $(/command/s6-rc list user | grep -v -e '-init$')
|
set -- $(only_longruns $(/command/s6-rc -e -a list))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for arg in "$@"
|
for arg in "$@"
|
||||||
do
|
do
|
||||||
_svcs="${arg}"
|
_svcs="$(only_longruns $(/command/s6-rc -e list "${arg}"))"
|
||||||
if is_a_bundle "${arg}"
|
|
||||||
then
|
|
||||||
_svcs="$(/command/s6-rc list "${arg}" | grep -v -e '-init$')"
|
|
||||||
fi
|
|
||||||
for service in $(svc_path ${_svcs})
|
for service in $(svc_path ${_svcs})
|
||||||
do
|
do
|
||||||
printf -- 'Restarting %-28s' "${service#${_dir}/}..."
|
printf -- 'Restarting %-28s' "${service#${_dir}/}..."
|
||||||
@@ -47,5 +42,4 @@ do
|
|||||||
"$( expr "${_ended}" - "${_began}" )"
|
"$( expr "${_ended}" - "${_began}" )"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
unset -v _began _ended _svcs arg service
|
unset -v _began _dir _ended _svcs arg service
|
||||||
unset -v _bundles _dir
|
|
||||||
|
|||||||
Reference in New Issue
Block a user