posaune
[projects.git] / etc / sysd2sysv.tpl
1 #!/bin/bash
2 set -e # end if anything fails
3
4 # tag: if the next line is changed/removed a reinstall of sysd2sysv will keep this file
5 # sysd2sysv-template #
6
7 PROG=%PROG%
8 PROG_PATH=$(which $PROG) || { echo "$PROG missing"; exit 1; }
9
10 syslog=/dev/null
11 syserr=/tmp/%PROG%.err
12
13 RETVAL=0
14
15 . /lib/lsb/init-functions
16
17 usage() {
18         echo "$0 [options] start|restart|stop"
19         echo "  -l <syslog>     DEFAULT: $syslog"
20         echo "  -e <errlog>     DEFAULT: $syserr"
21 }
22
23 start () {
24
25         # check, if process is already running
26         if [ `ps -ef | grep $PROG_PATH | grep -v grep | grep -v bash | wc -l` -gt 0 ]
27         then
28                 log_end_msg 1
29                 exit 1
30         fi
31         
32         log_daemon_msg $PROG || true
33         ($PROG &) 1>>$syslog 2>>$syserr
34         sleep 2
35         if status_of_proc $PROG
36         then
37                 log_end_msg 0 || true
38         else
39             log_end_msg 1 || true
40         fi
41 }
42
43 status() {
44         if [ `ps -ef | grep $PROG_PATH | grep -v grep | grep -v bash | wc -l` -gt 0 ]
45         then
46                 echo -n $PROG" is running..."
47                 echo ""
48         else
49                 echo -n $PROG" is stopped"
50                 echo ""
51         fi
52 }
53
54 stop () {
55         log_daemon_msg "Stopping $PROG"
56         kill $(ps aux |grep $PROG_PATH |grep -v grep | awk '{print $2}') || true
57         return 0
58 }
59
60 # evaluate parameters
61
62 operation="NOP"
63
64 while [ -n "$1" ]
65 do
66         case "$1" in
67         start)
68                 operation=start
69                 shift
70                 ;;
71         restart)
72                 operation=restart
73                 shift
74                 ;;
75         stop)
76                 operation=stop
77                 shift
78                 ;;
79         -c)
80                 configfile=$2
81                 shift 2
82                 ;;
83         -l)
84                 syslog=$2
85                 if [ -f $syslog ]; then rm $syslog; fi
86                 shift 2
87                 ;;
88         -e)
89                 syserr=$2
90                 shift 2
91                 ;;
92         -h)
93                 usage
94                 exit 0
95                 ;;
96         *)
97                 usage
98                 exit 1
99                 ;;
100         esac
101 done
102
103 if [ -f $syserr ]; then rm $syserr; fi
104
105 case $operation in
106 start)
107         start
108         ;;
109 stop)
110         stop
111         ;;
112 restart)
113         stop
114         start
115         ;;
116 *)
117         usage
118         exit 1
119         ;;
120 esac
121
122 exit 0
123