From: Michael Wagner Date: Mon, 17 Dec 2018 17:28:08 +0000 (+0100) Subject: posaune X-Git-Tag: sysd2sysv_0.2-2~5 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=028d1826361a6a14b7363f03285ba5ab3dad4ea5;p=projects.git posaune --- diff --git a/etc/sysd2sysv.tpl b/etc/sysd2sysv.tpl new file mode 100644 index 0000000..8e61839 --- /dev/null +++ b/etc/sysd2sysv.tpl @@ -0,0 +1,123 @@ +#!/bin/bash +set -e # end if anything fails + +# tag: if the next line is changed/removed a reinstall of sysd2sysv will keep this file +# sysd2sysv-template # + +PROG=%PROG% +PROG_PATH=$(which $PROG) || { echo "$PROG missing"; exit 1; } + +syslog=/dev/null +syserr=/tmp/%PROG%.err + +RETVAL=0 + +. /lib/lsb/init-functions + +usage() { + echo "$0 [options] start|restart|stop" + echo " -l DEFAULT: $syslog" + echo " -e DEFAULT: $syserr" +} + +start () { + + # check, if process is already running + if [ `ps -ef | grep $PROG_PATH | grep -v grep | grep -v bash | wc -l` -gt 0 ] + then + log_end_msg 1 + exit 1 + fi + + log_daemon_msg $PROG || true + ($PROG &) 1>>$syslog 2>>$syserr + sleep 2 + if status_of_proc $PROG + then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi +} + +status() { + if [ `ps -ef | grep $PROG_PATH | grep -v grep | grep -v bash | wc -l` -gt 0 ] + then + echo -n $PROG" is running..." + echo "" + else + echo -n $PROG" is stopped" + echo "" + fi +} + +stop () { + log_daemon_msg "Stopping $PROG" + kill $(ps aux |grep $PROG_PATH |grep -v grep | awk '{print $2}') || true + return 0 +} + +# evaluate parameters + +operation="NOP" + +while [ -n "$1" ] +do + case "$1" in + start) + operation=start + shift + ;; + restart) + operation=restart + shift + ;; + stop) + operation=stop + shift + ;; + -c) + configfile=$2 + shift 2 + ;; + -l) + syslog=$2 + if [ -f $syslog ]; then rm $syslog; fi + shift 2 + ;; + -e) + syserr=$2 + shift 2 + ;; + -h) + usage + exit 0 + ;; + *) + usage + exit 1 + ;; + esac +done + +if [ -f $syserr ]; then rm $syserr; fi + +case $operation in +start) + start + ;; +stop) + stop + ;; +restart) + stop + start + ;; +*) + usage + exit 1 + ;; +esac + +exit 0 +