14 Commits
no-help ... 1.0

Author SHA1 Message Date
a2164ac051 s6-rc-db-update-hook: rename usersv to adminsv
Thinking about it some more, usersv is actually a bad name. That implies
local users on the machine which is not correct. These directories are
for adminstrators and are owned by root. Instead, call them adminsv
which makes more sense.
2021-09-21 09:38:48 -05:00
32cfa84a93 s6-rc-db-update-hook: rename to fallbacksv
This name should make it clearer that this directory is only ever used
as an emergency fallback. Alter the printed messages a little bit as
well.
2021-09-20 14:33:01 -05:00
27263a58e8 s6-rc-hook: fix service shutdown behavior
It turns out that old logic caused all services and bundles to always
shutdown. The s6-rc -a list grep always returns some nonzero string.
Thus, the conditional is always true and we always try to shutdown
anything that's removed. This has the side effect of causing any moved
bundles to automatically shutdown as well which is never desirable (only
services that go away for good should shut down). Instead of using -n,
we should check for ! $active which is equivalent to checking if $active
= "". This is what is actually returned by that grep if the sv name is
not in the s6-rc -a list.
2021-09-19 22:10:49 -05:00
09bcac3bbb s6-rc-db-update-hook: support custom user sv path
Finally got around to working on this. Some users in #artix and #s6
correctly pointed out that Artix's s6 implementation is heavily
dependent on s6-rc-bundle and is not very friendly about letting users
edit and make their own services. Specifically, the default bundle and
its contents are commonly overwritten on every s6-scripts update. This
adds some groundwork to splitting the s6-rc database compilation into
multiple directories. ${USERSVPATH} is the path for custom user service
files. The default bundle will live here along with anything else not
installed by the user. ${BACKUPSVPATH} is strictly for emergency usage
when the compilation fails. These are not to be altered by users.
2021-09-19 20:56:11 -05:00
c7db8b46ab s6-rc-update-hook: remove tabs
A couple of tabs snuck in here. Replace them with spaces. Also make that
printf one line (it's not that long).
2021-09-19 17:47:30 -05:00
54b6a8d842 makefile: don't install empty dir for sysusers & tmpfiles 2021-08-29 01:01:45 +02:00
41274292e4 udev: remove commented line 2021-07-24 19:29:53 +02:00
10c5644890 Merge pull request 's6-rc-db-update-hook and s6-rc-bundle-update improvements' (#10) from s6-rc-db-update-posix into master
Reviewed-on: #10
2021-07-18 20:05:52 +02:00
022c5887a5 s6-rc-bundle-update: make error messages prettier
Just add some single quotes to make things nicer. The main change is the
extra if that ensures that there isn't an extra space at the beginning
of CONTENTS.
2021-07-18 12:15:07 -05:00
capezotte
b74274ec84 s6-rc-db-update: optimize the main update loop
s6-rc-bundle-update must do at least one loop to update an existing
bundle. In the main update loop, s6-rc-bundle-update is called several
times which means we do several loops here. However, s6-rc-bundle-update
is designed to be able to handle any arbitrary number of arguments as
needed. In this case, just call it once after we finishing populating
new_contents. This should save a massive amount of time when executing
the script.
2021-07-18 10:28:03 -05:00
9142373219 s6-rc-db-update-hook: reindex loop variables
Start from "i" instead of "j" since it's more natural. The original "i"
got removed at some point during the rewrite. Just shift all the
variables up one letter basically.
2021-07-17 22:28:17 -05:00
capezotte
88147c78b3 s6-rc-db-update-hook: remove arrays and make posix 2021-07-17 22:28:08 -05:00
a88c0c6036 s6-rc-db-update-hook: make database update atomic
Technically, this has been wrong for a while (no bad side effects seem
to have been reported at least). The original version of this script did
do atomic updates but it got lost in a recent-ish rewrite. According to
skarnet documentation, the updated symlink to the newly compiled
database should be made atomically. The standard ln utilty does not do
that and actually forbids this. We could use s6-ln (it is packaged), but
artix is a GNU distro so it's better not to incur any additional
dependencies. The correct way to fix this is to simply use && mv -f as
per the skarnet documentation.
2021-07-17 20:16:24 -05:00
720d72ac7d s6-rc-db-update-hook: quote ${SVDIRS}
Shellcheck complained about this one and it should be okay to quote.
Note that we do want word splitting for $new_contents though so ignore
shellcheck there.
2021-07-17 20:14:43 -05:00
5 changed files with 63 additions and 61 deletions

View File

@@ -62,10 +62,10 @@ install_udev: install_common
install $(EMODE) $(UDEVSCRIPTS) $(DESTDIR)$(SCRIPTSDIR)
install $(MODE) $(UDEVHOOKS) $(DESTDIR)$(HOOKSDIR)
install_tmpfiles: install_common
install_tmpfiles: install_hook_common
install $(MODE) $(TMPFILESHOOKS) $(DESTDIR)$(HOOKSDIR)
install_sysusers: install_common
install_sysusers: install_hook_common
install $(MODE) $(SYSUSERSHOOKS) $(DESTDIR)$(HOOKSDIR)
install_openrc: install_common

View File

@@ -11,23 +11,23 @@ bundle_action() {
}
db_err_msg() {
echo "${CMD_UPD}: fatal: unable to take lock on ${DATABASE} Permission denied"
echo "${CMD_UPD}: fatal: unable to take lock on ${DATABASE}: Permission denied"
exit 1
}
bundle_err_msg() {
echo "${BUNDLE} is not an existing bundle. Create it with ${CMD}."
echo "'${BUNDLE}' is not an existing bundle. Create it with ${CMD}."
exit 1
}
bundle_entry_err_msg() {
name="$1"
echo "$name does not exist in bundle ${BUNDLE}!"
echo "'$name' does not exist in bundle '${BUNDLE}'!"
exit 1
}
bundle_add_err_msg() {
echo "Error when trying to add ${CONTENTS}!"
echo "Error when trying to add '${CONTENTS}'!"
}
cmd_help() {
@@ -154,6 +154,10 @@ for arg in "$@"; do
BUNDLE=$arg
continue
fi
if [ "${CONTENTS}" = "" ]; then
CONTENTS=$arg
continue
fi
CONTENTS="${CONTENTS} $arg"
done

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# {{{ functions
@@ -7,8 +7,8 @@ db_action() {
}
a_newbundle() {
for j in $new_bundles; do
if [ "$j" = "$1" ]; then
for i in $new_bundles; do
if [ "$i" = "$1" ]; then
return 0
fi
done
@@ -16,8 +16,8 @@ a_newbundle() {
}
service_exists() {
for k in $all_services; do
if [ "$k" = "$1" ]; then
for j in $all_services; do
if [ "$j" = "$1" ]; then
return 0
fi
done
@@ -26,8 +26,8 @@ service_exists() {
in_newbundle() {
bundle_contents=$(db_action contents "$1")
for l in $bundle_contents; do
if [ "$l" = "$2" ]; then
for k in $bundle_contents; do
if [ "$k" = "$2" ]; then
return 0
fi
done
@@ -42,26 +42,36 @@ in_newbundle() {
RCPATH='/etc/s6/rc'
DBPATH="${RCPATH}/compiled"
SVPATH='/etc/s6/sv'
ADMINSVPATH='/etc/s6/adminsv'
FALLBACKSVPATH='/etc/s6/fallbacksv'
SVDIRS='/run/s6-rc/servicedirs'
TIMESTAMP=$(date +%s)
if [ -e "${DBPATH}" ]; then
old_bundles="$(db_action list bundles)"
len=0
for bundle in $old_bundles; do
contents[$len]=$(db_action contents "$bundle")
len=$(( len + 1 ))
done
# Print contents of older bundles, using the format:
# <name1>
# <sv1> <sv2> <sv3> ... <svN>
# <name2>
# <sv1> ... <svN>
old_bundle_contents=$(
for bundle in $(db_action list bundles); do
printf '%s\n' "$bundle" "$(db_action contents "$bundle" | paste -sd" ")"
done
)
fi
if ! s6-rc-compile "${DBPATH}"-"${TIMESTAMP}" "${SVPATH}"; then
echo "Error compiling database."
echo "Please double check the ${SVPATH} directories. Exiting."
if ! s6-rc-compile "${DBPATH}"-"${TIMESTAMP}" "${SVPATH}" "${ADMINSVPATH}"; then
echo "Error compiling database. Trying the system fallback paths!"
echo "Please double check the ${ADMINSVPATH} directories."
if ! s6-rc-compile "${DBPATH}"-"${TIMESTAMP}" "${SVPATH}" "${FALLBACKSVPATH}"; then
echo "The system fallback compilation failed. Something is really wrong with your service directories!"
echo "Check your ${SVPATH} and ${FALLBACKSVPATH} directories."
fi
exit 1
fi
if [ -e "/run/s6-rc" ]; then
for dir in ${SVDIRS}/*; do
for dir in "${SVDIRS}"/*; do
if [ -e "${dir}/down" ]; then
s6-svc -x "${dir}"
fi
@@ -70,8 +80,7 @@ if [ -e "/run/s6-rc" ]; then
fi
if [ -d "${DBPATH}" ]; then
ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}"/compiled
mv -f "${DBPATH}"/compiled "${RCPATH}"
ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}"/compiled && mv -f "${DBPATH}"/compiled "${RCPATH}"
else
ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}"
fi
@@ -79,44 +88,33 @@ fi
new_bundles=$(db_action list bundles)
all_services=$(db_action list all)
while read -r l && read -r old_contents; do
CMD='s6-rc-bundle'
if [ -n "$old_bundles" ]; then
len=0
for m in $old_bundles; do
old_contents=${contents[$len]}
a_newbundle "$m"
ret=$?
a_newbundle "$l"
ret=$?
for n in $old_contents; do
service_exists "$n"
ret2=$?
if [ $ret -eq 1 ]; then
if [ $ret2 -eq 0 ]; then
new_contents="$new_contents $n"
fi
else
if [ $ret2 -eq 0 ]; then
in_newbundle "$m" "$n"
ret3=$?
if [ $ret3 -eq 1 ]; then
s6-rc-bundle-update -c "${DBPATH}" add "$m" "$n"
fi
fi
for m in $old_contents; do
# We should handle the service if it exists and either:
# [ $ret -eq 1 ] -> the bundle it is in not doesn't exist yet
# ! in_newbundle -> it's not in the bundle it used to be in
if service_exists "$m"; then
if [ $ret -eq 1 ] || ! in_newbundle "$l" "$m"; then
new_contents="$new_contents $m"
fi
done
if [ -n "$new_contents" ]; then
s6-rc-bundle -c "${DBPATH}" add "$m" $new_contents
fi
new_contents=""
len=$(( len + 1 ))
done
fi
# If bundle exists, we're only going to update it
[ $ret -eq 1 ] || CMD="$CMD-update"
# Add or update bundle
[ -z "$new_contents" ] || "$CMD" -c "${DBPATH}" add "$l" $new_contents
new_contents=''
done <<EOF
$old_bundle_contents
EOF
echo "==> Switched to a new database."
echo " Remove any old unwanted/unneeded database directories in ${RCPATH}."

View File

@@ -35,9 +35,10 @@ shutdown_service() {
if [ -d "$dir" ] && [ "$dir" != "etc/s6/sv/" ]; then
sv=$(basename "$dir")
active=$(s6-rc -a list | grep -Fx "$sv" || true)
if [ -n $active ]; then
s6-rc -d change "$sv"
if [ ! "$active" ]; then
continue
fi
s6-rc -d change "$sv"
fi
done
}

View File

@@ -10,7 +10,6 @@ udevd_live() {
op="$1"; shift
case "$op" in
#hwdb) /usr/bin/udev-hwdb --usr update ;;
hwdb) /usr/bin/udevadm hwdb --update ;;
udev-reload) udevd_live; /usr/bin/udevadm control --reload ;;
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;