wmstartup: Annotate service functions, move more logic to main script

This commit is contained in:
Salt 2018-08-27 13:09:40 -05:00
parent df605a74b2
commit e344caec74
3 changed files with 28 additions and 6 deletions

View File

@ -11,11 +11,13 @@ service_process="true"
service_kill_on_reload="true" service_kill_on_reload="true"
service_flags="" service_flags=""
# Basic logging service. Do not override unless necessary
function svc_log() { function svc_log() {
if [ -z ${1+x} ]; then return 1; fi if [ -z ${1+x} ]; then return 1; fi
dtf_log "$service_name: $1" dtf_log "$service_name: $1"
} }
# Basic pre-start checks. Stick extra checks in prestart-extra
function prestart() { function prestart() {
if pgrep $service_process > /dev/null 2>&1; then if pgrep $service_process > /dev/null 2>&1; then
svc_log "Already running" svc_log "Already running"
@ -25,22 +27,28 @@ function prestart() {
svc_log "Could not find process" svc_log "Could not find process"
return 1 return 1
fi fi
if ! prestart-extra; then
return 1
fi
return 0 return 0
} }
# Template function. If it fails, the service will not be started
function prestart-extra() { function prestart-extra() {
return 0 return 0
} }
# Basic start function. Override if you have special startup functionality
function start() { function start() {
svc_log "Starting" svc_log "Starting"
$service_process $service_flags > /dev/null 2>&1 & $service_process $service_flags > /dev/null 2>&1 &
return 0 return 0
} }
# Template function. Override for post-startup tasks
# Can also be used for blocking
function start-extra() {
return 0
}
# Basic stop function. Kills the task and implements a SIGKILL timer
function stop() { function stop() {
svc_log "Stopping" svc_log "Stopping"
killall $service_process & killall $service_process &
@ -55,12 +63,14 @@ function stop() {
return $? return $?
} }
# Basic process detection function. Returns 0 if the process exists.
function isup() { function isup() {
pgrep "$service_process" > /dev/null 2>&1 pgrep "$service_process" > /dev/null 2>&1
isup-extra $? isup-extra $?
return $? return $?
} }
# Template function. Gets passed the result of a simple pgrep for the process
function isup-extra() { function isup-extra() {
return $1 return $1
} }

View File

@ -17,3 +17,15 @@ function start() {
return 0 return 0
} }
function start-extra() {
for i in {1..100}; do
if xprop -name "Conky" > /dev/null 2>&1; then break; fi
sleep 0.01
if (( $i > 99 )); then
svc_log "Conky may spawn behind the current desktop"
break
fi
done
return 0
}

View File

@ -100,10 +100,10 @@ for service in $DTF_SERVICES; do
if isup && [[ "$service_kill_on_reload" == "true" ]] ; then if isup && [[ "$service_kill_on_reload" == "true" ]] ; then
stop stop
fi fi
if ! prestart; then if ! prestart; then exit 1; fi
exit 1 if ! prestart-extra; then exit 1; fi
fi
start start
start-extra
) )
done done