| 1 |
#!/bin/sh |
| 2 |
# The content after this line comes from openstack-pkg-tools |
| 3 |
# and has been automatically added to a .init.in script, which |
| 4 |
# contains only the descriptive part for the daemon. Everything |
| 5 |
# else is standardized as a single unique script. |
| 6 |
|
| 7 |
# Author: Thomas Goirand <[email protected]> |
| 8 |
# Author: Ondřej Nový <[email protected]> |
| 9 |
|
| 10 |
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 11 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 12 |
|
| 13 |
if [ -n "${UWSGI_PORT}" ] && [ -n "${UWSGI_INI_PATH}" ] && [ -n "${UWSGI_INI_APP}" ] ; then |
| 14 |
if ! [ -f "${UWSGI_INI_APP}" ] ; then |
| 15 |
exit 0 |
| 16 |
fi |
| 17 |
if [ -d /etc/${PROJECT_NAME}/ssl/private ] ; then |
| 18 |
KEY_FILE=$(find /etc/${PROJECT_NAME}/ssl/private -type f -iname '*.pem' 2>/dev/null | head -n 1) |
| 19 |
fi |
| 20 |
|
| 21 |
if [ -d /etc/${PROJECT_NAME}/ssl/public ] ; then |
| 22 |
CERT_FILE=$(find /etc/${PROJECT_NAME}/ssl/public -type f -iname '*.crt' 2>/dev/null | head -n 1) |
| 23 |
else |
| 24 |
# This is needed for https://opendev.org/openstack/puppet-openstack-integration |
| 25 |
if [ -d /etc/${PROJECT_NAME}/ssl/certs ] ; then |
| 26 |
CERT_FILE=$(find /etc/${PROJECT_NAME}/ssl/certs -type f -iname '*.pem' 2>/dev/null | head -n 1) |
| 27 |
if [ -z "${CERT_FILE}" ] ; then |
| 28 |
CERT_FILE=$(find /etc/${PROJECT_NAME}/ssl/certs -type f -iname '*.crt' 2>/dev/null | head -n 1) |
| 29 |
fi |
| 30 |
fi |
| 31 |
fi |
| 32 |
|
| 33 |
if [ -d /etc/${PROJECT_NAME}/ssl/ca ] ; then |
| 34 |
CA_FILE=$(find /etc/${PROJECT_NAME}/ssl/ca -type f -iname '*.pem' 2>/dev/null | head -n 1) |
| 35 |
fi |
| 36 |
|
| 37 |
# Sid doesn't have /usr/bin/uwsgi_python3, so we need |
| 38 |
# to search for a more specific daemon name. For stretch |
| 39 |
# /usr/bin/uwsgi_python3 is fine. |
| 40 |
for i in 3 35 36 37 38 39 310 311 312 313 314 315 316 317 318 319 ; do |
| 41 |
if [ -x /usr/bin/uwsgi_python${i} ] ; then |
| 42 |
DAEMON=/usr/bin/uwsgi_python${i} |
| 43 |
fi |
| 44 |
done |
| 45 |
|
| 46 |
if [ -n "${UWSGI_BIND_CONFIG_FILE}" ] && [ -r "${UWSGI_BIND_CONFIG_FILE}" ] && [ -n "${UWSGI_BIND_CONFIG_SECTION}" ] && [ -n "${UWSGI_BIND_CONFIG_IP_DIRECTIVE}" ] && [ -n "${UWSGI_BIND_CONFIG_PORT_DIRECTIVE}" ] && [ -r /usr/share/openstack-pkg-tools/pkgos_func ] ; then |
| 47 |
. /usr/share/openstack-pkg-tools/pkgos_func |
| 48 |
pkgos_inifile get ${UWSGI_BIND_CONFIG_FILE} ${UWSGI_BIND_CONFIG_SECTION} ${UWSGI_BIND_CONFIG_IP_DIRECTIVE} |
| 49 |
if [ -n "${RET}" ] && [ ! "${RET}" = "NOT_FOUND" ] ; then |
| 50 |
UWSGI_BIND_IP=${RET} |
| 51 |
fi |
| 52 |
pkgos_inifile get ${UWSGI_BIND_CONFIG_FILE} ${UWSGI_BIND_CONFIG_SECTION} ${UWSGI_BIND_CONFIG_PORT_DIRECTIVE} |
| 53 |
if [ -n "${RET}" ] && [ ! "${RET}" = "NOT_FOUND" ] ; then |
| 54 |
UWSGI_PORT=${RET} |
| 55 |
fi |
| 56 |
if [ -n "${UWSGI_BIND_CONFIG_WORKERS_DIRECTIVE}" ] ; then |
| 57 |
pkgos_inifile get ${UWSGI_BIND_CONFIG_FILE} ${UWSGI_BIND_CONFIG_SECTION} ${UWSGI_BIND_CONFIG_WORKERS_DIRECTIVE} |
| 58 |
if [ -n "${RET}" ] && [ ! "${RET}" = "NOT_FOUND" ] ; then |
| 59 |
UWSGI_PROCESSES=" --processes ${RET}" |
| 60 |
else |
| 61 |
# If we can't find the directive in the config file, |
| 62 |
# we fallback to the number of thread / 2. |
| 63 |
UWSGI_PROCESSES=" --processes "$(( $(nproc) / 2 )) |
| 64 |
fi |
| 65 |
fi |
| 66 |
if [ "${UWSGI_BIND_CONFIG_FILE}" = "/etc/swift/object-server.conf" ] ; then |
| 67 |
pkgos_inifile get ${UWSGI_BIND_CONFIG_FILE} ${UWSGI_BIND_CONFIG_SECTION} devices |
| 68 |
if [ -n "${RET}" ] && [ ! "${RET}" = "NOT_FOUND" ] ; then |
| 69 |
DEVICES_PATH=${RET} |
| 70 |
NUM_DEVICES=$(ls ${DEVICES_PATH} | wc -l) |
| 71 |
COUNT=0 |
| 72 |
while [ "${COUNT}" != "${NUM_DEVICES}" ] ; do |
| 73 |
CUR_PORT=$(( ${UWSGI_PORT} + ${COUNT} )) |
| 74 |
BIND_PARAMS="${BIND_PARAMS} --http-socket ${UWSGI_BIND_IP}:${CUR_PORT}" |
| 75 |
COUNT=$(( ${COUNT} + 1 )) |
| 76 |
done |
| 77 |
fi |
| 78 |
fi |
| 79 |
else |
| 80 |
UWSGI_BIND_IP="[::]" |
| 81 |
fi |
| 82 |
|
| 83 |
if [ -n "${BIND_PARAMS}" ] ; then |
| 84 |
DAEMON_ARGS="${BIND_PARAMS}${UWSGI_PROCESSES}" |
| 85 |
else |
| 86 |
if [ -n "${KEY_FILE}" ] && [ -n "${CERT_FILE}" ] ; then |
| 87 |
if [ -z "${CA_FILE}" ] ; then |
| 88 |
DAEMON_ARGS="--https-socket ${UWSGI_BIND_IP}:${UWSGI_PORT},${CERT_FILE},${KEY_FILE}${UWSGI_PROCESSES}" |
| 89 |
else |
| 90 |
DAEMON_ARGS="--https-socket ${UWSGI_BIND_IP}:${UWSGI_PORT},${CERT_FILE},${KEY_FILE},,${CA_FILE}${UWSGI_PROCESSES}" |
| 91 |
fi |
| 92 |
else |
| 93 |
DAEMON_ARGS="--http-socket ${UWSGI_BIND_IP}:${UWSGI_PORT}${UWSGI_PROCESSES}" |
| 94 |
fi |
| 95 |
fi |
| 96 |
|
| 97 |
DAEMON_ARGS="${DAEMON_ARGS} --ini ${UWSGI_INI_PATH}" |
| 98 |
NO_OPENSTACK_CONFIG_FILE_DAEMON_ARG=yes |
| 99 |
NO_OPENSTACK_LOGFILE_DAEMON_ARG=yes |
| 100 |
fi |
| 101 |
|
| 102 |
if [ -z "${DAEMON}" ] ; then |
| 103 |
DAEMON=/usr/bin/${NAME} |
| 104 |
fi |
| 105 |
PIDFILE=/var/run/${PROJECT_NAME}/${NAME}.pid |
| 106 |
if [ -z "${SCRIPTNAME}" ] ; then |
| 107 |
SCRIPTNAME=/etc/init.d/${NAME} |
| 108 |
fi |
| 109 |
if [ -z "${SYSTEM_USER}" ] ; then |
| 110 |
SYSTEM_USER=${PROJECT_NAME} |
| 111 |
fi |
| 112 |
if [ -z "${SYSTEM_GROUP}" ] ; then |
| 113 |
SYSTEM_GROUP=${PROJECT_NAME} |
| 114 |
fi |
| 115 |
if [ "${SYSTEM_USER}" != "root" ] ; then |
| 116 |
STARTDAEMON_CHUID="--chuid ${SYSTEM_USER}:${SYSTEM_GROUP}" |
| 117 |
fi |
| 118 |
if [ -z "${CONFIG_FILE}" ] ; then |
| 119 |
CONFIG_FILE=/etc/${PROJECT_NAME}/${PROJECT_NAME}.conf |
| 120 |
fi |
| 121 |
LOGFILE=/var/log/${PROJECT_NAME}/${NAME}.log |
| 122 |
if [ -z "${NO_OPENSTACK_CONFIG_FILE_DAEMON_ARG}" ] ; then |
| 123 |
DAEMON_ARGS="--config-file=${CONFIG_FILE} ${DAEMON_ARGS}" |
| 124 |
fi |
| 125 |
|
| 126 |
# Exit if the package is not installed |
| 127 |
[ -x $DAEMON ] || exit 0 |
| 128 |
|
| 129 |
# If ran as root, create /var/lock/X, /var/run/X and /var/cache/X as needed |
| 130 |
if [ `whoami` = "root" ] ; then |
| 131 |
for i in lock run cache ; do |
| 132 |
mkdir -p /var/$i/${PROJECT_NAME} |
| 133 |
chown ${SYSTEM_USER}:${SYSTEM_GROUP} /var/$i/${PROJECT_NAME} |
| 134 |
done |
| 135 |
fi |
| 136 |
|
| 137 |
# This defines support functions which we use later on |
| 138 |
[ -e /lib/lsb/init-functions ] && . /lib/lsb/init-functions |
| 139 |
|
| 140 |
RET=0 |
| 141 |
|
| 142 |
# Manage log options: logfile and/or syslog, depending on user's choosing |
| 143 |
[ -r /etc/default/openstack ] && . /etc/default/openstack |
| 144 |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 145 |
[ "x$USE_SYSLOG" = "xyes" ] && DAEMON_ARGS="$DAEMON_ARGS --use-syslog" |
| 146 |
if [ -z "${NO_OPENSTACK_LOGFILE_DAEMON_ARG}" ] ; then |
| 147 |
[ "x$USE_LOGFILE" != "xno" ] && DAEMON_ARGS="$DAEMON_ARGS --log-file=$LOGFILE" |
| 148 |
fi |
| 149 |
|
| 150 |
do_start() { |
| 151 |
start-stop-daemon \ |
| 152 |
--start \ |
| 153 |
--quiet \ |
| 154 |
--background ${STARTDAEMON_CHUID} \ |
| 155 |
--make-pidfile --pidfile ${PIDFILE} \ |
| 156 |
--chdir /var/lib/${PROJECT_NAME} \ |
| 157 |
--startas $DAEMON \ |
| 158 |
--test > /dev/null \ |
| 159 |
|| return 1 |
| 160 |
if [ -n "${PYARGV}" ] ; then |
| 161 |
start-stop-daemon \ |
| 162 |
--start \ |
| 163 |
--quiet \ |
| 164 |
--background ${STARTDAEMON_CHUID} \ |
| 165 |
--make-pidfile --pidfile ${PIDFILE} \ |
| 166 |
--chdir /var/lib/${PROJECT_NAME} \ |
| 167 |
--startas $DAEMON \ |
| 168 |
-- $DAEMON_ARGS --pyargv "${PYARGV}" \ |
| 169 |
|| return 2 |
| 170 |
else |
| 171 |
start-stop-daemon \ |
| 172 |
--start \ |
| 173 |
--quiet \ |
| 174 |
--background ${STARTDAEMON_CHUID} \ |
| 175 |
--make-pidfile --pidfile ${PIDFILE} \ |
| 176 |
--chdir /var/lib/${PROJECT_NAME} \ |
| 177 |
--startas $DAEMON \ |
| 178 |
-- $DAEMON_ARGS \ |
| 179 |
|| return 2 |
| 180 |
fi |
| 181 |
} |
| 182 |
|
| 183 |
do_stop() { |
| 184 |
start-stop-daemon \ |
| 185 |
--stop \ |
| 186 |
--quiet \ |
| 187 |
--retry=TERM/30/KILL/5 \ |
| 188 |
--pidfile $PIDFILE |
| 189 |
RETVAL=$? |
| 190 |
rm -f $PIDFILE |
| 191 |
return "$RETVAL" |
| 192 |
} |
| 193 |
|
| 194 |
do_systemd_start() { |
| 195 |
# Set umask to ensure log files are created with 0644 mode bits |
| 196 |
# Note we can't set 0026 to have files 0640, because that's going |
| 197 |
# to be in use in for example neutron-dhcp-agent, which makes it |
| 198 |
# so it wont be able to read /var/lib/neutron/external/pids/*.pid.haproxy |
| 199 |
# and then fail hardly. However, 0022 is enough, since the log |
| 200 |
# folders are owned by <project>:adm, so users don't have access |
| 201 |
# to it unless they are on the adm group, which is what we want. |
| 202 |
umask 0022 |
| 203 |
if [ -n "${PYARGV}" ] ; then |
| 204 |
exec $DAEMON $DAEMON_ARGS --pyargv "${PYARGV}" |
| 205 |
else |
| 206 |
exec $DAEMON $DAEMON_ARGS |
| 207 |
fi |
| 208 |
} |
| 209 |
|
| 210 |
case "$1" in |
| 211 |
start) |
| 212 |
log_daemon_msg "Starting $DESC" "$NAME" |
| 213 |
do_start |
| 214 |
case $? in |
| 215 |
0|1) log_end_msg 0 ; RET=$? ;; |
| 216 |
2) log_end_msg 1 ; RET=$? ;; |
| 217 |
esac |
| 218 |
;; |
| 219 |
stop) |
| 220 |
log_daemon_msg "Stopping $DESC" "$NAME" |
| 221 |
do_stop |
| 222 |
case $? in |
| 223 |
0|1) log_end_msg 0 ; RET=$? ;; |
| 224 |
2) log_end_msg 1 ; RET=$? ;; |
| 225 |
esac |
| 226 |
;; |
| 227 |
status) |
| 228 |
status_of_proc "$DAEMON" "$NAME" |
| 229 |
RET=$? |
| 230 |
;; |
| 231 |
systemd-start) |
| 232 |
do_systemd_start |
| 233 |
;; |
| 234 |
show-args) |
| 235 |
if [ -n "${PYARGV}" ] ; then |
| 236 |
echo $DAEMON $DAEMON_ARGS --pyargv \"${PYARGV}\" |
| 237 |
else |
| 238 |
echo $DAEMON $DAEMON_ARGS |
| 239 |
fi |
| 240 |
;; |
| 241 |
restart|force-reload) |
| 242 |
log_daemon_msg "Restarting $DESC" "$NAME" |
| 243 |
do_stop |
| 244 |
case $? in |
| 245 |
0|1) |
| 246 |
do_start |
| 247 |
case $? in |
| 248 |
0) log_end_msg 0 ; RET=$? ;; |
| 249 |
1) log_end_msg 1 ; RET=$? ;; # Old process is still running |
| 250 |
*) log_end_msg 1 ; RET=$? ;; # Failed to start |
| 251 |
esac |
| 252 |
;; |
| 253 |
*) log_end_msg 1 ; RET=$? ;; # Failed to stop |
| 254 |
esac |
| 255 |
;; |
| 256 |
*) |
| 257 |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|systemd-start}" >&2 |
| 258 |
RET=3 |
| 259 |
;; |
| 260 |
esac |
| 261 |
|
| 262 |
exit $RET |