reset-exit fix

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-03-05 04:28:35 +03:00
parent 611349e243
commit 29bc62f208
2 changed files with 53 additions and 11 deletions

View File

@ -6,4 +6,39 @@ Yet another service manager.
Services Services
-------- --------
A service is a script in the ssm's init.d directory. A service is a script in the ssm's init.d directory.
By default it's /etc/ssm/init.d for system services and $XDG_CONFIG_HOME/ssm/init.d for user ones. By default it's /etc/ssm/services for system services and $XDG_CONFIG_HOME/ssm/services for user ones.
## Global settings
* cgroups
* usrdir
* service_path
* cfg_path
## Service config
Mandatory options:
* service_command
Optional settings (incomplete list):
* service_respawn
* service_workdir
* service_pidfile
* service_pidfile_timeout
* service_pidfile_remove_stale
* service_logfile_out
* service_logfile_err
* service_stop_timeout
* service_ready_timeout
* service_stop_signal
* service_reload_signal
* service_cgroup_exclusive
* service_cgroup_wait
* service_cgroup_strict
* service_cgroup_kill
* service_cgroup_kill_signal
* service_cgroup_cleanup
* service_success_exit
* service_oneshot

27
ssm
View File

@ -544,7 +544,7 @@ qstatus() { nullexec status; }
ready() { :; } ready() { :; }
## Reset failes ## Reset failes
reset-failed() { rm -f "$service_exit_file"; } reset-exit() { rm -f "$service_exit_file"; }
# Main code # Main code
## Empty declarations ## Empty declarations
@ -580,6 +580,7 @@ var service_pid \
## Internal defaults ## Internal defaults
var flag_list_services = 0 var flag_list_services = 0
var flag_edit_service = 0 var flag_edit_service = 0
var flag_reset_exit = 0
## check for some environment stuff ## check for some environment stuff
var EDITOR := 'vim' var EDITOR := 'vim'
@ -674,6 +675,9 @@ while (( $# )); do
(-L|--list-services) # List all services (-L|--list-services) # List all services
flag_list_services = 1;; flag_list_services = 1;;
(--reset-exit) # Reset last exit status
flag_reset_exit = 1;;
(-e|--edit-service) # Edit the service file. (-e|--edit-service) # Edit the service file.
flag_edit_service = 1;; flag_edit_service = 1;;
@ -731,13 +735,19 @@ fi
service_config || die 19 "Service not found: $1" service_config || die 19 "Service not found: $1"
# Edit the service config # Edit the service config
flag_edit_service && { flag_edit_service && { edit; die $?; }
edit; die $?
}
# Service name is the basename # Service name is the basename
service_name = "${1##*/}" service_name = "${1##*/}"
# These depend on the service_name and make little sense to reconfigure.
service_ready_flag := "$rundir/$service_name.ready"
service_enabled_flag := "$rundir/$service_name.enabled"
service_stopped_flag := "$rundir/$service_name.stopped"
service_exit_file := "$rundir/$service_name.exit"
service_cgroup_name := "$service_name"
service_cgroup_path := "$cgroup_home/$service_name"
# Get the service defaults # Get the service defaults
for p in "${cfg_path[@]/%//$service_name}"; do for p in "${cfg_path[@]/%//$service_name}"; do
[[ -f "$p" ]] && { [[ -f "$p" ]] && {
@ -745,6 +755,9 @@ for p in "${cfg_path[@]/%//$service_name}"; do
} }
done done
# Reset the exit status
flag_reset_exit && { reset-exit; die $?; }
# 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"
@ -771,12 +784,6 @@ svc_pidfile = "$rundir/$service_name.pid"
service_pidfile := "$svc_pidfile" service_pidfile := "$svc_pidfile"
service_logfile_out := "$logdir/${service_name}.log" service_logfile_out := "$logdir/${service_name}.log"
service_logfile_err := "$service_logfile_out" service_logfile_err := "$service_logfile_out"
service_ready_flag := "$rundir/$service_name.ready"
service_enabled_flag := "$rundir/$service_name.enabled"
service_stopped_flag := "$rundir/$service_name.stopped"
service_exit_file := "$rundir/$service_name.exit"
service_cgroup_name := "$service_name"
service_cgroup_path := "$cgroup_home/$service_name"
service_success_exit := 0 service_success_exit := 0
# A shortcut for disabling logging # A shortcut for disabling logging