summaryrefslogtreecommitdiffstats
path: root/recipes-networking/openvswitchdpdk/files/openvswitchdpdk-controller
diff options
context:
space:
mode:
authorAdrian Dudau <adrian.dudau@enea.com>2014-06-26 13:48:23 +0200
committerAdrian Dudau <adrian.dudau@enea.com>2014-06-26 13:48:23 +0200
commit1b6242fc583a6b871304fb995af6dc211b58f69b (patch)
treeb5d434d90dedae24792906aa304897c23a134386 /recipes-networking/openvswitchdpdk/files/openvswitchdpdk-controller
downloadmeta-ip-1b6242fc583a6b871304fb995af6dc211b58f69b.tar.gz
initial commit for Enea Linux 4.0daisy-enea
Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'recipes-networking/openvswitchdpdk/files/openvswitchdpdk-controller')
-rwxr-xr-xrecipes-networking/openvswitchdpdk/files/openvswitchdpdk-controller279
1 files changed, 279 insertions, 0 deletions
diff --git a/recipes-networking/openvswitchdpdk/files/openvswitchdpdk-controller b/recipes-networking/openvswitchdpdk/files/openvswitchdpdk-controller
new file mode 100755
index 0000000..fdd5a46
--- /dev/null
+++ b/recipes-networking/openvswitchdpdk/files/openvswitchdpdk-controller
@@ -0,0 +1,279 @@
1#!/bin/sh
2#
3# Copyright (c) 2011 Nicira Networks Inc.
4# Copyright (c) 2007, 2009 Javier Fernandez-Sanguino <jfs@debian.org>
5#
6# This is free software; you may redistribute it and/or modify
7# it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; either version 2,
9# or (at your option) any later version.
10#
11# This is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License with
17# the Debian operating system, in /usr/share/common-licenses/GPL; if
18# not, write to the Free Software Foundation, Inc., 59 Temple Place,
19# Suite 330, Boston, MA 02111-1307 USA
20#
21### BEGIN INIT INFO
22# Provides: openvswitch-controller
23# Required-Start: $network $local_fs $remote_fs
24# Required-Stop: $remote_fs
25# Should-Start: $named
26# Should-Stop:
27# Default-Start: 2 3 4 5
28# Default-Stop: 0 1 6
29# Short-Description: Open vSwitch controller
30### END INIT INFO
31
32INSTALLPREFIX=
33
34if [ -n "$INSTALLPREFIX" ]
35then
36 PATH=$INSTALLPREFIX/sbin:$INSTALLPREFIX/bin:$PATH
37fi
38
39DAEMON=$INSTALLPREFIX/bin/ovs-controller # Introduce the server's location here
40NAME=ovs-controller # Introduce the short server's name here
41DESC=ovs-controller # Introduce a short description here
42LOGDIR=$INSTALLPREFIX/var/log/openvswitch # Log directory to use
43
44PIDFILE=$INSTALLPREFIX/var/run/openvswitch/$NAME.pid
45
46test -x $DAEMON || exit 0
47
48. /lib/lsb/init-functions
49
50# Default options, these can be overriden by the information
51# at /etc/default/openvswitchdpdk-controller
52DAEMON_OPTS="" # Additional options given to the server
53
54DODTIME=10 # Time to wait for the server to die, in seconds
55 # If this value is set too low you might not
56 # let some servers to die gracefully and
57 # 'restart' will not work
58
59LOGFILE=$LOGDIR/$NAME.log # Server logfile
60#DAEMONUSER= # User to run the daemons as. If this value
61 # is set start-stop-daemon will chuid the server
62
63# Include defaults if available
64default=/etc/default/openvswitchdpdk-controller
65if [ -f $default ] ; then
66 . $default
67fi
68
69# Check that the user exists (if we set a user)
70# Does the user exist?
71if [ -n "$DAEMONUSER" ] ; then
72 if getent passwd | grep -q "^$DAEMONUSER:"; then
73 # Obtain the uid and gid
74 DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
75 DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
76 else
77 log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
78 exit 1
79 fi
80fi
81
82
83set -e
84
85running_pid() {
86# Check if a given process pid's cmdline matches a given name
87 pid=$1
88 name=$2
89 [ -z "$pid" ] && return 1
90 [ ! -d /proc/$pid ] && return 1
91 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
92 # Is this the expected server
93 [ "$cmd" != "$name" ] && return 1
94 return 0
95}
96
97running() {
98# Check if the process is running looking at /proc
99# (works for all users)
100
101 # No pidfile, probably no daemon present
102 [ ! -f "$PIDFILE" ] && return 1
103 pid=`cat $PIDFILE`
104 running_pid $pid $DAEMON || return 1
105 return 0
106}
107
108start_server() {
109 if [ -z "$LISTEN" ]; then
110 echo "$default: No connection methods configured, controller disabled" >&2
111 exit 0
112 fi
113
114 if [ ! -d $INSTALLPREFIX/var/run/openvswitch ]; then
115 install -d -m 755 -o root -g root $INSTALLPREFIX/var/run/openvswitch
116 fi
117
118 SSL_OPTS=
119 case $LISTEN in
120 *ssl*)
121 : ${PRIVKEY:=$INSTALLPREFIX/etc/openvswitch-controller/privkey.pem}
122 : ${CERT:=$INSTALLPREFIX/etc/openvswitch-controller/cert.pem}
123 : ${CACERT:=$INSTALLPREFIX/etc/openvswitch-controller/cacert.pem}
124 if test ! -e "$PRIVKEY" || test ! -e "$CERT" ||
125 test ! -e "$CACERT"; then
126 if test ! -e "$PRIVKEY"; then
127 echo "$PRIVKEY: private key missing" >&2
128 fi
129 if test ! -e "$CERT"; then
130 echo "$CERT: certificate for private key missing" >&2
131 fi
132 if test ! -e "$CACERT"; then
133 echo "$CACERT: CA certificate missing" >&2
134 fi
135 exit 1
136 fi
137 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
138 ;;
139 esac
140
141# Start the process using the wrapper
142 if [ -z "$DAEMONUSER" ] ; then
143 start-stop-daemon --start --pidfile $PIDFILE \
144 --exec $DAEMON -- --detach --pidfile=$PIDFILE \
145 $LISTEN $DAEMON_OPTS $SSL_OPTS
146 errcode=$?
147 else
148# if we are using a daemonuser then change the user id
149 start-stop-daemon --start --quiet --pidfile $PIDFILE \
150 --chuid $DAEMONUSER --exec $DAEMON -- \
151 --detach --pidfile=$PIDFILE $LISTEN $DAEMON_OPTS \
152 $SSL_OPTS
153 errcode=$?
154 fi
155 return $errcode
156}
157
158stop_server() {
159# Stop the process using the wrapper
160 if [ -z "$DAEMONUSER" ] ; then
161 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
162 --exec $DAEMON
163 errcode=$?
164 else
165# if we are using a daemonuser then look for process that match
166 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
167 --user $DAEMONUSER --exec $DAEMON
168 errcode=$?
169 fi
170
171 return $errcode
172}
173
174reload_server() {
175 [ ! -f "$PIDFILE" ] && return 1
176 pid=`cat $PIDFILE` # This is the daemon's pid
177 # Send a SIGHUP
178 kill -1 $pid
179 return $?
180}
181
182force_stop() {
183# Force the process to die killing it manually
184 [ ! -e "$PIDFILE" ] && return
185 if running ; then
186 kill -15 $pid
187 # Is it really dead?
188 sleep "$DODTIME"
189 if running ; then
190 kill -9 $pid
191 sleep "$DODTIME"
192 if running ; then
193 echo "Cannot kill $NAME (pid=$pid)!"
194 exit 1
195 fi
196 fi
197 fi
198 rm -f $PIDFILE
199}
200
201
202case "$1" in
203 start)
204 log_begin_msg "Starting $DESC " "$NAME"
205 # Check if it's running first
206 if running ; then
207 log_warning_msg "apparently already running"
208 log_end_msg 0
209 exit 0
210 fi
211 if start_server && running ; then
212 # It's ok, the server started and is running
213 log_end_msg 0
214 else
215 # Either we could not start it or it is not running
216 # after we did
217 # NOTE: Some servers might die some time after they start,
218 # this code does not try to detect this and might give
219 # a false positive (use 'status' for that)
220 log_end_msg 1
221 fi
222 ;;
223 stop)
224 log_begin_msg "Stopping $DESC" "$NAME"
225 if running ; then
226 # Only stop the server if we see it running
227 stop_server
228 log_end_msg $?
229 else
230 # If it's not running don't do anything
231 log_warning_msg "apparently not running"
232 log_end_msg 0
233 exit 0
234 fi
235 ;;
236 force-stop)
237 # First try to stop gracefully the program
238 $0 stop
239 if running; then
240 # If it's still running try to kill it more forcefully
241 log_begin_msg "Stopping (force) $DESC" "$NAME"
242 force_stop
243 log_end_msg $?
244 fi
245 ;;
246 restart|force-reload)
247 log_begin_msg "Restarting $DESC" "$NAME"
248 stop_server
249 # Wait some sensible amount, some server need this
250 [ -n "$DODTIME" ] && sleep $DODTIME
251 start_server
252 running
253 log_end_msg $?
254 ;;
255 status)
256
257 log_begin_msg "Checking status of $DESC" "$NAME"
258 if running ; then
259 log_begin_msg "running"
260 log_end_msg 0
261 else
262 log_warning_msg "apparently not running"
263 log_end_msg 1
264 exit 1
265 fi
266 ;;
267 # Use this if the daemon cannot reload
268 reload)
269 log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
270 log_warning_msg "cannot re-read the config file (use restart)."
271 ;;
272 *)
273 N=/etc/init.d/openvswitchdpdk-controller
274 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
275 exit 1
276 ;;
277esac
278
279exit 0