Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-graphql domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the pods domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6114 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6114) in /var/www/html/wp-includes/rest-api/class-wp-rest-server.php on line 1893 {"id":801,"date":"2019-10-05T09:49:02","date_gmt":"2019-10-05T09:49:02","guid":{"rendered":"http:\/\/site.sifars.com\/blog\/?p=801"},"modified":"2024-03-27T04:10:03","modified_gmt":"2024-03-27T04:10:03","slug":"best-way-to-handle-background-processes-in-linux","status":"publish","type":"post","link":"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/","title":{"rendered":"Best way to handle background processes in linux"},"content":{"rendered":"Reading Time: <\/span> < 1<\/span> minute<\/span><\/span>

E<\/span>very programmer soon comes to a point where he requires to setup several jobs to run in the background with 100% uptime. For example a website server, email server, job schedulers etc.<\/p>\n

These processes are more like a daemon process. And as like any other job, these tend to stop due to mishandling or uncatchable exceptions\/errors. Rather to put a person to sit and constantly monitor the jobs, we make use of the Supervisor<\/a>.<\/p>\n

A Supervisor<\/a> is a process control system that will start, stop and monitor all our processes and will restart any, that fails.<\/p>\n

To install Supervisor on Ubuntu:<\/h3>\n

sudo apt-get install supervisor<\/code><\/p>\n

Configuring Supervisor<\/h3>\n

Let say we have a command that should run indefinitely:<\/p>\n

python run_this_command<\/code><\/p>\n

Supervisor configuration files are stored in the \/etc\/supervisor\/conf.d<\/span> directory. Let’s create a new configuration file as monitor-my-process.conf.<\/p>\n

Inside monitor-my-process.conf write:<\/p>\n

[program:my-worker]
\nprocess_name=%(program_name)s_%(process_num)02d
\ncommand=python run_this_command
\nautostart=true
\nautorestart=true
\nuser=linux_user
\nnumprocs=8
\nredirect_stderr=true
\nstdout_logfile=\/home\/linux_user\/app.com\/worker.log
\n<\/code><\/p>\n

In this example, the numprocs directive will instruct Supervisor to run 8 processes of my command and monitor all of them, automatically restarting them if they fail. Also change the ‘linux_user’ to the user you want the process to be run as.<\/p>\n

Starting Supervisor<\/h3>\n

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:<\/p>\n

sudo supervisorctl reread
\nsudo supervisorctl update
\nsudo supervisorctl start my-worker:*<\/code><\/p>\n

Cheers! Your processes will run indefinitely with auto restart.<\/p>\n

Bonus!<\/h3>\n

Few more commands that are likely to be used sometime later:<\/p>\n

Stop all supervisor workers:<\/h5>\n

sudo supervisorctl stop my-worker:*<\/code><\/p>\n

Restart all supervisor workers:<\/h5>\n

sudo supervisorctl restart my-worker:*<\/code><\/p>\n

Get the current status of workers:<\/h5>\n

sudo supervisorctl status my-worker:*<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"

Reading Time: <\/span> < 1<\/span> minute<\/span><\/span> Every programmer soon comes to a point where he requires to setup several jobs to run in the background with 100% uptime. For example a website server, email server, job schedulers etc. These processes are more like a daemon process. And as like any other job, these tend to stop due to mishandling or uncatchable […]<\/p>\n","protected":false},"author":3,"featured_media":1782,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-801","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"yoast_head":"\nBest way to handle background processes in linux - Sifars<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Best way to handle background processes in linux - Sifars\" \/>\n<meta property=\"og:description\" content=\"Reading Time: < 1 minute Every programmer soon comes to a point where he requires to setup several jobs to run in the background with 100% uptime. For example a website server, email server, job schedulers etc. These processes are more like a daemon process. And as like any other job, these tend to stop due to mishandling or uncatchable […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Sifars\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/sifars.tech\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-05T09:49:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-27T04:10:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"577\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"sifars\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sifars1\" \/>\n<meta name=\"twitter:site\" content=\"@sifars1\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"sifars\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/\",\"url\":\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/\",\"name\":\"Best way to handle background processes in linux - Sifars\",\"isPartOf\":{\"@id\":\"https:\/\/srafis.sifars.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png\",\"datePublished\":\"2019-10-05T09:49:02+00:00\",\"dateModified\":\"2024-03-27T04:10:03+00:00\",\"author\":{\"@id\":\"https:\/\/srafis.sifars.com\/#\/schema\/person\/6012251e6ccb25fb1aa2b058e3641da3\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/#primaryimage\",\"url\":\"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png\",\"contentUrl\":\"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png\",\"width\":1024,\"height\":577},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/srafis.sifars.com\/#website\",\"url\":\"https:\/\/srafis.sifars.com\/\",\"name\":\"Sifars\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/srafis.sifars.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/srafis.sifars.com\/#\/schema\/person\/6012251e6ccb25fb1aa2b058e3641da3\",\"name\":\"sifars\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/srafis.sifars.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"sifars\"},\"url\":\"https:\/\/srafis.sifars.com\/index.php\/author\/sifars\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Best way to handle background processes in linux - Sifars","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:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"Best way to handle background processes in linux - Sifars","og_description":"Reading Time: < 1 minute Every programmer soon comes to a point where he requires to setup several jobs to run in the background with 100% uptime. For example a website server, email server, job schedulers etc. These processes are more like a daemon process. And as like any other job, these tend to stop due to mishandling or uncatchable […]","og_url":"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/","og_site_name":"Sifars","article_publisher":"https:\/\/www.facebook.com\/sifars.tech","article_published_time":"2019-10-05T09:49:02+00:00","article_modified_time":"2024-03-27T04:10:03+00:00","og_image":[{"width":1024,"height":577,"url":"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png","type":"image\/png"}],"author":"sifars","twitter_card":"summary_large_image","twitter_creator":"@sifars1","twitter_site":"@sifars1","twitter_misc":{"Written by":"sifars","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/","url":"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/","name":"Best way to handle background processes in linux - Sifars","isPartOf":{"@id":"https:\/\/srafis.sifars.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png","datePublished":"2019-10-05T09:49:02+00:00","dateModified":"2024-03-27T04:10:03+00:00","author":{"@id":"https:\/\/srafis.sifars.com\/#\/schema\/person\/6012251e6ccb25fb1aa2b058e3641da3"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/srafis.sifars.com\/index.php\/2019\/10\/05\/best-way-to-handle-background-processes-in-linux\/#primaryimage","url":"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png","contentUrl":"https:\/\/srafis.sifars.com\/wp-content\/uploads\/2023\/05\/Procs-1024x577-1.png","width":1024,"height":577},{"@type":"WebSite","@id":"https:\/\/srafis.sifars.com\/#website","url":"https:\/\/srafis.sifars.com\/","name":"Sifars","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/srafis.sifars.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/srafis.sifars.com\/#\/schema\/person\/6012251e6ccb25fb1aa2b058e3641da3","name":"sifars","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/srafis.sifars.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"sifars"},"url":"https:\/\/srafis.sifars.com\/index.php\/author\/sifars\/"}]}},"_links":{"self":[{"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/posts\/801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/comments?post=801"}],"version-history":[{"count":2,"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/posts\/801\/revisions"}],"predecessor-version":[{"id":1823,"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/posts\/801\/revisions\/1823"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/media\/1782"}],"wp:attachment":[{"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/media?parent=801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/categories?post=801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/srafis.sifars.com\/index.php\/wp-json\/wp\/v2\/tags?post=801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}