Question: I want to create a cront tab to restart my delayed\_job server if it breaks.

how may check that my delayed\_job server is running or not with ps command?

how may i create a cron tab to check this thing work? Like if my server break than cron tab will restart it. I want to set cront tab to check it every 5 minute.

Answer: 
This is my script which check if pid files is created or not. If pid file is not exist than it will start the delayed\_job server.
I have created my script in my application root folder
This is my script delayed\_job.sh

```
if ! [ -s delayed_job.pids ]; then
  RAILS_ENV=production /app/script/delayed_job start
end

```

And i have set this script on crontab like this.

```
*/5 * * * * RAILS_ENV=production /bin/bash /app/delayed_job.sh

```

It's working fine. If i break delayed\_job server than it will automatically start my delayed\_job server. Is it a proper way??
Here's my solution. I check for whether you have a single job started or you have more than one. If you do, quit, otherwise start the job with two workers. You probably won't need that `/usr/local/bin/ruby` part. 

```
#!/bin/bash

if [[ ! -f /apps/gits/myapp/tmp/pids/delayed_job.pid 
      && ! -f /apps/gits/myapp/tmp/pids/delayed_job.0.pid ]];
then
  echo "DJ not running" 
  cd /apps/gits/myapp
  RAILS_ENV=production /usr/local/bin/ruby script/delayed_job -n 2 start
  echo "DJ Started"
else
  echo "DJ running"
fi

```

And then my cron runs every hour, just make sure the bash is executable. 

```
0 */1 * * * /apps/gits/scripts/start_dj_if_not_running.sh 
               >> /apps/gits/myapp/log/runner.log 2>&1

```