#!/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