early edit; list known
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
52f3117d3f
commit
611349e243
61
ssm
61
ssm
|
@ -529,7 +529,7 @@ logs() {
|
||||||
## Status is a bit of a special case. It's talkative.
|
## Status is a bit of a special case. It's talkative.
|
||||||
status() {
|
status() {
|
||||||
service_running && return 0
|
service_running && return 0
|
||||||
service_enabled && return 0
|
service_enabled && return 2
|
||||||
service_stopped && return 7
|
service_stopped && return 7
|
||||||
service_failed && return 9
|
service_failed && return 9
|
||||||
service_exit_last is empty || return 11
|
service_exit_last is empty || return 11
|
||||||
|
@ -577,6 +577,10 @@ var service_pid \
|
||||||
logdir \
|
logdir \
|
||||||
_self
|
_self
|
||||||
|
|
||||||
|
## Internal defaults
|
||||||
|
var flag_list_services = 0
|
||||||
|
var flag_edit_service = 0
|
||||||
|
|
||||||
## check for some environment stuff
|
## check for some environment stuff
|
||||||
var EDITOR := 'vim'
|
var EDITOR := 'vim'
|
||||||
var PAGER := 'less'
|
var PAGER := 'less'
|
||||||
|
@ -664,7 +668,15 @@ done
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
while (( $# )); do
|
while (( $# )); do
|
||||||
case $1 in
|
case $1 in
|
||||||
(-h|--help) usage; exit 0;;
|
(-h|--help) # Show help
|
||||||
|
usage; exit 0;;
|
||||||
|
|
||||||
|
(-L|--list-services) # List all services
|
||||||
|
flag_list_services = 1;;
|
||||||
|
|
||||||
|
(-e|--edit-service) # Edit the service file.
|
||||||
|
flag_edit_service = 1;;
|
||||||
|
|
||||||
(--) shift; break;;
|
(--) shift; break;;
|
||||||
(-*) printf 'Unknown key: %s\n' "$1" >&2; exit 1;;
|
(-*) printf 'Unknown key: %s\n' "$1" >&2; exit 1;;
|
||||||
(*) break;;
|
(*) break;;
|
||||||
|
@ -681,8 +693,26 @@ done
|
||||||
# Common service path
|
# Common service path
|
||||||
service_path += "$XDG_CONFIG_HOME/ssm/services" '/etc/ssm/services' "$rundir/services" "$usrdir/services"
|
service_path += "$XDG_CONFIG_HOME/ssm/services" '/etc/ssm/services' "$rundir/services" "$usrdir/services"
|
||||||
|
|
||||||
# This script requires at least two aruments
|
# Special actions
|
||||||
(( $# >= 2 )) || { usage; exit 2; }
|
if flag_list_services; then
|
||||||
|
var known_services
|
||||||
|
for i in "$rundir"/*.{pid,exit,stopped,enabled}; do
|
||||||
|
i_fname="${i##*/}"
|
||||||
|
i_sname="${i_fname%.*}"
|
||||||
|
|
||||||
|
known_services u "$i_sname" || known_services += "$i_sname"
|
||||||
|
done
|
||||||
|
|
||||||
|
for s in "${known_services[@]}"; do
|
||||||
|
printf '%s: ' "$s"
|
||||||
|
ssm "$s" status
|
||||||
|
done
|
||||||
|
|
||||||
|
die 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# This script requires at least one argument
|
||||||
|
(( $# >= 1 )) || { usage; exit 2; }
|
||||||
|
|
||||||
# If $1 is a full path, source it.
|
# If $1 is a full path, source it.
|
||||||
# If not, search for it in the service path.
|
# If not, search for it in the service path.
|
||||||
|
@ -700,6 +730,11 @@ fi
|
||||||
# Die if there is no service config file
|
# Die if there is no service config file
|
||||||
service_config || die 19 "Service not found: $1"
|
service_config || die 19 "Service not found: $1"
|
||||||
|
|
||||||
|
# Edit the service config
|
||||||
|
flag_edit_service && {
|
||||||
|
edit; die $?
|
||||||
|
}
|
||||||
|
|
||||||
# Service name is the basename
|
# Service name is the basename
|
||||||
service_name = "${1##*/}"
|
service_name = "${1##*/}"
|
||||||
|
|
||||||
|
@ -713,6 +748,12 @@ done
|
||||||
# Get the service config
|
# Get the service config
|
||||||
source -- "$service_config" "${@:3}" || die 7 "Failed to read the service config: $service_config"
|
source -- "$service_config" "${@:3}" || die 7 "Failed to read the service config: $service_config"
|
||||||
|
|
||||||
|
# Legacy
|
||||||
|
service_args && service_command += "${service_args[@]}"
|
||||||
|
service_type == 'oneshot' && service_oneshot = 1
|
||||||
|
service_respawn == 1 && service_respawn = always
|
||||||
|
|
||||||
|
# Set respawn flag
|
||||||
if ! service_respawn == 'no'; then
|
if ! service_respawn == 'no'; then
|
||||||
case $service_respawn in
|
case $service_respawn in
|
||||||
(on-failure|on-success|always) service_respawn_flag = 1;;
|
(on-failure|on-success|always) service_respawn_flag = 1;;
|
||||||
|
@ -720,10 +761,7 @@ if ! service_respawn == 'no'; then
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Legacy
|
# Unset the managed flag on services with their own pidfile
|
||||||
service_args && service_command += "${service_args[@]}"
|
|
||||||
service_type == 'oneshot' && service_oneshot = 1
|
|
||||||
|
|
||||||
service_pidfile && service_managed = 0
|
service_pidfile && service_managed = 0
|
||||||
|
|
||||||
# Semi-hardcoded stuff
|
# Semi-hardcoded stuff
|
||||||
|
@ -835,18 +873,13 @@ case "$2" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
status)
|
status)
|
||||||
if service_oneshot; then
|
|
||||||
result "$res" \
|
|
||||||
0 "$service_name is enabled" \
|
|
||||||
1 "$service_name is not enabled"
|
|
||||||
else
|
|
||||||
result "$res" \
|
result "$res" \
|
||||||
0 "$service_name is running" \
|
0 "$service_name is running" \
|
||||||
|
2 "$service_name was successful" \
|
||||||
1 "$service_name is not running" \
|
1 "$service_name is not running" \
|
||||||
7 "$service_name was stopped" \
|
7 "$service_name was stopped" \
|
||||||
9 "$service_name has failed with code: $service_exit_last" \
|
9 "$service_name has failed with code: $service_exit_last" \
|
||||||
11 "$service_name has exited with code: $service_exit_last"
|
11 "$service_name has exited with code: $service_exit_last"
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user