diff --git a/ssm b/ssm index 91ba31c..03a385f 100755 --- a/ssm +++ b/ssm @@ -23,6 +23,8 @@ var() { ('==') mode=compare;; ('=~') mode=regex;; + ('is') mode=\"is_\$2\";; + ('u') mode=includes;; (*) die 71 \"Syntax error in \$FUNCNAME!\";; @@ -55,6 +57,12 @@ var() { return 1 ;; + + (is_fs_object) [[ -e \"\$_var\" ]];; + (is_file) [[ -f \"\$_var\" ]];; + (is_dir|is_directory) [[ -d \"\$_var\" ]];; + + (*) die 71 \"Syntax error in \$FUNCNAME!\";; esac }; readonly -f \"${varname}\" @@ -195,7 +203,7 @@ timer() { }; readonly -f timer ## Is a service ready? -is_ready() [[ -f "$service_ready_flag" ]] +is_ready() { service_ready_flag is file; } readonly -f is_ready ## Wait for this service to get ready @@ -301,8 +309,7 @@ read_systemd_service() { ## Start the service, write down the svc pid start() { service_running && return 3 - - [[ -f "${service_command[0]}" ]] || return 9 + service_command is file || return 9 if cgroups; then if service_cgroup_exclusive; then @@ -470,6 +477,7 @@ var service_pid \ service_stopped_flag \ service_cgroup_name \ service_cgroup_procs \ + service_cgroup_path \ cgroup_home \ failed_deps \ svc_pidfile \ @@ -514,6 +522,7 @@ var service_stopped = 0 var service_systemd = 0 var service_nologs = 0 var service_cgroup_empty = 1 +var service_cgroup_empty = 1 # These depend on who we are if (( $UID )); then @@ -543,7 +552,7 @@ for p in "/etc/ssm/init.d" "$XDG_CONFIG_HOME/ssm/init.d"; do done # Source the config -if [[ -f "$cfg_file" ]]; then +if cfg_file is file; then source "$cfg_file" || die 37 "Failed to load config: $cfg_file" fi @@ -641,6 +650,7 @@ service_ready_flag := "$rundir/$service_name.ready" service_enabled_flag := "$rundir/$service_name.enabled" service_stopped_flag := "$rundir/$service_name.stopped" service_cgroup_name := "$service_name" +service_cgroup_path := "$cgroup_home/$service_name" # A shortcut for disabling logging if service_nologs; then @@ -649,7 +659,7 @@ if service_nologs; then fi # Let's see if there's a PID -if [[ -f "$service_pidfile" ]]; then +if service_pidfile is file; then read -r service_pid < "$service_pidfile" # Let's see if it's running @@ -659,20 +669,20 @@ if [[ -f "$service_pidfile" ]]; then fi # Maybe the service is enabled? -if [[ -f "$service_enabled_flag" ]]; then +if service_enabled_flag is file; then # Yay, it is! service_enabled = 1 fi # Let's see if the service was deliberately stopped -if [[ -f "$service_stopped_flag" ]]; then +if service_stopped_flag is file; then # Ooh, it was. service_stopped = 1 fi # Check cgroups, if enabled if cgroups; then - if [[ -d "$cgroup_home/$service_cgroup_name" ]]; then + if service_cgroup_path is dir; then while read -r line; do service_cgroup_procs += "$line" done < "$cgroup_home/$service_cgroup_name/cgroup.procs"