mirror of
https://github.com/frebib/dotfiles.git
synced 2024-06-14 12:57:23 +00:00
Joe Groocock
839d972e95
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>
28 lines
585 B
Bash
Executable File
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[@]}" -- "$@"
|