wmstartup: Add custom service definition, leverage subshells better

This commit is contained in:
Salt 2018-08-27 12:02:14 -05:00
parent c0b14dba2d
commit c4c2cfdcc9
2 changed files with 31 additions and 9 deletions

View File

@ -17,7 +17,7 @@ function svc_log() {
} }
function prestart() { function prestart() {
if pgrep $service_proccess > /dev/null 2>&1; then if pgrep $service_process > /dev/null 2>&1; then
svc_log "Already running" svc_log "Already running"
return 1 return 1
fi fi

View File

@ -23,6 +23,8 @@
## Clean up some variables ## Clean up some variables
# General # General
unset TERMINAL unset TERMINAL
# Specific to these dtfscripts
unset DTF_SERVICES
# Polybar # Polybar
unset PB_MONITOR unset PB_MONITOR
unset PB_WM_RESTACK unset PB_WM_RESTACK
@ -68,18 +70,38 @@ if [[ -x "$XDG_CONFIG_HOME/dtfscripts/devices/$(hostname).rc" ]]; then
source $HOME/.config/dtfscripts/devices/$(hostname).rc source $HOME/.config/dtfscripts/devices/$(hostname).rc
fi fi
## Determine which services to run
# If DTF_SERVICES is set, use that
# Otherwise, populate it with every service
if [[ "$DTF_SERVICES" == "" ]]; then
dtf_log "Starting all available services"
for service in $DTF_SEVICES_DIR/*.dtf; do
export DTF_SERVICES="$DTF_SERVICES $(basename $service)"
done
else
dtf_log "Starting a subset of available services"
fi
## Run startup scripts ## Run startup scripts
for service in $DTF_SERVICES_DIR/*.dtf; do for service in $DTF_SERVICES_DIR/*.dtf; do
service_full="$DTF_SERVICES_DIR/$service"
( (
source $service if ! [ -r $service ]; then
if ! prestart; then dtf_log "Service is unreadable or missing: $service"
svc_log "Failed pre-start checks" exit 1
else
if isup && [[ "$service_kill_on_reload" == "true" ]] ; then
stop
fi
start
fi fi
if ! [ -x $service ]; then
dtf_log "Service is unexecutable: $service"
exit 1
fi
source $service
if isup && [[ "$service_kill_on_reload" == "true" ]] ; then
stop
fi
if ! prestart; then
exit 1
fi
start
) )
done done