Commit 48bed470 authored by Sigmund Augdal's avatar Sigmund Augdal

De-duplicate init scripts

parent 6680f8fd
......@@ -7,6 +7,8 @@ rm -rf pkg/opt
target=pkg/opt/nova_router_services
mkdir -p $target/bin
cp clean_stale.py dhcp_configurator.py iptables_configurator.py neighbors.py nova_bfd_monitor.py $target/bin
mkdir -p $target/lib
cp init-functions $target/lib
virtualenv $target
source $target/bin/activate
......
die()
{
log_failure_msg $1
exit 1
}
start()
{
. /opt/nova_router_services/bin/activate
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec $EXE -- $args || return 2
return 0
}
stop()
{
if [ ! -f $PIDFILE ] ; then
# This is a success according to LSB
return 0
fi
start-stop-daemon --stop --pidfile "$PIDFILE"
rm -f $PIDFILE
return 0
}
status()
{
if [ ! -f $PIDFILE ] ; then
# program not running
return 3
fi
for pid in $(cat $PIDFILE) ; do
if ! ps --no-headers p "$pid" | grep $EXE > /dev/null ; then
# program running, bogus pidfile
return 1
fi
done
return 0
}
main()
{
case "$1" in
start)
log_daemon_msg "Starting $NAME" "$NAME"
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
echo "pid file '$PIDFILE' found, $NAME not started."
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
stop)
log_daemon_msg "Stopping $NAME" "$NAME"
stop
ret=$?
case "$ret" in
0|1)
log_end_msg 0
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
restart)
log_daemon_msg "Restarting $NAME" "$NAME"
stop
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
status)
status
ret=$?
case "$ret" in
0)
echo "$NAME is running."
;;
1)
echo "$NAME dead, but $PIDFILE exists."
;;
*)
echo "$NAME not running."
;;
esac
exit $ret
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|status}"
exit 2
;;
esac
:
}
......@@ -17,131 +17,14 @@ CA_CERT=/etc/etcd/myca.crt
CERT=/etc/etcd/server.crt
KEY=/etc/etcd/server.key
test -x $ETCD || exit 0
if [ -e /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/lsb/init-functions
die()
{
log_failure_msg $1
exit 1
}
. /opt/nova_router_services/lib/init-functions
args="-d --pidfile $PIDFILE --cert $CERT --key $KEY --cacert $CA_CERT"
start()
{
. /opt/nova_router_services/bin/activate
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec $EXE -- $args || return 2
return 0
}
stop()
{
if [ ! -f $PIDFILE ] ; then
# This is a success according to LSB
return 0
fi
start-stop-daemon --stop --pidfile "$PIDFILE"
rm -f $PIDFILE
return 0
}
status()
{
if [ ! -f $PIDFILE ] ; then
# program not running
return 3
fi
for pid in $(cat $PIDFILE) ; do
if ! ps --no-headers p "$pid" | grep $EXE > /dev/null ; then
# program running, bogus pidfile
return 1
fi
done
return 0
}
case "$1" in
start)
log_daemon_msg "Starting $NAME" "$NAME"
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
echo "pid file '$PIDFILE' found, $NAME not started."
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
stop)
log_daemon_msg "Stopping $NAME" "$NAME"
stop
ret=$?
case "$ret" in
0|1)
log_end_msg 0
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
restart)
log_daemon_msg "Restarting $NAME" "$NAME"
stop
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
status)
status
ret=$?
case "$ret" in
0)
echo "$NAME is running."
;;
1)
echo "$NAME dead, but $PIDFILE exists."
;;
*)
echo "$NAME not running."
;;
esac
exit $ret
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|status}"
exit 2
;;
esac
:
main $1
......@@ -17,131 +17,14 @@ CA_CERT=/etc/etcd/myca.crt
CERT=/etc/etcd/server.crt
KEY=/etc/etcd/server.key
test -x $ETCD || exit 0
if [ -e /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/lsb/init-functions
die()
{
log_failure_msg $1
exit 1
}
. /opt/nova_router_services/lib/init-functions
args="-d --pidfile $PIDFILE --cert $CERT --key $KEY --cacert $CA_CERT"
start()
{
. /opt/nova_router_services/bin/activate
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec $EXE -- $args || return 2
return 0
}
stop()
{
if [ ! -f $PIDFILE ] ; then
# This is a success according to LSB
return 0
fi
start-stop-daemon --stop --pidfile "$PIDFILE"
rm -f $PIDFILE
return 0
}
status()
{
if [ ! -f $PIDFILE ] ; then
# program not running
return 3
fi
for pid in $(cat $PIDFILE) ; do
if ! ps --no-headers p "$pid" | grep $EXE > /dev/null ; then
# program running, bogus pidfile
return 1
fi
done
return 0
}
case "$1" in
start)
log_daemon_msg "Starting $NAME" "$NAME"
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
echo "pid file '$PIDFILE' found, $NAME not started."
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
stop)
log_daemon_msg "Stopping $NAME" "$NAME"
stop
ret=$?
case "$ret" in
0|1)
log_end_msg 0
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
restart)
log_daemon_msg "Restarting $NAME" "$NAME"
stop
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
status)
status
ret=$?
case "$ret" in
0)
echo "$NAME is running."
;;
1)
echo "$NAME dead, but $PIDFILE exists."
;;
*)
echo "$NAME not running."
;;
esac
exit $ret
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|status}"
exit 2
;;
esac
:
main $1
......@@ -14,131 +14,14 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
PIDFILE=/var/run/$NAME.pid
EXE=/opt/nova_router_services/bin/$NAME.py
test -x $ETCD || exit 0
if [ -e /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/lsb/init-functions
die()
{
log_failure_msg $1
exit 1
}
. /opt/nova_router_services/lib/init-functions
args="-d --pidfile $PIDFILE --interface $INTERFACE"
start()
{
. /opt/nova_router_services/bin/activate
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec $EXE -- $args || return 2
return 0
}
stop()
{
if [ ! -f $PIDFILE ] ; then
# This is a success according to LSB
return 0
fi
start-stop-daemon --stop --pidfile "$PIDFILE"
rm -f $PIDFILE
return 0
}
status()
{
if [ ! -f $PIDFILE ] ; then
# program not running
return 3
fi
for pid in $(cat $PIDFILE) ; do
if ! ps --no-headers p "$pid" | grep $EXE > /dev/null ; then
# program running, bogus pidfile
return 1
fi
done
return 0
}
case "$1" in
start)
log_daemon_msg "Starting $NAME" "$NAME"
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
echo "pid file '$PIDFILE' found, $NAME not started."
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
stop)
log_daemon_msg "Stopping $NAME" "$NAME"
stop
ret=$?
case "$ret" in
0|1)
log_end_msg 0
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
restart)
log_daemon_msg "Restarting $NAME" "$NAME"
stop
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
status)
status
ret=$?
case "$ret" in
0)
echo "$NAME is running."
;;
1)
echo "$NAME dead, but $PIDFILE exists."
;;
*)
echo "$NAME not running."
;;
esac
exit $ret
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|status}"
exit 2
;;
esac
:
main $1
......@@ -17,131 +17,14 @@ CA_CERT=/etc/etcd/myca.crt
CERT=/etc/etcd/server.crt
KEY=/etc/etcd/server.key
test -x $ETCD || exit 0
if [ -e /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/lsb/init-functions
die()
{
log_failure_msg $1
exit 1
}
. /opt/nova_router_services/lib/init-functions
args="-d --pidfile $PIDFILE --cert $CERT --key $KEY --cacert $CA_CERT --interface $INTERFACE --routers $ROUTERS"
start()
{
. /opt/nova_router_services/bin/activate
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec $EXE -- $args || return 2
return 0
}
stop()
{
if [ ! -f $PIDFILE ] ; then
# This is a success according to LSB
return 0
fi
start-stop-daemon --stop --pidfile "$PIDFILE"
rm -f $PIDFILE
return 0
}
status()
{
if [ ! -f $PIDFILE ] ; then
# program not running
return 3
fi
for pid in $(cat $PIDFILE) ; do
if ! ps --no-headers p "$pid" | grep $EXE > /dev/null ; then
# program running, bogus pidfile
return 1
fi
done
return 0
}
case "$1" in
start)
log_daemon_msg "Starting $NAME" "$NAME"
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
echo "pid file '$PIDFILE' found, $NAME not started."
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
stop)
log_daemon_msg "Stopping $NAME" "$NAME"
stop
ret=$?
case "$ret" in
0|1)
log_end_msg 0
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
restart)
log_daemon_msg "Restarting $NAME" "$NAME"
stop
start
ret=$?
case "$ret" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
;;
2)
log_end_msg 1
;;
esac
exit $ret
;;
status)
status
ret=$?
case "$ret" in
0)
echo "$NAME is running."
;;
1)
echo "$NAME dead, but $PIDFILE exists."
;;
*)
echo "$NAME not running."
;;
esac
exit $ret
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|status}"
exit 2
;;
esac
:
main $1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment