title: Is there a way to restart pm2 process using cron but only if it's not already running?
body: <p>I want to restart my Node.Js app using PM2 through </p>
  
  <p><code>pm2 restart app.js</code></p>
  
  <p>using crontab but ONLY if the app is not already running (e.g. if my server crashed and restarted and pm2 didn't restart). </p>
  
  <p>the command above restarts it anyway even if it's running. </p>
  
  <p>How do I fix it?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I do not want my app to restart if it's already running. I want it to restart <em>only</em> if it's listed as "stopped" or if it is not running.
  Some suggestions offer to write a bash script, but what would it be? I tried the options below, but they either don't work or restart the app even if it's running.</p>