runit-user-services/new-service
2024-02-29 11:56:00 +01:00

27 lines
652 B
Bash
Executable file

#!/bin/zsh
zparseopts -D l=logs -log=logs -enable-log=logs i:=importenv -import-env:=importenv h=help -help=help
if [[ -z $1 || $help ]]; then
echo "Usage: $0 [-l|--logs] [-i|--import-env=process] service [parameters]"
exit 1
fi
mkdir $1
ln -s ${XDG_RUNTIME_DIR:-/run/user/$UID}/supervise.$1 $1/supervise
{
echo '#!/bin/zsh'
if [[ $importenv ]]; then
echo 'source ${0:a:h:h}/import-env.zsh'
echo "import-env ${importenv[2]} || exit 1"
fi
echo 'exec 2>&1'
echo "exec $*"
} > $1/run
chmod +x $1/run
if [[ $logs ]]; then
mkdir $1/log
ln -sr ./log $1/log/run
ln -s ${XDG_RUNTIME_DIR:-/run/user/$UID}/supervise.${1}-log $1/log/supervise
fi