-
-
Notifications
You must be signed in to change notification settings - Fork 105
Waiting for the user systemd
If your distribution (or your personal configuration) makes use of per-user systemd instances, or related functionality such as the systemd-logind linger feature, you may find the following code snippets useful to avoid errors should your dotfiles invoke functionality that is started by these, or should you wish to delay the first prompt until these have fully started.
This first snippet checks to make sure that it is being executed inside the bottle, and if so, waits until the user systemd has entered the running state before continuing:
# Are we in the bottle?
if [[ -v INSIDE_GENIE ]]; then
echo -n " * Waiting for systemd (user)..."
until systemctl --user is-system-running &>/dev/null
do
sleep 1
echo -n "."
done
echo
fi
It is also possible to wait for a particular service to have started, rather than waiting for the user systemd as a whole to have reached the running state. This snippet, for example, waits for the tmux server started by the user systemd to be running before attempting to attach the tmux client to it:
echo -n " * Waiting for tmux..."
until systemctl --user is-active tmux@1 &>/dev/null
do
sleep 1
echo -n "."
done
echo
if [[ -z "$TMUX" ]]; then
/usr/local/bin/tmux attach
exit