# Bin/mongrel\_rails to make it play nice with monit

**URL:** <https://www.ruby-forum.com/t/bin-mongrel-rails-to-make-it-play-nice-with-monit/119429>\
**Category:** Rails\
**Created:** [November 6, 2007, 11:34pm UTC](https://www.ruby-forum.com/t/bin-mongrel-rails-to-make-it-play-nice-with-monit/119429 "2007-11-06T23:34:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![uncle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e5b9ba/32.png) [@uncle](https://www.ruby-forum.com/u/uncle)\
**Post date:** [November 6, 2007, 11:34pm UTC](https://www.ruby-forum.com/t/bin-mongrel-rails-to-make-it-play-nice-with-monit/119429/1 "2007-11-06T23:34:26Z")

</div>

Looks like the mongrel\_rails command in mongrel 1.1 still does not fix  
(or include an option) the issue of stale pid files. mongrel\_rails  
will just exit if a pid exists without first checking if anything is  
actually running. You can use this script to patch up  
mongrel\_rails…

#===== patch mongrel  
cd /usr/lib/ruby/gems/1.8/gems/mongrel-1.1/bin/  
cp mongrel\_rails mongrel\_rails.orig  
patch -p0 \<\< ‘EOF’  
— mongrel\_rails 2007-05-08 11:18:32.000000000 -0500  
+++ mongrel\_rails.new 2007-05-08 11:18:32.000000000 -0500  
@@ -83,10 +83,20 @@  
config = Mongrel::Rails::RailsConfigurator.new(settings) do  
if defaults[:daemon]  
if File.exist? defaults[:pid\_file]

- 

```
       log "!!! PID file #{defaults[:pid_file]} already exists.

```

Mongrel could be running already. Check your #{defaults[:log\_file]}  
for errors."

- 

```
       log "!!! Exiting with error. You must stop mongrel and

```

clear the .pid before I’ll attempt a start."

- 

```
       exit 1

```

- 

```
       pid = File.new(defaults[:pid_file]).readline

```

- 

```
       if `ps --pid #{pid} --no-headers`.length > 0

```

- 

```
           log "!!! PID file #{defaults[:pid_file]} already

```

exists and the process id referenced is running. This mongrel is  
probably already running. #{defaults[:log\_file]} for errors.  
EXITING."

- 

```
           exit 1

```

- 

```
       else

```

- 

```
           log "!!! PID file #{defaults[:pid_file]} exists, but

```

is stale, and will be deleted so that this mongrel can run."

- 

```
           File.delete(defaults[:pid_file])

```

- 

```
       end
     end

```

+# if File.exist? defaults[:pid\_file]  
+# log “!!! PID file #{defaults[:pid\_file]} already  
exists. Mongrel could be running already. Check your  
#{defaults[:log\_file]} for errors.”  
+# log “!!! Exiting with error. You must stop mongrel and  
clear the .pid before I’ll attempt a start.”  
+# exit 1  
+# end

```
       daemonize
       log "Daemonized, any open files are closed. Look at

```

#{defaults[:pid\_file]} and #{defaults[:log\_file]} for info."  
EOF

---

<div class="post-metadata">

**Author:** ![uncle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e5b9ba/32.png) [@uncle](https://www.ruby-forum.com/u/uncle)\
**Post date:** [November 7, 2007, 1:33am UTC](https://www.ruby-forum.com/t/bin-mongrel-rails-to-make-it-play-nice-with-monit/119429/2 "2007-11-07T01:33:51Z")

</div>

On Nov 6, 2007 5:33 PM, uncle [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Looks like the mongrel\_rails command in mongrel 1.1 still does not fix  
> (or include an option) the issue of stale pid files. mongrel\_rails  
> will just exit if a pid exists without first checking if anything is  
> actually running. You can use this script to patch up  
> mongrel\_rails…

Maybe it’s specific to mongrel\_cluster, but I thought there was a new  
–clean option to take care of this.

Michael G.
