<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Monitor running processes with Perl	</title>
	<atom:link href="https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/feed/" rel="self" type="application/rss+xml" />
	<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/</link>
	<description>Ramblings of an old-fashioned space cowboy</description>
	<lastBuildDate>Wed, 20 Apr 2022 07:18:55 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>
		By: Chris Fowler		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252916</link>

		<dc:creator><![CDATA[Chris Fowler]]></dc:creator>
		<pubDate>Sun, 18 Dec 2016 21:50:25 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-252916</guid>

					<description><![CDATA[I run a lot of mysqld slaves on one host has hot spares for many systems over direct VPN connections.  The systems have a P-t-P VPN directly to the backup system.  When I need to reset replication I sometimes run into a problem shutting down the slave for that instance.  

A bit of test code to solve it.  Of course use mysqladmin to shutdown that instance first.  I only bring this up because I just reset an instance and mysqladmin was in a constant loop of connection.  The pid file was there, but the service for that one was not.  

sub get_pid {
  my $re = shift;
  my $processes = Proc::ProcessTable-&#062;new();
  foreach my $p (@{ $processes-&#062;table() }){
    if($p-&#062;{&#039;cmndline&#039;} =~ m#$re#) {
      # Winner Winner Chicken Dinner
      return $p-&#062;{&#039;pid&#039;};
    }
  }

  return 0;
}


my $pid = get_pid(&#039;mysqld_safe.+15034.+&#039;);
printf &quot;PID: %d\n&quot;, $pid;
my $pid = get_pid(&#039;mysqld .+15034.+&#039;);
printf &quot;PID: %d\n&quot;, $pid;]]></description>
			<content:encoded><![CDATA[<p>I run a lot of mysqld slaves on one host has hot spares for many systems over direct VPN connections.  The systems have a P-t-P VPN directly to the backup system.  When I need to reset replication I sometimes run into a problem shutting down the slave for that instance.  </p>
<p>A bit of test code to solve it.  Of course use mysqladmin to shutdown that instance first.  I only bring this up because I just reset an instance and mysqladmin was in a constant loop of connection.  The pid file was there, but the service for that one was not.  </p>
<p>sub get_pid {<br />
  my $re = shift;<br />
  my $processes = Proc::ProcessTable-&gt;new();<br />
  foreach my $p (@{ $processes-&gt;table() }){<br />
    if($p-&gt;{&#8216;cmndline&#8217;} =~ m#$re#) {<br />
      # Winner Winner Chicken Dinner<br />
      return $p-&gt;{&#8216;pid&#8217;};<br />
    }<br />
  }</p>
<p>  return 0;<br />
}</p>
<p>my $pid = get_pid(&#8216;mysqld_safe.+15034.+&#8217;);<br />
printf &#8220;PID: %d\n&#8221;, $pid;<br />
my $pid = get_pid(&#8216;mysqld .+15034.+&#8217;);<br />
printf &#8220;PID: %d\n&#8221;, $pid;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chris Fowler		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252913</link>

		<dc:creator><![CDATA[Chris Fowler]]></dc:creator>
		<pubDate>Thu, 15 Dec 2016 17:23:24 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-252913</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252912&quot;&gt;Johnny Morano&lt;/a&gt;.

I can&#039;t say I have any suggestions that would make your script better.  My changes are specific to what I&#039;m doing and I&#039;d thought you&#039;d be interested in seeing how I applied it to the problems I&#039;m facing.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252912">Johnny Morano</a>.</p>
<p>I can&#8217;t say I have any suggestions that would make your script better.  My changes are specific to what I&#8217;m doing and I&#8217;d thought you&#8217;d be interested in seeing how I applied it to the problems I&#8217;m facing.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Johnny Morano		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252912</link>

		<dc:creator><![CDATA[Johnny Morano]]></dc:creator>
		<pubDate>Thu, 15 Dec 2016 10:14:15 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-252912</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252910&quot;&gt;Chris Fowler&lt;/a&gt;.

Hi Chris

I&#039;d be more than happy to see your suggestions or corrections ;)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252910">Chris Fowler</a>.</p>
<p>Hi Chris</p>
<p>I&#8217;d be more than happy to see your suggestions or corrections 😉</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chris Fowler		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252911</link>

		<dc:creator><![CDATA[Chris Fowler]]></dc:creator>
		<pubDate>Thu, 15 Dec 2016 03:59:27 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-252911</guid>

					<description><![CDATA[I&#039;ll add one more comment.

My original approach at keeping these programs up is to run each process in the foreground under a parent.  On SIGCHLD the parent makes a note and starts it back up.

I never considered the approach of just monitoring /proc.  That can be difficult, but I also never considered using a regular expression as a check either.  

As a daemon I do run the risk of it dying.  Your solution was cron.  Since only one can run on a system I typically lock $0 and check iton startup to make sure another copy is not running.  Using that idea I can stay a daemon and cron could try to start it every hour.  It&#039;ll just fail to lock and exit.  If it died within that 30 minute cycle it would run again.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll add one more comment.</p>
<p>My original approach at keeping these programs up is to run each process in the foreground under a parent.  On SIGCHLD the parent makes a note and starts it back up.</p>
<p>I never considered the approach of just monitoring /proc.  That can be difficult, but I also never considered using a regular expression as a check either.  </p>
<p>As a daemon I do run the risk of it dying.  Your solution was cron.  Since only one can run on a system I typically lock $0 and check iton startup to make sure another copy is not running.  Using that idea I can stay a daemon and cron could try to start it every hour.  It&#8217;ll just fail to lock and exit.  If it died within that 30 minute cycle it would run again.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chris Fowler		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252910</link>

		<dc:creator><![CDATA[Chris Fowler]]></dc:creator>
		<pubDate>Thu, 15 Dec 2016 03:54:26 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-252910</guid>

					<description><![CDATA[I ran into an issue a while back where I believe a STUN event in VMWare caused a few processes to die in a guest.  Each group has a manager, but this group did not.  I was going to copy a manager from another group, modify it, and if it manage this group.  I decided to extend your idea instead.

I use databases to create a concept of &quot;organizations&quot;.  Each daemon type will spawn one child per org.  That is why I started from a manager.

I extended your code to have a default section for $services.  I then build the other sections off the database.  Instead of a cron job I&#039;m am doing daemon.  When changes are made to an org a daemon from a group will be restarted.  In your program I implemented a UNIX socket where I could connect, dump status, disable a program, enable a program, stop, etc.  

Each org does have an org_config table that I use to disable a program there.  When building the config I check that.  I also check for config changes each 120s cycle.  Before, when I added an org I had to restart the whole group.  With the mods I done with your program I just create it and it works.

I did this as  rush for that one VMware incident and feature creep hit at light speed.  It is a mess so I&#039;ll clean it up and send it to you.  You can contact me via my email if you wish.

Chris]]></description>
			<content:encoded><![CDATA[<p>I ran into an issue a while back where I believe a STUN event in VMWare caused a few processes to die in a guest.  Each group has a manager, but this group did not.  I was going to copy a manager from another group, modify it, and if it manage this group.  I decided to extend your idea instead.</p>
<p>I use databases to create a concept of &#8220;organizations&#8221;.  Each daemon type will spawn one child per org.  That is why I started from a manager.</p>
<p>I extended your code to have a default section for $services.  I then build the other sections off the database.  Instead of a cron job I&#8217;m am doing daemon.  When changes are made to an org a daemon from a group will be restarted.  In your program I implemented a UNIX socket where I could connect, dump status, disable a program, enable a program, stop, etc.  </p>
<p>Each org does have an org_config table that I use to disable a program there.  When building the config I check that.  I also check for config changes each 120s cycle.  Before, when I added an org I had to restart the whole group.  With the mods I done with your program I just create it and it works.</p>
<p>I did this as  rush for that one VMware incident and feature creep hit at light speed.  It is a mess so I&#8217;ll clean it up and send it to you.  You can contact me via my email if you wish.</p>
<p>Chris</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Albert Roberson		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252779</link>

		<dc:creator><![CDATA[Albert Roberson]]></dc:creator>
		<pubDate>Mon, 08 Aug 2016 21:32:15 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-252779</guid>

					<description><![CDATA[My question can be ignored. I got the source from github and it has the corrections in it that make the file work like a charm. Very useful tool. Thank you.]]></description>
			<content:encoded><![CDATA[<p>My question can be ignored. I got the source from github and it has the corrections in it that make the file work like a charm. Very useful tool. Thank you.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Albert Roberson		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-252778</link>

		<dc:creator><![CDATA[Albert Roberson]]></dc:creator>
		<pubDate>Mon, 08 Aug 2016 20:49:35 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-252778</guid>

					<description><![CDATA[Using the code above, I get the error &quot;Not an ARRAY reference at wd.pl line 48&quot;, which for me is the line stating:

foreach my $p (@{ $processes }){

Is this due to some change in the module, or in perl?]]></description>
			<content:encoded><![CDATA[<p>Using the code above, I get the error &#8220;Not an ARRAY reference at wd.pl line 48&#8221;, which for me is the line stating:</p>
<p>foreach my $p (@{ $processes }){</p>
<p>Is this due to some change in the module, or in perl?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Euler Sánchez		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-26396</link>

		<dc:creator><![CDATA[Euler Sánchez]]></dc:creator>
		<pubDate>Sat, 31 May 2014 08:01:42 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-26396</guid>

					<description><![CDATA[Very nice post. :) Thanks]]></description>
			<content:encoded><![CDATA[<p>Very nice post. 🙂 Thanks</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Johnny Morano		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-25806</link>

		<dc:creator><![CDATA[Johnny Morano]]></dc:creator>
		<pubDate>Fri, 30 May 2014 09:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-25806</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-25408&quot;&gt;Buddy Burden&lt;/a&gt;.

Yeah you&#039;re right! I have updated this blog post once more ;-)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-25408">Buddy Burden</a>.</p>
<p>Yeah you&#8217;re right! I have updated this blog post once more 😉</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Buddy Burden		</title>
		<link>https://jmorano.moretrix.com/2014/05/monitor-running-processes-with-perl/#comment-25408</link>

		<dc:creator><![CDATA[Buddy Burden]]></dc:creator>
		<pubDate>Thu, 29 May 2014 18:16:20 +0000</pubDate>
		<guid isPermaLink="false">http://jmorano.moretrix.com/?p=1081#comment-25408</guid>

					<description><![CDATA[Good example of Proc::ProcessTable, which I wasn&#039;t familiar with.

Hard to tell since I only saw the code after you reworked it, but it looks like the bit that was using the &#039;re&#039; part of your structure got lost.  As a result, the current version is awfully dependent on pidfiles.  What if the service is running but the pidfile is gone somehow?  Looks to me like your script would just happily start it up again.

It&#039;s always good to simplify, but you have to be careful not to go too far.  There&#039;s unnecessary complexity, and then there&#039;s necessary complexity. ;-&#062;]]></description>
			<content:encoded><![CDATA[<p>Good example of Proc::ProcessTable, which I wasn&#8217;t familiar with.</p>
<p>Hard to tell since I only saw the code after you reworked it, but it looks like the bit that was using the &#8216;re&#8217; part of your structure got lost.  As a result, the current version is awfully dependent on pidfiles.  What if the service is running but the pidfile is gone somehow?  Looks to me like your script would just happily start it up again.</p>
<p>It&#8217;s always good to simplify, but you have to be careful not to go too far.  There&#8217;s unnecessary complexity, and then there&#8217;s necessary complexity. ;-&gt;</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
