{"id":3791,"date":"2021-06-06T18:06:36","date_gmt":"2021-06-06T18:06:36","guid":{"rendered":"https:\/\/nenadnoveljic.com\/blog\/?p=3791"},"modified":"2021-06-06T18:06:38","modified_gmt":"2021-06-06T18:06:38","slug":"improving-chia-farm-resilience","status":"publish","type":"post","link":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/","title":{"rendered":"Improving Chia Farm Resilience"},"content":{"rendered":"<p>Chia cryptocurrency farming seems popular these days. Farmers proudly post images of their expensive rigs in social networks, and avidly discuss optimization techniques.<\/p>\n<p>Surprisingly, few are concerned with resilience.<\/p>\n<p>Why is that important?<\/p>\n<p>The software can stop working anytime. In the case of a long lasting outage, the cost of a missed opportunity could be significant.<\/p>\n<p>Sooner or later, everyone needs to leave home to get food, interact with the outside world, and pursue activities unrelated to cryptocurrencies. It&#8217;s, therefore, essential to automatically recover the services when they become stale or go down.<\/p>\n<h1>Start on boot<\/h1>\n<p>First of all, make sure that farming starts after the machine reboots. The probability of such an event isn&#8217;t negligible, as most farmers run their services at home without redundant electricity supply.<\/p>\n<p>On Ubuntu, save the following code in the file <i>start_all<\/i> in your chia-blockchain directory:<\/p>\n<pre><code>#!\/usr\/bin\/bash\n\ncd \/home\/x\/chia-blockchain\/\n. .\/activate\nchia start all<\/code><\/pre>\n<p>Then, make it executable:<\/p>\n<pre><code>chmod u+x \/home\/x\/chia-blockchain\/start_all<\/code><\/pre>\n<p>Finally, schedule it in crontab to run on boot:<\/p>\n<pre><code>@reboot \/home\/x\/chia-blockchain\/start_all<\/code><\/pre>\n<p>You must replace <i>\/home\/x\/chia-blockchain<\/i> with your installation directory path.<\/p>\n<h1>Monitoring<\/h1>\n<p>Every now and then, farming gets stuck &#8211; probably due to a software bug. After restarting the services, syncing kicks in again.<\/p>\n<p>As this problem can happen anytime, you need to monitor the status and autocorrect.<\/p>\n<p>The following Python <i>monitor.py<\/i> program queries the farming status, and restarts everything if the status isn&#8217;t either &#8220;Farming&#8221; or &#8220;Syncing&#8221;.:<\/p>\n<pre><code>#!\/home\/neno\/chia-blockchain\/venv\/bin\/python\n\nimport subprocess\nimport re\nfrom datetime import datetime\n\nout = subprocess.Popen(['chia', 'farm', 'summary'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\nstdout, stderr = out.communicate()\nstdout = stdout.decode('utf-8')\n\nstatus = re.search( 'Farming status:\\s+(.+?)\\n' , stdout).group(1)\n\nif status != 'Farming' and status != 'Syncing':\n  f = open(\"\/tmp\/chia_hanging\", \"a\")\n  f.write( datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\") + ' ' + status + '\\n')\n\n  out = subprocess.Popen(['chia', 'start', '-r', 'all' ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n  stdout, stderr = out.communicate()\n  stdout = stdout.decode('utf-8')\n  f.write(stdout + '\\n')\n\n  f.close()<\/code><\/pre>\n<p>It logs incidents in <i>\/tmp\/chia_hanging<\/i>.<\/p>\n<p><i>monitor.py<\/i> is called by the shell script <i>monitor<\/i>:<\/p>\n<pre><code>#!\/usr\/bin\/bash\nDIR=\/home\/x\/chia-blockchain\/\ncd $DIR\n. .\/activate\n.\/monitor.py<\/code><\/pre>\n<p>Save both <i>monitor.py<\/i> and <i>monitor<\/i> in your chia-blockchain installation directory, replace <i>\/home\/x\/chia-blockchain\/<\/i> with your path and make both scripts executable.<\/p>\n<p>Finally, schedule the bash script in crontab:<\/p>\n<p><i>0 * * * * \/home\/neno\/chia-blockchain\/monitor &gt; \/tmp\/monitor.log 2&gt;&amp;1<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Monitoring, autocorrection and boot scripts for Chia farming services <a href=\"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[41],"tags":[],"class_list":["post-3791","post","type-post","status-publish","format-standard","hentry","category-chia-cryptocurrency"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Improving Chia Farm Resilience - All-round Database Topics<\/title>\n<meta name=\"description\" content=\"Monitoring, autocorrection and boot scripts for Chia farming services\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Improving Chia Farm Resilience - All-round Database Topics\" \/>\n<meta property=\"og:description\" content=\"Monitoring, autocorrection and boot scripts for Chia farming services\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/\" \/>\n<meta property=\"og:site_name\" content=\"All-round Database Topics\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-06T18:06:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-06T18:06:38+00:00\" \/>\n<meta name=\"author\" content=\"Nenad Noveljic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@NenadNoveljic\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nenad Noveljic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/\"},\"author\":{\"name\":\"Nenad Noveljic\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"headline\":\"Improving Chia Farm Resilience\",\"datePublished\":\"2021-06-06T18:06:36+00:00\",\"dateModified\":\"2021-06-06T18:06:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/\"},\"wordCount\":288,\"commentCount\":0,\"articleSection\":[\"Chia (cryptocurrency)\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/\",\"name\":\"Improving Chia Farm Resilience - All-round Database Topics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\"},\"datePublished\":\"2021-06-06T18:06:36+00:00\",\"dateModified\":\"2021-06-06T18:06:38+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"description\":\"Monitoring, autocorrection and boot scripts for Chia farming services\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/improving-chia-farm-resilience\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Improving Chia Farm Resilience\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\",\"name\":\"All-round Database Topics\",\"description\":\"Nenad Noveljic\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\",\"name\":\"Nenad Noveljic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"caption\":\"Nenad Noveljic\"},\"sameAs\":[\"nenad-noveljic-9b746a6\",\"https:\\\/\\\/x.com\\\/NenadNoveljic\"],\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/author\\\/nenad\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Improving Chia Farm Resilience - All-round Database Topics","description":"Monitoring, autocorrection and boot scripts for Chia farming services","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/","og_locale":"en_US","og_type":"article","og_title":"Improving Chia Farm Resilience - All-round Database Topics","og_description":"Monitoring, autocorrection and boot scripts for Chia farming services","og_url":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/","og_site_name":"All-round Database Topics","article_published_time":"2021-06-06T18:06:36+00:00","article_modified_time":"2021-06-06T18:06:38+00:00","author":"Nenad Noveljic","twitter_card":"summary_large_image","twitter_creator":"@NenadNoveljic","twitter_misc":{"Written by":"Nenad Noveljic","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/#article","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/"},"author":{"name":"Nenad Noveljic","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"headline":"Improving Chia Farm Resilience","datePublished":"2021-06-06T18:06:36+00:00","dateModified":"2021-06-06T18:06:38+00:00","mainEntityOfPage":{"@id":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/"},"wordCount":288,"commentCount":0,"articleSection":["Chia (cryptocurrency)"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/","url":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/","name":"Improving Chia Farm Resilience - All-round Database Topics","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#website"},"datePublished":"2021-06-06T18:06:36+00:00","dateModified":"2021-06-06T18:06:38+00:00","author":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"description":"Monitoring, autocorrection and boot scripts for Chia farming services","breadcrumb":{"@id":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nenadnoveljic.com\/blog\/improving-chia-farm-resilience\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nenadnoveljic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Improving Chia Farm Resilience"}]},{"@type":"WebSite","@id":"https:\/\/nenadnoveljic.com\/blog\/#website","url":"https:\/\/nenadnoveljic.com\/blog\/","name":"All-round Database Topics","description":"Nenad Noveljic","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nenadnoveljic.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa","name":"Nenad Noveljic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","caption":"Nenad Noveljic"},"sameAs":["nenad-noveljic-9b746a6","https:\/\/x.com\/NenadNoveljic"],"url":"https:\/\/nenadnoveljic.com\/blog\/author\/nenad\/"}]}},"_links":{"self":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/comments?post=3791"}],"version-history":[{"count":1,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3791\/revisions"}],"predecessor-version":[{"id":3796,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3791\/revisions\/3796"}],"wp:attachment":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/media?parent=3791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/categories?post=3791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/tags?post=3791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}