-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow checking/depending on system services from user init script #770
Comments
i've considered this, but it's an issue because user scripts can't start system services, so all we achieve from this is stopping the service from starting all together, which isn't really useful implementing this would also involve a lot of internal refactoring, so if we decide it's necessary, i'd like to do so in a release after user-script proper |
You're right in hindsight that a full implementation of It could be implemented in a single interface: wait for service to start for a specified timeout (in |
#777 introduces a it might be prudent to add |
That's a solution. It would be nice to have the user be able to specify in their scripts what services they want to start after, but simply waiting until the system is fully up is fine too. I actually took a similar approach to that by adding this script to #!/bin/sh
# run OpenRC user mode for all users
getent passwd | while read -r x; do
dir=$(printf %s "$x" | cut -d: -f6)
rc="$dir/.config/rc"
# start up OpenRC if special file or rc conf dir is present
# the file is required if your rc conf dir isn't at the default location
# TODO: handle this check in the user's shell? if they set XDG_CONFIG_HOME
[ -d "$rc" -o -e "$dir/.start_user_rc" ] || continue
# check for valid shell
shell=$(printf %s "$x" | cut -d: -f7)
getent shells "$shell" >/dev/null ||
getent shells $(readlink "$shell") >/dev/null ||
continue
# mimic alpine/busybox inittab for OpenRC user mode
# see also: https://github.com/OpenRC/openrc/blob/master/etc/rc.in
# XXX: assuming posix-compatible shell
sudo -niu "$(printf %s "$x" | cut -d: -f1)" "$shell" <<EOF
: \${HOME:=$dir}
export HOME
: \${XDG_RUNTIME_DIR:=~/.local/run}
export XDG_RUNTIME_DIR
[ ! -e "\$XDG_RUNTIME_DIR" ] && /bin/mkdir -p "\$XDG_RUNTIME_DIR"
/sbin/openrc -U sysinit || exit 1
/sbin/openrc -U boot || exit 1
/sbin/openrc -U default
EOF
done
# vim: sts=4 sw=4 et |
that works
#777 addresses this by starting a helper script with on your script, just be careful about running openrc manually from a logged in session, as |
With the merge of user-mode OpenRC, one thing that becomes evident is that there is no built-in way to check system state from within a user init script. So, for example, there's no way to depend on
net
, since it and everything it interacts with exists entirely outside of the current OpenRC process and environment.At least, I haven't seen a way to do it. But I also haven't looked too hard, so if this already exists, I apologize.
I imagine this would be possible to implement manually, by changing/clearing the relevant env vars and running the needed OpenRC commands yourself—but it would be nice if there was a native way to do it.
Maybe this could be implemented with user-mode only
depends
verbs likeneeds_system
? This would be the most cross-platform but would mean new functions. Could also approach it with prefixes or something, likeneeds system.net
, but this could cause conflict if a service with that prefix already exists.The text was updated successfully, but these errors were encountered: