• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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