rudimentary cgroup support

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-01-08 08:07:18 +03:00
parent 2d748aebc9
commit f191b625dc

35
ssm
View File

@ -88,6 +88,12 @@ svc() {
declare job_pid
var job_pid
# Cgroups
if cgroups; then
mkdir -p "$cgroup_home/$service_name"
echo "$BASHPID" > "$cgroup_home/$service_name/cgroup.procs"
fi
svc::cleanup() {
nullexec kill -n "$service_stop_signal" "$job_pid"
@ -421,6 +427,7 @@ var service_pid \
service_ready_flag \
service_enabled_flag \
service_stopped_flag \
cgroup_home \
failed_deps \
svc_pidfile \
cfg_path \
@ -450,10 +457,11 @@ var service_stop_signal = 15
var service_reload_signal = 1
var service_signals = 1 10 12
var service_nologs = 0
var usrdir = '/usr/share/ssm'
var systemd = 0
var systemd_service_path = /etc/systemd/system /run/systemd/system /lib/systemd/system
var ssm_config = 0
var usrdir = '/usr/share/ssm'
var cgroups = 0
## Figure out our full path
case "$0" in
@ -461,14 +469,6 @@ case "$0" in
(*) _self = "$PWD/$0";;
esac
if (( $UID )); then
rundir = "$XDG_RUNTIME_DIR/ssm"
logdir = "$HOME/log/ssm"
else
rundir = '/run/ssm'
logdir = '/var/log/ssm'
fi
# Warn the user of deprecated stuff.
for p in "/etc/ssm/init.d" "$XDG_CONFIG_HOME/ssm/init.d"; do
if [[ -d "$p" ]]; then
@ -477,9 +477,6 @@ for p in "/etc/ssm/init.d" "$XDG_CONFIG_HOME/ssm/init.d"; do
fi
done
# Common service path
service_path += "$XDG_CONFIG_HOME/ssm/services" '/etc/ssm/services' "$rundir/services" "$usrdir/services"
# Common config path
cfg_path = "$XDG_CONFIG_HOME/ssm" '/etc/ssm'
@ -499,11 +496,25 @@ for (( idx=${#cfg_path[@]}-1; idx>=0; idx-- )); do
done
done
# These depend on who we are
if (( $UID )); then
rundir := "$XDG_RUNTIME_DIR/ssm"
logdir := "$HOME/log/ssm"
cgroup_home := "/sys/fs/cgroup/user/$UID/my/ssm"
else
rundir := '/run/ssm'
logdir := '/var/log/ssm'
cgroup_home := "/sys/fs/cgroup/ssm"
fi
# Now create the needed runtime stuff
for d in "$rundir" "$logdir"; do
mkdir -p "$d" || die 3 "Failed to create runtime dir: $d"
done
# Common service path
service_path += "$XDG_CONFIG_HOME/ssm/services" '/etc/ssm/services' "$rundir/services" "$usrdir/services"
# If $1 is a full path, source it.
# If not, search for it in the service path.
if [[ $1 == /* ]]; then