title: Bash: Continuously check processes running or not with some parameters
body: <p>I want to create script that will check continuously process status running or not. If process will not run, script should catch it and restart it in a seconds. How can I run continuously this script on the system and how should I change the script via ---&gt; Important points: it should take as parameters these: 1-seconds to wait between attempts to restart service, 2- number of attempts and 3- generate logs of events. Nginx is a example for the process. It can be replaceable.</p>
  <pre><code>#!/bin/bash 
  SERVICE=&quot;nginx&quot; 
  if pgrep -x &quot;$SERVICE&quot; &gt;/dev/null 
  then 
      echo &quot;$SERVICE is running&quot; 
  else 
      echo &quot;$SERVICE stopped&quot; 
      # start nginx if stopped 
      echo &quot;$SERVICE starting&quot; 
      systemctl start $SERVICE
  fi
  </code></pre>