{"id":9114,"date":"2022-07-06T12:32:09","date_gmt":"2022-07-06T17:32:09","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=9114"},"modified":"2022-07-06T12:32:09","modified_gmt":"2022-07-06T17:32:09","slug":"logstash-jruby-and-private-temp","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=9114","title":{"rendered":"Logstash, JRuby, and Private Temp"},"content":{"rendered":"\n<p>There&#8217;s a long-standing <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/elastic\/logstash\/issues\/11051\" target=\"_blank\">bug in logstash where the private temp folder created for jruby isn&#8217;t cleaned up when the logstash process exits<\/a>. To avoid filling up the temp disk space, I put together a quick script to check the PID associated with each jruby temp folder, see if it&#8217;s an active process, and remove the temp folder if the associated process doesn&#8217;t exist. <\/p>\n\n\n\n<p>When the PID has been re-used, this means we&#8217;ve got an extra \/tmp\/jruby-### folder hanging about &#8230; but each folder is only 10 meg. The impacting issue is when we&#8217;ve restarted logstash a thousand times and a thousand ten meg folders are hanging about. <\/p>\n\n\n\n<p>This script can be cron&#8217;d to run periodically or it can be run when the logstash service launches. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport subprocess\nimport re\n\nfrom shutil import rmtree\n\nstrResult = subprocess.check_output(f&quot;ls \/tmp&quot;, shell=True)\n\nfor strLine in strResult.decode(&quot;utf-8&quot;).split(&#039;\\n&#039;):\n        if len(strLine) &gt; 0 and strLine.startswith(&quot;jruby-&quot;):\n                listSplitFileNames = re.split(&quot;jruby-(&#x5B;0-9]*)&quot;, strLine)\n                if listSplitFileNames&#x5B;1] is not None:\n                        try:\n                                strCheckPID = subprocess.check_output(f&quot;ps -efww |  grep {listSplitFileNames&#x5B;1]} | grep -v grep&quot;, shell=True)\n                                #print(f&quot;PID check result is {strCheckPID}&quot;)\n                        except:\n                                print(f&quot;I am deleting |{strLine}|&quot;)\n                                rmtree(f&quot;\/tmp\/{strLine}&quot;)\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>There&#8217;s a long-standing bug in logstash where the private temp folder created for jruby isn&#8217;t cleaned up when the logstash process exits. To avoid filling up the temp disk space, I put together a quick script to check the PID associated with each jruby temp folder, see if it&#8217;s an active process, and remove the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1588],"tags":[632,294,1643,1666],"class_list":["post-9114","post","type-post","status-publish","format-standard","hentry","category-elk","tag-bash","tag-linux","tag-logstash","tag-private-temp"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9114"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9114\/revisions"}],"predecessor-version":[{"id":9115,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9114\/revisions\/9115"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}