Add initial meta-stx to support StarlingX build
[pti/rtp.git] / meta-stx / recipes-devtools / python / files / python-django-horizon / horizon.init
1 #!/bin/sh
2
3 ### BEGIN INIT INFO
4 # Provides:          OpenStack Dashboard
5 # Required-Start:    networking
6 # Required-Stop:     networking
7 # Default-Start:     2 3 4 5
8 # Default-Stop:      0 1 6
9 # Short-Description: OpenStack Dashboard
10 # Description:       Web based user interface to OpenStack services including
11 #                    Nova, Swift, Keystone, etc.
12 ### END INIT INFO
13
14 RETVAL=0
15 DESC="openstack-dashboard"
16 PIDFILE="/var/run/$DESC.pid"
17 PYTHON=`which python`
18 # Centos packages openstack_dashboard under /usr/share
19 #MANAGE="@PYTHON_SITEPACKAGES@/openstack_dashboard/manage.py"
20 MANAGE="/usr/share/openstack-dashboard/manage.py"
21 EXEC="/usr/bin/gunicorn"
22 BIND="localhost"
23 PORT="8008"
24 WORKER="eventlet"
25 WORKERS=`grep workers /etc/openstack-dashboard/horizon-config.ini | cut -f3 -d' '`
26 # Increased timeout to facilitate large image uploads
27 TIMEOUT="200"
28 STATICDIR="/www/pages/static"
29 BRANDDIR="/opt/branding"
30 APPLIEDDIR="/opt/branding/applied"
31 TMPUPLOADDIR="/scratch/horizon"
32
33 source /usr/bin/tsconfig
34
35 start()
36 {
37     #  Change workers if combined controller/compute
38     . /etc/platform/platform.conf
39     if [ "${WORKERS}" -lt "2" ]; then
40         WORKERS=2
41     fi
42
43     if [ -e $PIDFILE ]; then
44         PIDDIR=/proc/$(cat $PIDFILE)
45         if [ -d ${PIDDIR} ]; then
46             echo "$DESC already running."
47             return
48         else
49             echo "Removing stale PID file $PIDFILE"
50             rm -f $PIDFILE
51         fi
52     fi
53
54     # Clean up any possible orphaned worker threads
55     if lsof -t -i:${PORT} 1> /dev/null 2>&1; then
56         kill $(lsof -t -i:${PORT}) > /dev/null 2>&1
57     fi
58
59     rm -rf ${TMPUPLOADDIR}
60     mkdir -p ${TMPUPLOADDIR}
61
62     echo -n "Starting $DESC..."
63     
64     start-stop-daemon --start --quiet --background --pidfile ${PIDFILE} \
65         --make-pidfile --exec ${PYTHON} -- ${EXEC} --bind ${BIND}:${PORT} \
66         --worker-class ${WORKER} --workers ${WORKERS} --timeout ${TIMEOUT} \
67         --log-syslog  \
68         --config '/usr/share/openstack-dashboard/guni_config.py' \
69         --pythonpath '/usr/share/openstack-dashboard' \
70         openstack_dashboard.wsgi
71     RETVAL=$?
72     if [ $RETVAL -eq 0 ]; then
73         echo "done."
74     else
75         echo "failed."
76     fi
77
78     # now copy customer branding file to CONFIG_PATH/branding if anything updated
79     sm-query service drbd-platform | grep enabled-active > /dev/null 2>&1
80     IS_ACTIVE=$?
81
82     if ls ${BRANDDIR}/*.tgz 1> /dev/null 2>&1; then
83         LATESTBRANDING=$(ls $BRANDDIR |grep '\.tgz$' | tail -n 1)
84         if [ $IS_ACTIVE -eq 0 ]; then
85             # Only do the copy if the tarball has changed
86             if ! cmp --silent ${BRANDDIR}/${LATESTBRANDING} ${CONFIG_PATH}/branding/${LATESTBRANDING} ; then
87                 mkdir -p ${CONFIG_PATH}/branding
88                 rm -rf ${CONFIG_PATH}/branding/*.tgz
89                 cp -r ${BRANDDIR}/${LATESTBRANDING} ${CONFIG_PATH}/branding
90             fi
91         fi
92     fi
93
94     # As part of starting horizon we should kill containerized horizon so that it
95     # will pickup branding changes
96     kubectl --kubeconfig=/etc/kubernetes/admin.conf delete pods -n openstack -l application=horizon 1>/dev/null
97 }
98
99 stop()
100 {
101     if [ ! -e $PIDFILE ]; then return; fi
102
103     echo -n "Stopping $DESC..."
104
105     start-stop-daemon --stop --quiet --pidfile $PIDFILE
106     RETVAL=$?
107     if [ $RETVAL -eq 0 ]; then
108         echo "done."
109     else
110         echo "failed."
111     fi
112     rm -rf ${TMPUPLOADDIR}
113     rm -f $PIDFILE
114 }
115
116 status()
117 {
118     pid=`cat $PIDFILE 2>/dev/null`
119     if [ -n "$pid" ]; then
120         if ps -p $pid &> /dev/null ; then
121             echo "$DESC is running"
122             RETVAL=0
123             return
124         else
125             RETVAL=1
126         fi
127     fi
128     echo "$DESC is not running"
129     RETVAL=3
130 }
131
132 case "$1" in
133     start)
134         start
135         ;;
136     stop)
137         stop
138         ;;
139     restart|force-reload|reload)
140         stop
141         start
142         ;;
143     status)
144             status
145         ;;
146     *)
147         echo "Usage: $0 {start|stop|force-reload|restart|reload|status}"
148         RETVAL=1
149         ;;
150 esac
151
152 exit $RETVAL