1a77b01cda66885aceebf2c5ee55a453125ea6ba
[openstack-build/neutron-build.git] / centos7 / rpm / SOURCES / neutron-netns-cleanup.init
1 #!/bin/bash
2 #
3 # neutron-netns-cleanup  OpenStack Neutron netns cleanup utility
4 #
5 # chkconfig:   - 97 02
6 # description: OpenStack Neutron netns cleanup utility
7 #
8 # This is a one-shot init.d script with the next properties:
9 #
10 # * It accepts 3 verbs: start, stop, status
11 # * It cleans unused resources during start (system or agents startup)
12 # * It cleans everything on stop (agents migration to other hosts)
13 # * Once started, it will respond with status = OK
14 # * Once stopped, it will respond with status = DEAD
15 #
16 ### END INIT INFO
17
18 . /etc/rc.d/init.d/functions
19
20 proj=neutron
21 prog=$proj-netns-cleanup
22 exec="/usr/bin/$prog"
23 configs=(
24     "/etc/$proj/$proj.conf" \
25     "/etc/$proj/dhcp_agent.ini"
26 )
27 configs_str=${configs[@]/#/--config-file }
28
29 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
30
31 lockfile=/var/lock/subsys/$prog
32
33 clean() {
34     cleanopts="$@"
35     [ -x $exec ] || exit 5
36     for config in ${configs[@]}; do
37         [ -f $config ] || exit 6
38     done
39     runuser -s /bin/bash neutron -c "$exec $cleanopts --log-file /var/log/$proj/netns-cleanup.log $configs_str &>/dev/null"
40     if [ "x$1" == "x--force" ]; then
41         killall neutron-ns-metadata-proxy 2>/dev/null  || :
42         killall neutron-keepalived-state-change 2>/dev/null || :
43         kill $(ps ax | grep -e "keepalived.*\.pid-vrrp" | awk '{print $1}') 2>/dev/null || :
44         kill $(ps ax | grep -e "radvd.*\.pid\.radvd" | awk '{print $1}') 2>/dev/null || :
45     fi
46     return $?
47 }
48
49 retval=0
50
51 case "$1" in
52     start)
53         clean
54         retval=$?
55         [ $retval -eq 0 ] && touch $lockfile
56         ;;
57     stop)
58         clean --force
59         retval=$?
60         [ $retval -eq 0 ] && rm -f $lockfile
61         ;;
62     status)
63         [ ! -f $lockfile ] && retval=3
64         ;;
65     restart|reload|force-reload|status|condrestart|try-restart)
66         # Do nothing
67         ;;
68     *)
69         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
70         exit 2
71 esac
72 exit $retval