• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

Issue Nginx not starting after reboot

Alireza Famili

Basic Pleskian
I rarely ever restart my server, but just in case.....
I have this watchdog which starts nginx (or some other service) whenever it's not running.
Because I don't want to write a different watchdog for each server I wrote something that should work in most cases by just using the name of the service in the symbolic link.

My watchdog is working for
Code:
watch-mysql
watch-nginx
watch-redis-server
watch-zabbix-agent
watch-syncthing
watch-rslsync

grep cron.5min /etc/crontab
Code:
*/5  *  *   *   * root   cd / && run-parts /etc/cron.5min

cat /usr/local/sbin/watch-process
ln -s /usr/local/sbin/watch-process /etc/cron.5min/watch-nginx
Code:
#!/bin/bash

PROCESS="`echo $0 | grep -o 'watch-.*' | cut -b7-`"
THIS_SCRIPT="`readlink $0`"
SCRIPTNAME=${THIS_SCRIPT##*/}

if [ -z "${PROCESS}" ] ; then
  echo "Wrong usage: make a symbolic link to ${THIS_SCRIPT} named watch-<service>" >&2
  exit 1
elif [ "watch-${PROCESS}" = "${SCRIPTNAME}" ]  ; then
  echo "Wrong usage: make a symbolic link to ${THIS_SCRIPT} named watch-<service>" >&2
  exit 1
fi

USER="`echo ${PROCESS} | awk -F- '{print $1}' | cut -b1-7`"
USERID="`grep "^${USER}" /etc/passwd | awk -F: '{print $3}'`"
SEARCH="`echo ${PROCESS} | tr - .`"
SERVICE=`find /etc/init.d/ -maxdepth 1 -type f | grep ${SEARCH} | head -n1`

if ! grep -q ${USER} /etc/passwd ; then
  echo "${USER} does not exist, service is not installed" >&2
  exit 1
fi
if [ -z "${SERVICE}" ] ; then
  echo "${SERVICE} is not installed as service" >&2
  exit 1
elif [ ! -x ${SERVICE} ] ; then
  echo "${SERVICE} is a DISABLED service" >&2
  exit 1
fi

ps aux | egrep "^(${USER}|${USERID} )" | grep -q " .*${SEARCH}" && exit 0

echo "`date +%b' '%d' '%H:%M:%S` Watchdog $0 invokes \"${SERVICE} start\"" | tee -a /var/log/${SCRIPTNAME}.log >&2

${SERVICE} start
 
Back
Top