Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-03-09 06:57:26 +03:00
parent 2aff1db42b
commit 924324aa10
1 changed files with 47 additions and 37 deletions

84
ssm
View File

@ -494,22 +494,15 @@ stop() {
info() {
declare -a _info_items
declare _status_code _status
var _info_items _status_code _status
declare _status_code _status _show_pid
var _info_items _status_code _status _show_pid
_info_items = 'Name' "$service_name"
if service_oneshot; then
_info_items += 'Oneshot' 'yes'
fi
info::item() { printf "%16s: %s\n" "$1" "$2"; }
status; _status_code = "$?"
case $_status_code in
(0)
_status = 'running'
_info_items += 'PID' "$service_pid"
_info_items += 'PIDFile' "$service_pidfile"
;;
(0) _status = 'running';;
(1) _status = 'down';;
(2) _status = 'success';;
(7) _status = 'stopped';;
(9) _status = "failed: $service_exit_last";;
@ -517,26 +510,35 @@ info() {
(*) _status = 'unknown';;
esac
_info_items += 'Status' "$_status"
info::item Name "$service_name"
_info_items += \
"Exec" "${service_command[*]}" \
"Respawn" "$service_respawn" \
"Config path" "$service_config" \
# Logs
_info_items += 'Output log' "$service_logfile_out"
service_logfile_out == "$service_logfile_err" || \
_info_items += "Error log" "$service_logfile_err"
# Show the cgroup
if cgroups; then
_info_items += "Cgroup" "$cgroup_home/$service_cgroup_name" \
"Cgroup procs" "${#service_cgroup_procs[@]}"
if service_oneshot; then
info::item Oneshot 'yes'
else
info::item Restart "$service_respawn"
fi
printf "%16s: %s\n" "${_info_items[@]}"
info::item Status "$_status"
info::item Exec "${service_command[*]}"
info::item Config "$service_config"
info::item Workdir "$service_workdir"
info::item 'Output log' "$service_logfile_out"
service_logfile_out == "$service_logfile_err" || \
info::item 'Error log' "$service_logfile_err"
if service_running; then
info::item PID "$service_pid"
info::item PIDFile "$service_pidfile"
cgroups && {
info::item Cgroup "$cgroup_home/$service_cgroup_name"
info::item 'Cgroup procs' "${#service_cgroup_procs[@]}"
}
fi
return 0
}
## Restart just calls the script twice by default
@ -620,6 +622,7 @@ var flag_edit_service = 0
var flag_reset_exit = 0
var flag_reread_service = 0
var flag_forget_service = 0
var flag_load_service = 0
## check for some environment stuff
var EDITOR := 'vim'
@ -723,9 +726,15 @@ while (( $# )); do
(-r|--reread) # Reload the service file.
flag_reread_service = 1;;
(-u|--forget) # Unload a service.
(-f|--forget) # Unload a service.
flag_forget_service = 1;;
(-l|--load) # Load a service.
flag_load_service = 1;;
(-i|--info)
action = 'info';;
(--) shift; break;;
(-*) printf 'Unknown key: %s\n' "$1" >&2; exit 1;;
(*) break;;
@ -771,9 +780,9 @@ if flag_reread_service; then
fi
# Find the service
if [[ $1 == /* ]]; then
service_config = "$1"
service_name = "${service_config##*/}"
if [[ $service_name == /* ]]; then
service_config = "$service_name"
service_name = "${service_name##*/}"
else
for i in "$service_config_current" "${service_path[@]/%//$service_name}"; do
[[ -f "$i" ]] && {
@ -797,7 +806,7 @@ if flag_forget_service; then
fi
# Die if there is no service config file
service_config || die 19 "Service not found: $1"
service_config || die 19 "Service not found: $service_name"
# Edit the service config
flag_edit_service && { edit; die $?; }
@ -828,6 +837,9 @@ service_config == "$service_config_current" || {
printf 'Loaded %s from: %s\n' "$service_name" "$service_config" >&2
}
# Die if we only needed to load a service
flag_load_service && die 0
# Legacy
service_args && service_command += "${service_args[@]}"
service_type == 'oneshot' && service_oneshot = 1
@ -925,11 +937,9 @@ if cgroups; then
fi
fi
# Were we given something to do?
(( $# )) || { usage; die 2; }
# Action!
action = "$1"
[[ "$1" ]] && action = "$1"
action || { usage; die 2; }
# Do we have such a function?
if_service_action "$action" || die 17 "Function $action is not defined for $service_name."