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