@@ -240,6 +240,51 @@ if migrating_postgres; then
240
240
safe_cp " $PREFIX /share" postgresql " $BACKUP_DIR /share"
241
241
fi
242
242
243
+ #
244
+ # We check if there is a server listening on port 9000.
245
+ # If one is found and belongs to CFEngine,
246
+ # then we try to shut it down using fuser.
247
+ # If that does not work, we abort the installation.
248
+ #
249
+ ensure_php_fpm_terminated () {
250
+ PHP_FPM_RUNNING=$( filter_netstat_listen " :9000\\ s" )
251
+ if [ -z " $PHP_FPM_RUNNING " ]; then
252
+ return 0;
253
+ fi
254
+
255
+ cf_console echo " There seems to be a server listening on port 9000."
256
+
257
+ phpfpmpid=$( echo " $PHP_FPM_RUNNING " | sed -r -e ' /pid=/!d' -e ' s/.*pid=([0-9]+),.*/\1/' | tail -1)
258
+ phpfpmargs=$( ps -p " $phpfpmpid " -o args=)
259
+
260
+ if echo " $phpfpmargs " | grep -q " cfengine" ; then
261
+ cf_console echo " The PHP-FPM process belongs to a previous CFEngine deployment, shutting it down."
262
+ cf_console echo " Attempting to terminate the process using fuser."
263
+ if ! command -v fuser > /dev/null; then
264
+ cf_console echo " fuser not available, can't kill!"
265
+ return 1
266
+ fi
267
+
268
+ fuser -k -TERM -n tcp 9000
269
+
270
+ sleep 5s
271
+ PHP_FPM_FINAL_CHECK=$( filter_netstat_listen " :9000\\ s" )
272
+ if [ -n " $PHP_FPM_FINAL_CHECK " ]; then
273
+ cf_console echo " There is still a process listening on port 9000. Please kill it manually before retrying. Aborting."
274
+ return 1
275
+ fi
276
+ else
277
+ cf_console echo " The PHP-FPM process is not from a previous CFEngine deployment"
278
+ cf_console echo " This scenario is not supported, aborting installation"
279
+ ps -p ` fuser -n tcp 9000 2> /dev/null` -o args=
280
+ return 1
281
+ fi
282
+
283
+ return 0
284
+ }
285
+
286
+ ensure_php_fpm_terminated || exit 1
287
+
243
288
#
244
289
# We check if there is a server listening on port 80 or port 443.
245
290
# If one is found, then we try to shut it down by calling
0 commit comments