Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4560272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:54:27+00:00 2026-05-21T17:54:27+00:00

I have several rails applications deployed by nginx passenger. I want those applications to

  • 0

I have several rails applications deployed by nginx passenger. I want those applications to be monitored by using monit. How can I monitor those applications using monit? Should I monitor nginx as well?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:54:27+00:00Added an answer on May 21, 2026 at 5:54 pm

    This is how I solved this. First, I added to application.rb:

    
    # Monit support
    if defined?(PhusionPassenger)
      require 'pidfile_manager'
      PhusionPassenger.on_event(:starting_worker_process) do |forked|
        if forked
          # We're in smart spawning mode.
          PidfileManager.write_pid_file
        else
          # We're in conservative spawning mode. We don't need to do anything.
        end
      end
    
      PhusionPassenger.on_event(:stopping_worker_process) do
        PidfileManager.remove_pid_file
      end
    end
    

    and then I implemented the PidfileManager:

    
    module PidfileManager
      extend self
    
      BASENAME = '/var/tmp/rack.*.pid'
    
      def write_pid_file
        pid = Process.pid
        count = 1
        pidfile = nil
        go_over_pid_files do |file, saved_pid|
          file_id = file[/(\d+)/,1].to_i
          # Increase counter only if we met the same file id
          count += 1 if file_id == count
          # We're already there
          return if saved_pid == pid
          # Check if the process is alive
          res = begin
            Process.kill(0, saved_pid)
          rescue Errno::ESRCH
            nil
          end
          # It's dead, reuse
          unless res
            pidfile = file
            break
          end
        end
        pidfile ||= BASENAME.sub('*', count.to_s)
        File.open(pidfile, 'w') {|f| f.write(pid.to_s)}
      end
    
      def remove_pid_file
        pid = Process.pid
        go_over_pid_files do |file, saved_pid|
          if pid == saved_pid
            File.unlink(file)
            break
          end
        end
      end
    
      private
      def go_over_pid_files
        Dir[BASENAME].each do |file|
          saved_pid = File.read(file).to_i
          yield file, saved_pid
        end
      end
    
    end
    

    And then you just tell monit to monitor each instance using /var/tmp/rack.X.pid as a pidfile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails 3.2.2 app with patients who can have several types of
I have a rails application using cancan, and there are several different roles that
I have a rails application that I deploy on Heroku. I'm using several different
I'm not sure if I am using the correct term. I have several Nginx
The main idea is that I have several worker instances of a Rails app,
I'm a rails beginner and have been several hours now trying to figure out
I have several xml files with different node structure. I want to extract xml
we have several tens of macro enabled excel files, each of those contains few
I have one 'super' repository in GitHub which will contain several applications I would
I have deployed a Rails application on Heroku (web-server thin). When I push it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.