Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions tubesync/restart_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,32 @@ svc_path() (
realpath -e -s "$@"
)

_bundles="$(
find '/etc/s6-overlay/s6-rc.d' -mindepth 2 -maxdepth 2 \
-name 'type' \
-execdir grep -F -q -e bundle '{}' ';' \
-printf '%P\n' | \
sed -e 's,/type$,,' ;
)"
is_a_bundle() {
local bundle
for bundle in ${_bundles}
is_a_longrun() {
if [ 'longrun' = "$(/command/s6-rc-db type "$1")" ]
then
return 0
fi
return 1
}
only_longruns() {
local service
for service in "$@"
do
if [ "$1" = "${bundle}" ]
if is_a_longrun "${service}"
then
return 0
printf -- '%s\n' "${service}"
fi
done
return 1
}

if [ 0 -eq $# ]
then
set -- $(/command/s6-rc list user | grep -v -e '-init$')
set -- $(only_longruns $(/command/s6-rc -e -a list))
fi

for arg in "$@"
do
_svcs="${arg}"
if is_a_bundle "${arg}"
then
_svcs="$(/command/s6-rc list "${arg}" | grep -v -e '-init$')"
fi
_svcs="$(only_longruns $(/command/s6-rc -e list "${arg}"))"
for service in $(svc_path ${_svcs})
do
printf -- 'Restarting %-28s' "${service#${_dir}/}..."
Expand All @@ -47,5 +42,4 @@ do
"$( expr "${_ended}" - "${_began}" )"
done
done
unset -v _began _ended _svcs arg service
unset -v _bundles _dir
unset -v _began _dir _ended _svcs arg service