mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-20 20:16:35 +00:00
Merge pull request #1099 from tcely/patch-16
Resolve bundles in restart_services.sh
This commit is contained in:
commit
06b175f762
@ -1,26 +1,51 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
dir='/run/service'
|
||||
_dir='/run/service'
|
||||
svc_path() (
|
||||
cd "${dir}"
|
||||
cd "${_dir}" &&
|
||||
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}
|
||||
do
|
||||
if [ "$1" = "${bundle}" ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ 0 -eq $# ]
|
||||
then
|
||||
set -- \
|
||||
$( cd "${dir}" && svc_path tubesync*-worker ) \
|
||||
"$( svc_path gunicorn )" \
|
||||
"$( svc_path nginx )"
|
||||
set -- $(/command/s6-rc list user | grep -v -e '-init$')
|
||||
fi
|
||||
|
||||
for service in $( svc_path "$@" )
|
||||
for arg in "$@"
|
||||
do
|
||||
printf -- 'Restarting %-28s' "${service#${dir}/}..."
|
||||
_svcs="${arg}"
|
||||
if is_a_bundle "${arg}"
|
||||
then
|
||||
_svcs="$(/command/s6-rc list "${arg}" | grep -v -e '-init$')"
|
||||
fi
|
||||
for service in $(svc_path ${_svcs})
|
||||
do
|
||||
printf -- 'Restarting %-28s' "${service#${_dir}/}..."
|
||||
_began="$( date '+%s' )"
|
||||
/command/s6-svc -wr -r "${service}"
|
||||
_ended="$( date '+%s' )"
|
||||
printf -- '\tcompleted (in %2.1d seconds).\n' \
|
||||
"$( expr "${_ended}" - "${_began}" )"
|
||||
done
|
||||
unset -v _began _ended service
|
||||
done
|
||||
unset -v _began _ended _svcs arg service
|
||||
unset -v _bundles _dir
|
||||
|
Loading…
Reference in New Issue
Block a user