File: init-script-template

package info (click to toggle)
openstack-pkg-tools 117
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 904 kB
  • sloc: sh: 3,994; makefile: 31
file content (226 lines) | stat: -rw-r--r-- 6,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
# The content after this line comes from openstack-pkg-tools
# and has been automatically added to a .init.in script, which
# contains only the descriptive part for the daemon. Everything
# else is standardized as a single unique script.

# Author: Thomas Goirand <zigo@debian.org>
# Author: Ondřej Nový <novy@ondrej.org>

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin

if [ -n "${UWSGI_PORT}" ] && [ -n "${UWSGI_INI_PATH}" ] && [ -n "${UWSGI_INI_APP}" ] ; then
	if ! [ -f "${UWSGI_INI_APP}" ] ; then
		exit 0
	fi
	if [ -d /etc/${PROJECT_NAME}/ssl/private ] ; then
		KEY_FILE=$(find /etc/${PROJECT_NAME}/ssl/private -type f -iname '*.pem' 2>/dev/null | head -n 1)
	fi

	if [ -e /usr/local/share/ca-certificates/puppet_openstack.crt ] ; then
		# This is needed for puppet...
		CERT_FILE=/usr/local/share/ca-certificates/puppet_openstack.crt
	else
		if [ -d /etc/${PROJECT_NAME}/ssl/public ] ; then
			CERT_FILE=$(find /etc/${PROJECT_NAME}/ssl/public -type f -iname '*.crt' 2>/dev/null | head -n 1)
		fi
	fi

	# Sid doesn't have /usr/bin/uwsgi_python3, so we need
	# to search for a more specific daemon name. For stretch
	# /usr/bin/uwsgi_python3 is fine.
	for i in 3 35 36 37 38 39 ; do
		if [ -x /usr/bin/uwsgi_python${i} ] ; then
			DAEMON=/usr/bin/uwsgi_python${i}
		fi
	done

	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
		. /usr/share/openstack-pkg-tools/pkgos_func
		pkgos_inifile get ${UWSGI_BIND_CONFIG_FILE} ${UWSGI_BIND_CONFIG_SECTION} ${UWSGI_BIND_CONFIG_IP_DIRECTIVE}
	        if [ -n "${RET}" ] && [ ! "${RET}" = "NOT_FOUND" ] ; then
			UWSGI_BIND_IP=${RET}
		fi
		pkgos_inifile get ${UWSGI_BIND_CONFIG_FILE} ${UWSGI_BIND_CONFIG_SECTION} ${UWSGI_BIND_CONFIG_PORT_DIRECTIVE}
	        if [ -n "${RET}" ] && [ ! "${RET}" = "NOT_FOUND" ] ; then
			UWSGI_PORT=${RET}
		fi
		if [ -n "${UWSGI_BIND_CONFIG_WORKERS_DIRECTIVE}" ] ; then
			pkgos_inifile get ${UWSGI_BIND_CONFIG_FILE} ${UWSGI_BIND_CONFIG_SECTION} ${UWSGI_BIND_CONFIG_WORKERS_DIRECTIVE}
		        if [ -n "${RET}" ] && [ ! "${RET}" = "NOT_FOUND" ] ; then
				UWSGI_PROCESSES=" --processes ${RET}"
			else
				# If we can't find the directive in the config file,
				# we fallback to the number of thread / 2.
				UWSGI_PROCESSES=" --processes "$(( $(nproc) / 2 ))
			fi
		fi
	else
		UWSGI_BIND_IP=""
	fi

	if [ -n "${KEY_FILE}" ] && [ -n "${CERT_FILE}" ] ; then
		DAEMON_ARGS="--https-socket ${UWSGI_BIND_IP}:${UWSGI_PORT},${CERT_FILE},${KEY_FILE}${UWSGI_PROCESSES}"
	else
		DAEMON_ARGS="--http-socket ${UWSGI_BIND_IP}:${UWSGI_PORT}${UWSGI_PROCESSES}"
	fi

	DAEMON_ARGS="${DAEMON_ARGS} --ini ${UWSGI_INI_PATH}"
	NO_OPENSTACK_CONFIG_FILE_DAEMON_ARG=yes
	NO_OPENSTACK_LOGFILE_DAEMON_ARG=yes
fi

if [ -z "${DAEMON}" ] ; then
	DAEMON=/usr/bin/${NAME}
fi
PIDFILE=/var/run/${PROJECT_NAME}/${NAME}.pid
if [ -z "${SCRIPTNAME}" ] ; then
	SCRIPTNAME=/etc/init.d/${NAME}
fi
if [ -z "${SYSTEM_USER}" ] ; then
	SYSTEM_USER=${PROJECT_NAME}
fi
if [ -z "${SYSTEM_GROUP}" ] ; then
	SYSTEM_GROUP=${PROJECT_NAME}
fi
if [ "${SYSTEM_USER}" != "root" ] ; then
	STARTDAEMON_CHUID="--chuid ${SYSTEM_USER}:${SYSTEM_GROUP}"
fi
if [ -z "${CONFIG_FILE}" ] ; then
	CONFIG_FILE=/etc/${PROJECT_NAME}/${PROJECT_NAME}.conf
fi
LOGFILE=/var/log/${PROJECT_NAME}/${NAME}.log
if [ -z "${NO_OPENSTACK_CONFIG_FILE_DAEMON_ARG}" ] ; then
	DAEMON_ARGS="--config-file=${CONFIG_FILE} ${DAEMON_ARGS}"
fi

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0

# If ran as root, create /var/lock/X, /var/run/X and /var/cache/X as needed
if [ `whoami` = "root" ] ; then
	for i in lock run cache ; do
		mkdir -p /var/$i/${PROJECT_NAME}
		chown ${SYSTEM_USER}:${SYSTEM_GROUP} /var/$i/${PROJECT_NAME}
	done
fi

# This defines support functions which we use later on
. /lib/lsb/init-functions

RET=0

# Manage log options: logfile and/or syslog, depending on user's choosing
[ -r /etc/default/openstack ] && . /etc/default/openstack
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
[ "x$USE_SYSLOG" = "xyes" ] && DAEMON_ARGS="$DAEMON_ARGS --use-syslog"
if [ -z "${NO_OPENSTACK_LOGFILE_DAEMON_ARG}" ] ; then
	[ "x$USE_LOGFILE" != "xno" ] && DAEMON_ARGS="$DAEMON_ARGS --log-file=$LOGFILE"
fi

do_start() {
	start-stop-daemon \
		--start \
		--quiet \
		--background ${STARTDAEMON_CHUID} \
		--make-pidfile --pidfile ${PIDFILE} \
		--chdir /var/lib/${PROJECT_NAME} \
		--startas $DAEMON \
		--test > /dev/null \
		|| return 1
	if [ -n "${PYARGV}" ] ; then
		start-stop-daemon \
			--start \
			--quiet \
			--background ${STARTDAEMON_CHUID} \
			--make-pidfile --pidfile ${PIDFILE} \
			--chdir /var/lib/${PROJECT_NAME} \
			--startas $DAEMON \
			-- $DAEMON_ARGS --pyargv "${PYARGV}" \
			|| return 2
	else
		start-stop-daemon \
			--start \
			--quiet \
			--background ${STARTDAEMON_CHUID} \
			--make-pidfile --pidfile ${PIDFILE} \
			--chdir /var/lib/${PROJECT_NAME} \
			--startas $DAEMON \
			-- $DAEMON_ARGS \
			|| return 2
	fi
}

do_stop() {
	start-stop-daemon \
		--stop \
		--quiet \
		--retry=TERM/30/KILL/5 \
		--pidfile $PIDFILE
	RETVAL=$?
	rm -f $PIDFILE
	return "$RETVAL"
}

do_systemd_start() {
	if [ -n "${PYARGV}" ] ; then
		exec $DAEMON $DAEMON_ARGS --pyargv "${PYARGV}"
	else
		exec $DAEMON $DAEMON_ARGS
	fi
}

case "$1" in
start)
	log_daemon_msg "Starting $DESC" "$NAME"
	do_start
	case $? in
		0|1) log_end_msg 0 ; RET=$? ;;
		2)   log_end_msg 1 ; RET=$? ;;
	esac
;;
stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case $? in
		0|1) log_end_msg 0 ; RET=$? ;;
		2)   log_end_msg 1 ; RET=$? ;;
	esac
;;
status)
	status_of_proc "$DAEMON" "$NAME"
	RET=$?
;;
systemd-start)
	do_systemd_start
;;  
show-args)
	if [ -n "${PYARGV}" ] ; then
		echo $DAEMON $DAEMON_ARGS --pyargv \"${PYARGV}\"
	else
		echo $DAEMON $DAEMON_ARGS
	fi
;;
restart|force-reload)
	log_daemon_msg "Restarting $DESC" "$NAME"
	do_stop
	case $? in
		0|1)
			do_start
			case $? in
				0) log_end_msg 0 ; RET=$? ;;
				1) log_end_msg 1 ; RET=$? ;; # Old process is still running
				*) log_end_msg 1 ; RET=$? ;; # Failed to start
			esac
		;;
		*) log_end_msg 1 ; RET=$? ;; # Failed to stop
	esac
;;
*)
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|systemd-start}" >&2
	RET=3
;;
esac

exit $RET