1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00
dotfiles/scripts/systemd-run-i3
Joe Groocock 839d972e95
systemd-run-i3: Add ExitType=cgroup to user units
systemd v250 added ExitType= which allows systemd to wait for all
processes in the cgroup to exit before terminating the unit, instead of
only the main pid. This has many uses, but for desktop applications in
particular it allows self-restarting (forking) applications to correctly
fork/restart and other background processes that may have been spawned
to continue when their forked parent inevitably exits first (like ssh
processes inside terminals).

Signed-off-by: Joe Groocock <me@frebib.net>
2022-03-21 21:46:28 +00:00

28 lines
585 B
Bash
Executable File

#!/bin/bash -e
slice=app
rand=$(tr -dc 'a-f0-9' < /dev/urandom | head -c 8)
args=()
while getopts "s:e:d:cnw" opt
do case "$opt" in
s) slice="$OPTARG";;
e) args+=("--setenv=$OPTARG");;
d) args+=("--working-directory=$OPTARG");;
c) args+=("--scope");;
n) args+=("--no-block");;
w) args+=("--wait");;
*) shift;;
esac
done
shift $((OPTIND-1))
exec systemd-run \
--user \
--collect \
--slice="$slice" \
--unit="$slice-$1-$rand" \
--property=BindsTo=graphical-session.target \
--property=ExitType=cgroup \
"${args[@]}" -- "$@"