Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Register
    • Login
    Introducing Netgate Nexus: Multi-Instance Management at Your Fingertips.

    Proxy_monitor.sh fixed

    Scheduled Pinned Locked Moved pfSense Packages
    3 Posts 3 Posters 1.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      chudy
      last edited by

      I'm always monitoring squid. proxy_monitor.sh doesn't work as expected. so I've modified some. now its final.

      
      #!/bin/sh
      set -e
      LOOP_SLEEP=10
      sleep 5
      while [ /bin/true ] ; do
              if [  ! -f /var/run/squid_alarm ]; then
                      NUM_PROCS=`ps auxw | grep "(squid) -D" | grep -v grep |awk '{print $2}'| wc -l | awk '{ print $1 }'`
                      if [ $NUM_PROCS -lt 1 ]; then
                              echo "Squid has exited.  Reconfiguring filter." | \
                                      logger -p daemon.info -i -t Squid_Alarm
                              /etc/rc.filter_configure_sync
                              echo "Attempting restart..." | logger -p daemon.info -i -t Squid_Alarm
                              /usr/local/etc/rc.d/squid.sh start
      #if error squid will retry 5 times for about 13secs trying to run squid child process so wait 15secs.
                              sleep 15
                              touch /var/run/squid_alarm
                      fi
              fi
              NUM_PROCS=`ps auxw | grep "(squid) -D"| grep -v grep |awk '{print $2}'| wc -l | awk '{ print $1 }'`
              if [ $NUM_PROCS -gt 0 ]; then
                      if [ -f /var/run/squid_alarm ]; then
                              echo "Squid has resumed. Reconfiguring filter." | \
                                      logger -p daemon.info -i -t Squid_Alarm
                              /etc/rc.filter_configure_sync
                              rm /var/run/squid_alarm
                      fi
              fi
              sleep $LOOP_SLEEP
      done
      
      

      service-utils.inc sees anything squid from process as service even```
      tail -f /var/squid/log/cache.log

      This is why /etc/rc.filter_configure_sync won't remove redirect from pf nat :( so be careful when debugging squid ;)
      To fix that.Modify squid.inc to double check if squid -D is running(squid name in path. services detects squid is running)
      
      	$squid_conf = $config['installedpackages']['squid']['config'][0];
      if ((!is_service_running('squid')) || (!is_process_running('squid -D'))){
      	log_error("SQUID is installed but not started.  Not installing redirect rules.");
      	return;
      }
      
      but there's always a better way than proxy_monitor.sh which will exactly run script when squid dies or shutdown.
      1 Reply Last reply
      Reply Quote 0
      • K
        ktims
        last edited by

        It works, and in this situation has the identical meaning.

        1 Reply Last reply
        Reply Quote 0
        • S
          serangku
          last edited by

          may i know … what this goal ? btw, i would like to try it soon  :)

          1 Reply Last reply
          Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          Copyright 2026 Rubicon Communications LLC (Netgate). All rights reserved.
          Privacy Policy · Cookie Policy