~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/ippl

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
# Written by Hugo Haas <hugo@debian.org>.
4
 
# Modified by Marc Haber <mh+debian-packages@zugschlus.de>.
5
 
 
6
 
### BEGIN INIT INFO
7
 
# Provides:          ippl
8
 
# Required-Start:    $local_fs $remote_fs $syslog $named $network $time
9
 
# Required-Stop:     $local_fs $remote_fs $syslog $named $network
10
 
# Should-Start:
11
 
# Should-Stop:
12
 
# Default-Start:     2 3 4 5
13
 
# Default-Stop:      0 1 6
14
 
# Short-Description: IP protocols logger
15
 
# Description:       ippl writes information about incoming network traffic
16
 
### END INIT INFO
17
 
 
18
 
set -e
19
 
 
20
 
if [ -r "/lib/lsb/init-functions" ]; then
21
 
  . /lib/lsb/init-functions
22
 
else
23
 
  echo "E: /lib/lsb/init-functions not found, lsb-base (>= 3.0-6) needed"
24
 
  exit 1
25
 
fi
26
 
 
27
 
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
28
 
 
29
 
RUNDIR="/var/run/ippl"
30
 
PIDFILE="$RUNDIR/ippl.pid"
31
 
CONFDIR="/etc"
32
 
CONFDDIR="$CONFDIR/ippl.conf.d"
33
 
CONFFILE="$RUNDIR/ippl.conf"
34
 
IPPLCOMMENTS="no"
35
 
 
36
 
DAEMON="/usr/sbin/ippl"
37
 
NAME="ippl"
38
 
DESC="IP protocols logger"
39
 
 
40
 
test -f $DAEMON || exit 0
41
 
 
42
 
# this is from madduck on IRC, 2006-07-06
43
 
# There should be a better possibility to give daemon error messages
44
 
# and/or to log things
45
 
log()
46
 
{
47
 
  case "$1" in
48
 
    [[:digit:]]*) success=$1; shift;;
49
 
    *) :;;
50
 
  esac
51
 
  log_action_begin_msg "$1"; shift
52
 
  log_action_end_msg ${success:-0} "$*"
53
 
}
54
 
 
55
 
 
56
 
# run-parts emulation, stolen from Branden's /etc/X11/Xsession
57
 
# Addition: Use file.rul instead if file if it exists.
58
 
run_parts () {
59
 
        # reset LC_COLLATE
60
 
        unset LANG LC_COLLATE LC_ALL
61
 
 
62
 
        if [ -z "$1" ]; then
63
 
                log "internal run_parts called without an argument"
64
 
        fi
65
 
        if [ ! -d "$1" ]; then
66
 
                log "internal run_parts called, but $1 does not exist or is not a directory."
67
 
        fi
68
 
        for F in $(ls $1); do
69
 
                if expr "$F" : '[[:alnum:]_-]\+$' > /dev/null 2>&1; then
70
 
                        if [ -f "$1/$F" ] ; then
71
 
                                if [ -f "$1/${F}.rul" ] ; then
72
 
                                        echo "$1/${F}.rul"
73
 
                                else
74
 
                                        echo "$1/$F"
75
 
                                fi
76
 
                        fi
77
 
                fi
78
 
        done;
79
 
}
80
 
 
81
 
cat_parts() {
82
 
       if [ -z "$1" ]; then
83
 
               log "internal cat_parts called without an argument"
84
 
       fi
85
 
       if [ ! -d "$1" ]; then
86
 
               exit 0
87
 
       fi
88
 
       for file in $(run_parts $1); do
89
 
               echo "#####################################################"
90
 
               echo "### $file"
91
 
               echo "#####################################################"
92
 
               cat $file
93
 
               echo
94
 
               echo "#####################################################"
95
 
               echo "### end $file"
96
 
               echo "#####################################################"
97
 
       done
98
 
}
99
 
 
100
 
removecomments() {
101
 
        if [ "x${IPPLCOMMENTS}" = "xno" ] ; then
102
 
                grep -E -v '^[[:space:]]*#' | sed -e '/^$/N;/\n$/D' ;
103
 
        else
104
 
                cat
105
 
        fi
106
 
}
107
 
 
108
 
 
109
 
update_ippl_conf() {
110
 
cat << EOF > ${CONFFILE}.tmp
111
 
#########
112
 
# WARNING WARNING WARNING
113
 
# WARNING WARNING WARNING
114
 
# WARNING WARNING WARNING
115
 
# WARNING WARNING WARNING
116
 
# WARNING WARNING WARNING
117
 
# this file is generated dynamically from /etc/ippl/ippl.conf and the files
118
 
# in /etc/ippl/ippl.conf.d
119
 
# Any changes you make here will be lost.
120
 
# WARNING WARNING WARNING
121
 
# WARNING WARNING WARNING
122
 
# WARNING WARNING WARNING
123
 
# WARNING WARNING WARNING
124
 
# WARNING WARNING WARNING
125
 
#########
126
 
EOF
127
 
 
128
 
(cat ${CONFDIR}/ippl.conf 2>/dev/null; cat_parts ${CONFDDIR}) | \
129
 
  removecomments \
130
 
  >> ${CONFFILE}.tmp
131
 
 
132
 
# test validity if called without -o
133
 
# this is not currently possible with ippl,
134
 
# but can be easily enabled with this (of course untested) example code
135
 
#if [ "x${CONFFILE}" = "x${AUTOCONFIGFILE}" ] && \
136
 
#        [ -x ${DAEMON} ] ; then
137
 
#        if ! ${DAEMON} --config "${CONFFILE}.tmp" > /dev/null ; then
138
 
#                log "Invalid new configfile ${CONFFILE}.tmp"
139
 
#                log "not installing ${CONFFILE}.tmp to ${CONFFILE}"
140
 
#                exit 1
141
 
#        fi
142
 
#fi
143
 
 
144
 
mv -f ${CONFFILE}.tmp ${CONFFILE}
145
 
}
146
 
 
147
 
check_started () {
148
 
  pidofproc -p $PIDFILE $DAEMON > /dev/null
149
 
}
150
 
 
151
 
start () {
152
 
  if ! check_started; then
153
 
      start_daemon -p $PIDFILE $DAEMON -c /var/run/ippl/ippl.conf
154
 
      ret=$?
155
 
  else
156
 
    log_failure_msg "already running!"
157
 
    log_end_msg 1
158
 
    exit 1
159
 
  fi
160
 
  return $ret
161
 
}
162
 
 
163
 
stop () {
164
 
  killproc -p $PIDFILE $DAEMON
165
 
  return $?
166
 
}
167
 
 
168
 
status()
169
 
{
170
 
  log_action_begin_msg "checking $DAEMON"
171
 
  if check_started; then
172
 
    log_action_end_msg 0 "running"
173
 
  else
174
 
    if [ -e "$PIDFILE" ]; then
175
 
      log_action_end_msg 1 "$DAEMON failed"
176
 
      exit 1
177
 
    else
178
 
      log_action_end_msg 0 "not running"
179
 
      exit 3
180
 
    fi
181
 
  fi
182
 
}
183
 
 
184
 
 
185
 
[ -e /var/run/ippl ] || \
186
 
  install -d -oDebian-ippl -gDebian-ippl -m755 /var/run/ippl
187
 
 
188
 
case "$1" in
189
 
  start)
190
 
    log_daemon_msg "Starting $DESC" "$NAME"
191
 
    update_ippl_conf
192
 
    start
193
 
    log_end_msg $?
194
 
    ;;
195
 
  stop)
196
 
    log_daemon_msg "Stopping $DESC" "$NAME"
197
 
    stop
198
 
    log_end_msg $?
199
 
    ;;
200
 
  restart|force-reload)
201
 
    log_daemon_msg "Restarting $DESC" "$NAME"
202
 
    stop
203
 
    if [ -z "$?" -o "$?" = "0" ]; then
204
 
      update_ippl_conf
205
 
      start
206
 
    fi
207
 
    log_end_msg $?
208
 
    ;;
209
 
  status)
210
 
    status
211
 
    ;;
212
 
  *)
213
 
    log_failure_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2
214
 
    exit 1
215
 
    ;;
216
 
esac
217
 
 
218
 
exit 0