Add initial meta-stx to support StarlingX build
[pti/rtp.git] / meta-stx / recipes-devtools / python / files / python-keystone / stx-files / keystone-all
1 #!/bin/sh
2 # Copyright (c) 2013-2018 Wind River Systems, Inc.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5 #
6
7 ### BEGIN INIT INFO
8 # Provides:          OpenStack Keystone-wsgi
9 # Required-Start:    networking
10 # Required-Stop:     networking
11 # Default-Start:     2 3 4 5
12 # Default-Stop:      0 1 6
13 # Short-Description: OpenStack Keystone
14 # Description:       Openstack Identitiy service running on WSGI compatable gunicorn web server 
15 #                    
16 ### END INIT INFO
17
18 RETVAL=0
19 #public 5000
20
21 DESC_PUBLIC="openstack-keystone"
22
23 PIDFILE_PUBLIC="/var/run/$DESC_PUBLIC.pid"
24
25 PYTHON=`which python`
26
27 source /etc/keystone/keystone-extra.conf
28 source /etc/platform/platform.conf
29
30 if [ -n ${@:2:1} ] ; then
31         if [ ${@:2:1}="--public-bind-addr" ] ; then
32                 PUBLIC_BIND_ADDR_CMD=${@:3:1}
33         fi
34 fi
35
36
37 ###
38 EXEC="/usr/bin/gunicorn"
39
40 WORKER="eventlet"
41 # Increased timeout to facilitate large image uploads
42 TIMEOUT="200"
43
44 # Calculate the no of workers based on the number of workers retrieved by
45 # Platform Eng which is retreived from the keystone-extra.conf
46
47 if [ "$system_type" == "All-in-one" ]; then
48     TIS_WORKERS_FACTOR=1
49 else
50     TIS_WORKERS_FACTOR=1.5
51 fi
52 TIS_WORKERS=$(echo "${TIS_WORKERS_FACTOR}*${TIS_PUBLIC_WORKERS}"|bc )
53 TIS_WORKERS=${TIS_WORKERS%.*}
54
55 #--max-requests , --max-requests-jitter Configuration
56 #--max-requests = The max number of requests a worker will process before restarting
57 #--max-requests-jitter = The maximum jitter to add to the max_requests setting.
58 MAX_REQUESTS=100000
59 MAX_REQ_JITTER_CAP_FACTOR=0.5
60 MAX_REQ_JITTER_PUBLIC=$(echo "${TIS_WORKERS}*${MAX_REQ_JITTER_CAP_FACTOR}+1"|bc)
61 MAX_REQ_JITTER_PUBLIC=${MAX_REQ_JITTER_PUBLIC%.*}
62
63
64 start()
65 {
66     # Got proper no of workers . Starting gunicorn now
67     echo -e "Initialising keystone service using gunicorn .. \n"
68
69     if [ -z "$PUBLIC_BIND_ADDR" ]; then
70         echo "Keystone floating ip not found . Cannot start services. Exiting .."
71         exit 1
72     fi
73     BIND_PUBLIC=$PUBLIC_BIND_ADDR:5000
74
75     if [ -e $PIDFILE_PUBLIC ]; then
76         PIDDIR=/proc/$(cat $PIDFILE_PUBLIC)
77         if [ -d ${PIDDIR} ]; then
78             echo "$DESC_PUBLIC already running."
79             exit 1
80         else
81             echo "Removing stale PID file $PIDFILE_PUBLIC"
82             rm -f $PIDFILE_PUBLIC
83         fi
84     fi
85
86     echo -e "Starting $DESC_PUBLIC...\n";
87     echo -e "Worker is ${WORKER} --workers ${TIS_WORKERS} --timeout ${TIMEOUT} --max_requests ${MAX_REQUESTS} --max_request_jitter public ${MAX_REQ_JITTER_PUBLIC}\n" ;
88
89     echo -e "Starting keystone process at port 5000 \n" ;
90
91     start-stop-daemon --start --quiet --background --pidfile ${PIDFILE_PUBLIC} \
92         --make-pidfile --exec ${PYTHON} -- ${EXEC} --bind ${BIND_PUBLIC} \
93         --worker-class ${WORKER} --workers ${TIS_WORKERS} --timeout ${TIMEOUT} \
94         --max-requests ${MAX_REQUESTS}  --max-requests-jitter ${MAX_REQ_JITTER_PUBLIC} \
95         --log-syslog  \
96         --pythonpath '/usr/share/keystone' public:application --name keystone-public
97
98     RETVAL=$?
99     if [ $RETVAL -eq 0 ]; then
100         echo -e "Keystone started at port 5000... \n"
101     else
102         echo -e "Failed to start Keystone .. \n"
103     fi
104 }
105
106 stop()
107 {
108     if [  -e $PIDFILE_PUBLIC ]; then 
109         start-stop-daemon --stop --quiet --pidfile $PIDFILE_PUBLIC
110         RETVAL_PUBLIC=$?
111             if [ $RETVAL_PUBLIC -eq 0 ]; then
112                 echo "Stopped $DESC_PUBLIC."
113             else
114                 echo "Stopping failed - $PIDFILE_PUBLIC"
115             fi
116             rm -f $PIDFILE_PUBLIC
117     else 
118         echo "Already stopped - $PIDFILE_PUBLIC"
119     fi 
120 }
121
122 status()
123 {
124     pid_public=`cat $PIDFILE_PUBLIC 2>/dev/null`
125
126     if [ -n "$pid_public" ]; then
127         echo -e "\033[32m $DESC_PUBLIC  is running..\033[0m"
128     else
129         echo -e "\033[31m $DESC_PUBLIC  is not running..\033[0m"
130     fi
131 }
132
133
134
135 case "$1" in
136     start)
137         start
138         ;;
139     stop)
140         stop
141         ;;
142     restart|force-reload|reload)
143         stop
144         start
145         ;;
146     status)
147         status
148         ;;
149     *)
150         #echo "Usage: $0 {start|stop|force-reload|restart|reload|status} OR {/usr/bin/keystone-all start --public-bind-addr xxx.xxx.xxx}"
151         start
152         #RETVAL=1
153         ;;
154 esac
155
156 exit $RETVAL