2018-08-26 16:11:25 -05:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
#
|
|
|
|
# wmstartup service common functions
|
|
|
|
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
#
|
|
|
|
|
|
|
|
service_name="unnamed_service"
|
|
|
|
service_process="true"
|
2018-08-27 11:51:06 -05:00
|
|
|
service_kill_on_reload="true"
|
|
|
|
service_flags=""
|
2018-08-26 16:11:25 -05:00
|
|
|
|
|
|
|
function svc_log() {
|
|
|
|
if [ -z ${1+x} ]; then return 1; fi
|
|
|
|
dtf_log "$service_name: $1"
|
|
|
|
}
|
|
|
|
|
|
|
|
function prestart() {
|
2018-08-27 12:02:14 -05:00
|
|
|
if pgrep $service_process > /dev/null 2>&1; then
|
2018-08-27 11:51:06 -05:00
|
|
|
svc_log "Already running"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-08-26 16:11:25 -05:00
|
|
|
if ! which $service_process > /dev/null 2>&1; then
|
|
|
|
svc_log "Could not find process"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-08-27 11:51:06 -05:00
|
|
|
if ! prestart-extra; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function prestart-extra() {
|
2018-08-26 16:11:25 -05:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function start() {
|
|
|
|
svc_log "Starting"
|
2018-08-27 11:51:06 -05:00
|
|
|
$service_process $service_flags > /dev/null 2>&1 &
|
2018-08-26 16:11:25 -05:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function stop() {
|
|
|
|
svc_log "Stopping"
|
|
|
|
killall $service_process &
|
|
|
|
for i in {1..100}; do
|
|
|
|
if ! isup; then break; fi
|
|
|
|
sleep 0.01
|
|
|
|
if (( $i > 99 )); then
|
|
|
|
svc_log "Stopping with prejudice"
|
|
|
|
killall -9 $service_process
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function isup() {
|
|
|
|
pgrep "$service_process" > /dev/null 2>&1
|
2018-08-27 11:51:06 -05:00
|
|
|
isup-extra $?
|
2018-08-26 16:11:25 -05:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2018-08-27 11:51:06 -05:00
|
|
|
function isup-extra() {
|
|
|
|
return $1
|
|
|
|
}
|
|
|
|
|