some new stuff
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
532f7b0d09
commit
d5c0a30b96
14
ssm
14
ssm
|
@ -349,6 +349,8 @@ main() {
|
||||||
logdir='/var/log/ssm'
|
logdir='/var/log/ssm'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
service_path+=( "$cfgdir/init.d" "$rundir/services" )
|
||||||
|
|
||||||
# Load custom functions
|
# Load custom functions
|
||||||
for f in "$cfgdir/functions"/*; do
|
for f in "$cfgdir/functions"/*; do
|
||||||
source "$f" || die 9 "Failed to source functions from $f"
|
source "$f" || die 9 "Failed to source functions from $f"
|
||||||
|
@ -360,15 +362,17 @@ main() {
|
||||||
done
|
done
|
||||||
|
|
||||||
# If $1 is a full path, source it.
|
# If $1 is a full path, source it.
|
||||||
# If not, search for it in the service dir.
|
# If not, search for it in the service path.
|
||||||
if [[ $1 == /* ]]; then
|
if [[ $1 == /* ]]; then
|
||||||
service_config=$1
|
service_config=$1
|
||||||
else
|
else
|
||||||
service_config="$cfgdir/init.d/$1"
|
for i in "${service_path[@]}"; do
|
||||||
|
[[ -f "$i/$1" ]] && service_config="$i/$1"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Die if there is no such file
|
# Die if there is no such file
|
||||||
[[ -f "$service_config" ]] || die "No such file: $service_config"
|
[[ "$service_config" ]] || die 19 "Service not found: $1"
|
||||||
|
|
||||||
# Service name is the basename
|
# Service name is the basename
|
||||||
service_name="${1##*/}"
|
service_name="${1##*/}"
|
||||||
|
@ -387,7 +391,9 @@ main() {
|
||||||
# Legacy
|
# Legacy
|
||||||
[[ "$service_args" ]] && service_command=( "${service_command[@]}" "${service_args[@]}" )
|
[[ "$service_args" ]] && service_command=( "${service_command[@]}" "${service_args[@]}" )
|
||||||
[[ "$service_respawn" == 'true' ]] && service_respawn=1
|
[[ "$service_respawn" == 'true' ]] && service_respawn=1
|
||||||
[[ "$service_type" == 'oneshot' ]] && { service_oneshot=1; service_managed=0; }
|
[[ "$service_type" == 'oneshot' ]] && service_oneshot=1
|
||||||
|
|
||||||
|
(( service_oneshot )) && service_managed=0
|
||||||
|
|
||||||
[[ "$service_pidfile" ]] && service_managed=0
|
[[ "$service_pidfile" ]] && service_managed=0
|
||||||
|
|
||||||
|
|
50
ssm-gen
Executable file
50
ssm-gen
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
err() { printf '%s\n' "$*" >&2; }
|
||||||
|
|
||||||
|
workdir="/run/user/$UID/ssm/services"
|
||||||
|
|
||||||
|
[[ -d "$workdir" ]] || {
|
||||||
|
mkdir -p "$workdir" || exit 7
|
||||||
|
}
|
||||||
|
|
||||||
|
while (( $# )); do
|
||||||
|
case "$1" in
|
||||||
|
-o|--oneshot) flag_oneshot=1;;
|
||||||
|
-e|--edit) flag_edit=1;;
|
||||||
|
-s|--start) flag_start=1;;
|
||||||
|
|
||||||
|
-n|--name) service_name=$2; shift;;
|
||||||
|
-w|--workdir) workdir=$2; shift;;
|
||||||
|
|
||||||
|
--) shift; break;;
|
||||||
|
*) break;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ "$1" ]] || {
|
||||||
|
err "Need at least one argument!"
|
||||||
|
exit 5
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd=$1; shift
|
||||||
|
|
||||||
|
[[ "$service_name" ]] || service_name=$cmd
|
||||||
|
[[ "$cmd" == '/'* ]] || cmd=$(which "$cmd")
|
||||||
|
|
||||||
|
args=$@
|
||||||
|
|
||||||
|
{
|
||||||
|
printf '#!/usr/bin/env ssm\n\n'
|
||||||
|
|
||||||
|
(( flag_oneshot )) && printf 'service_oneshot=1\n'
|
||||||
|
|
||||||
|
printf 'service_command="%s"\n' "$cmd"
|
||||||
|
|
||||||
|
[[ "$args" ]] && printf 'service_args=( %s )\n' "${service_args[*]}"
|
||||||
|
} > "$workdir/$service_name"
|
||||||
|
|
||||||
|
(( edit )) && "$EDITOR" "$workdir/$service_name" || exit 3
|
||||||
|
|
||||||
|
(( flag_start )) && ssm "$workdir/$service_name" start
|
Loading…
Reference in New Issue
Block a user