• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS.

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