f7b921bcf96bf2b8b20d531c48d93788b27f2775
[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     "/usr/share/$proj/$proj-dist.conf" \
25     "/etc/$proj/$proj.conf" \
26     "/etc/$proj/dhcp_agent.ini"
27 )
28 configs_str=${configs[@]/#/--config-file }
29
30 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
31
32 lockfile=/var/lock/subsys/$prog
33
34 clean() {
35     cleanopts="$@"
36     [ -x $exec ] || exit 5
37     for config in ${configs[@]}; do
38         [ -f $config ] || exit 6
39     done
40     runuser -s /bin/bash neutron -c "$exec $cleanopts --log-file /var/log/$proj/netns-cleanup.log $configs_str &>/dev/null"
41     if [ "x$1" == "x--force" ]; then
42         killall neutron-ns-metadata-proxy 2>/dev/null  || :
43         killall neutron-keepalived-state-change 2>/dev/null || :
44         kill $(ps ax | grep -e "keepalived.*\.pid-vrrp" | awk '{print $1}') 2>/dev/null || :
45         kill $(ps ax | grep -e "radvd.*\.pid\.radvd" | awk '{print $1}') 2>/dev/null || :
46     fi
47     return $?
48 }
49
50 retval=0
51
52 case "$1" in
53     start)
54         clean
55         retval=$?
56         [ $retval -eq 0 ] && touch $lockfile
57         ;;
58     stop)
59         clean --force
60         retval=$?
61         [ $retval -eq 0 ] && rm -f $lockfile
62         ;;
63     status)
64         [ ! -f $lockfile ] && retval=3
65         ;;
66     restart|reload|force-reload|status|condrestart|try-restart)
67         # Do nothing
68         ;;
69     *)
70         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
71         exit 2
72 esac
73 exit $retval