How to supervise and automatically restart a process? Announcing the arrival of Valued...

Any stored/leased 737s that could substitute for grounded MAXs?

How can I list files in reverse time order by a command and pass them as arguments to another command?

Did John Wesley plagiarize Matthew Henry...?

Adapting the Chinese Remainder Theorem (CRT) for integers to polynomials

What is the proper term for etching or digging of wall to hide conduit of cables

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?

Does the universe have a fixed centre of mass?

Does the transliteration of 'Dravidian' exist in Hindu scripture? Does 'Dravida' refer to a Geographical area or an ethnic group?

Is it OK to use the testing sample to compare algorithms?

Understanding piped commands in GNU/Linux

How does TikZ render an arc?

newbie Q : How to read an output file in one command line

malloc in main() or malloc in another function: allocating memory for a struct and its members

How to make an animal which can only breed for a certain number of generations?

Why do C and C++ allow the expression (int) + 4*5;

French equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

Is the time—manner—place ordering of adverbials an oversimplification?

Can the Haste spell grant both a Beast Master ranger and their animal companion extra attacks?

How do I say "this must not happen"?

An isoperimetric-type inequality inside a cube

The test team as an enemy of development? And how can this be avoided?

In musical terms, what properties are varied by the human voice to produce different words / syllables?

Besides transaction validation, are there any other uses of the Script language in Bitcoin

Should man-made satellites feature an intelligent inverted "cow catcher"?



How to supervise and automatically restart a process?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to have a process automatically restartcannot get upstart to run user jobRunning PHP-CLI serverHow can I disable avahi-daemon?Why upstart documentation prevents me from using respawnHow do I stop the NetworkManager in Ubuntu 13.10 without using the service command?Daemonize process with autostartSoftware works when run manually through the terminal but not as an Upstart serviceHow to run an executable file (web app) 24/7 and restart automatically when it breaks down?Can't kill process and uninstall packageWhy does systemd stop my service but not restart it?How to enable user's systemd timers and services for Grive2?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







34















I want to have a process which will be restarted if it crashes. I googled a bit and found that an easy solution is to use daemontools.



I didn't understand how to configure it.




  1. What is the easiest way to acomplish such a functionality?

  2. How to configure it?










share|improve this question































    34















    I want to have a process which will be restarted if it crashes. I googled a bit and found that an easy solution is to use daemontools.



    I didn't understand how to configure it.




    1. What is the easiest way to acomplish such a functionality?

    2. How to configure it?










    share|improve this question



























      34












      34








      34


      16






      I want to have a process which will be restarted if it crashes. I googled a bit and found that an easy solution is to use daemontools.



      I didn't understand how to configure it.




      1. What is the easiest way to acomplish such a functionality?

      2. How to configure it?










      share|improve this question
















      I want to have a process which will be restarted if it crashes. I googled a bit and found that an easy solution is to use daemontools.



      I didn't understand how to configure it.




      1. What is the easiest way to acomplish such a functionality?

      2. How to configure it?







      services






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 5 '13 at 12:06









      gertvdijk

      51.5k18145240




      51.5k18145240










      asked Feb 5 '13 at 12:02









      opc0deopc0de

      2871410




      2871410






















          6 Answers
          6






          active

          oldest

          votes


















          28














          This answer applies to Ubuntu versions with Upstart (<= 14.10). Use another approach for versions with Systemd (>= 15.04).



          It seems you're looking for a functionality already provided in Ubuntu with Upstart. The respawn stanza in the configuration will do exactly what you need. I would recommend against the use of a less standard way of dealing with this.



          Without more details about the process you're trying to manage with it, it's hard to say what the configuration should look like. It depends on whether it forks and puts itself in the background for example. The Upstart documentation on the respawn stanza should give you more information.



          Unfortunately, it's not yet possible to run User Jobs properly: cannot get upstart to run user job



          Example



          Let's assume we want to keep the Calculator app running, even when it's being killed with fire (signal 9).





          1. Create a configuration file in /etc/init/calculator.conf (based on this article):



            #!upstart
            description "Calculator"

            # Start job via the daemon control script. Replace "gert" with your username.
            exec su -l gert -c 'export DISPLAY=:0; /usr/bin/gnome-calculator'

            # Restart the process if it dies with a signal
            # or exit code not given by the 'normal exit' stanza.
            respawn

            # Give up if restart occurs 10 times in 90 seconds.
            respawn limit 10 90



          2. Start it by running



            sudo start calculator



          3. It opens on your current display (:0) and enjoy the awesomeness by seeing it restarting after closing it.





            • Identify the process ID, e.g. by doing ps aux | grep calculator:



              gert  13695 0.2 0.4 349744 16460 ?   Sl   13:38   0:00 /usr/bin/gnome-calculator



            • Kill it with fire.



              sudo kill -9 13695



            • Watch it reappearing:



              gert  16059 4.6 0.4 349736 16448 ?   Sl   13:40   0:00 /usr/bin/gnome-calculator





          Note that this will be more elegant with the plans for the Ubuntu 13.04 plans with proper User Job support.






          share|improve this answer


























          • I get unknown job when i try to start it ? any ideea . i have placed the file in /etc/init

            – opc0de
            Feb 5 '13 at 13:19













          • @opc0de The name of the file servicename.conf has to match the command to start start servicename. I suspect you have chosen a different name.

            – gertvdijk
            Feb 5 '13 at 13:23













          • nope, it matches but I didn't follow your example so i think I might have an syntax error.

            – opc0de
            Feb 5 '13 at 13:26











          • @opc0de Well, start by explaining more about what you're trying to accomplish in the question: what kind of application/process and how you run it for example, as well as the details about your current attempt.

            – gertvdijk
            Feb 5 '13 at 15:18











          • Solved with your example my mistake was that i probably had a mistake into the exec statament. Thanks for your help!

            – opc0de
            Feb 5 '13 at 17:58



















          13














          An extremely simple tool that can accomplish the same effect without needing configuration is immortal: https://immortal.run/



          Simply execute the command like this:



          immortal <cmd>



          It will run in the background and restart automatically if it exits.





          • immortalctl: View the status of running jobs. There is a name column which will be printed here, you can use this to refer to the job with other control commands.


          • immortalctl stop <name>: Stops monitoring the job with the given name (it will not be automatically restarted, but the current process will continue to execute)


          • immortalctl -k <name>: Sends SIGKILL to the current process.


          • immortalctl exit <name>: Stops monitoring the job with the given name and removes it from the list of jobs.






          share|improve this answer





















          • 1





            Thanks, this worked great for my use case in 16.04. Putting this in my bag of useful tools.

            – Quentin Skousen
            Jun 13 '17 at 16:30








          • 2





            Indeed, this looks more lightweight than upstart/respawn.

            – Sridhar-Sarnobat
            Jul 26 '17 at 5:14











          • Is there a way to get it to display stdout and stderr in the foreground?

            – David S.
            Aug 7 '17 at 17:24











          • I'm not aware of one, since it's usually used to run a process in the background. However, you can use immortalctl -l out.log <cmd> && tail -f out.log to achieve the same effect.

            – extropic-engine
            Aug 8 '17 at 18:53











          • @DavidS. you could get a combined log or have stdout and stderr immortal.run/post/stderr

            – nbari
            Nov 11 '17 at 15:20



















          0














          There is a way without "Upstart". The keyword is "inittab" :-). Although that's a file not usually altered from default, it can be used to achieve the desired respawning on SYSV machines.






          share|improve this answer
























          • I don't understand why someone REJECTED this solution. If you don't understand it, just google it; it's pointless to cut and paste here the man pages of initttab, you can read them yourself on your system! just type "man inittab"...

            – cepal67
            Jun 16 '15 at 14:26








          • 13





            High quality answers detail more than "use this, figure it out on your own" :)

            – Seth
            Jun 17 '15 at 0:13



















          0














          ps-watcher is a tool that watches which processes are running and executes an action on defined circumstances. Let’s install it:



          apt-get install ps-watcher


          See the bottom of Running HHVM with fallback to PHP-FPM for details - this has worked well for me.






          share|improve this answer


























          • Since it's not very long please add a summary of the code instead of the article because only a very short section applies to this question.

            – derHugo
            Sep 19 '17 at 5:48



















          0














          Startup and respawning processes are managed by "systemd" since Ubuntu 15.04, a good introduction can be found here



          https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal



          an example that get you started is available on



          https://www.devdungeon.com/content/creating-systemd-service-files



          This approach supersedes older ones based on /etc/inittab and upstart.






          share|improve this answer

































            0














            If you don't need daemon/service/background process functionality and just want to do it in the console then create a file called autorestart.sh:



            #!/bin/bash

            while [ 1 ]; do
            some_command
            done


            Then ./autorestart.sh will automatically restart some_command if it exits or crashes. CTRL-C breaks the loop and quits the program cleanly.



            Tested on Ubuntu 18.04.






            share|improve this answer








            New contributor




            Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f251577%2fhow-to-supervise-and-automatically-restart-a-process%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              6 Answers
              6






              active

              oldest

              votes








              6 Answers
              6






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              28














              This answer applies to Ubuntu versions with Upstart (<= 14.10). Use another approach for versions with Systemd (>= 15.04).



              It seems you're looking for a functionality already provided in Ubuntu with Upstart. The respawn stanza in the configuration will do exactly what you need. I would recommend against the use of a less standard way of dealing with this.



              Without more details about the process you're trying to manage with it, it's hard to say what the configuration should look like. It depends on whether it forks and puts itself in the background for example. The Upstart documentation on the respawn stanza should give you more information.



              Unfortunately, it's not yet possible to run User Jobs properly: cannot get upstart to run user job



              Example



              Let's assume we want to keep the Calculator app running, even when it's being killed with fire (signal 9).





              1. Create a configuration file in /etc/init/calculator.conf (based on this article):



                #!upstart
                description "Calculator"

                # Start job via the daemon control script. Replace "gert" with your username.
                exec su -l gert -c 'export DISPLAY=:0; /usr/bin/gnome-calculator'

                # Restart the process if it dies with a signal
                # or exit code not given by the 'normal exit' stanza.
                respawn

                # Give up if restart occurs 10 times in 90 seconds.
                respawn limit 10 90



              2. Start it by running



                sudo start calculator



              3. It opens on your current display (:0) and enjoy the awesomeness by seeing it restarting after closing it.





                • Identify the process ID, e.g. by doing ps aux | grep calculator:



                  gert  13695 0.2 0.4 349744 16460 ?   Sl   13:38   0:00 /usr/bin/gnome-calculator



                • Kill it with fire.



                  sudo kill -9 13695



                • Watch it reappearing:



                  gert  16059 4.6 0.4 349736 16448 ?   Sl   13:40   0:00 /usr/bin/gnome-calculator





              Note that this will be more elegant with the plans for the Ubuntu 13.04 plans with proper User Job support.






              share|improve this answer


























              • I get unknown job when i try to start it ? any ideea . i have placed the file in /etc/init

                – opc0de
                Feb 5 '13 at 13:19













              • @opc0de The name of the file servicename.conf has to match the command to start start servicename. I suspect you have chosen a different name.

                – gertvdijk
                Feb 5 '13 at 13:23













              • nope, it matches but I didn't follow your example so i think I might have an syntax error.

                – opc0de
                Feb 5 '13 at 13:26











              • @opc0de Well, start by explaining more about what you're trying to accomplish in the question: what kind of application/process and how you run it for example, as well as the details about your current attempt.

                – gertvdijk
                Feb 5 '13 at 15:18











              • Solved with your example my mistake was that i probably had a mistake into the exec statament. Thanks for your help!

                – opc0de
                Feb 5 '13 at 17:58
















              28














              This answer applies to Ubuntu versions with Upstart (<= 14.10). Use another approach for versions with Systemd (>= 15.04).



              It seems you're looking for a functionality already provided in Ubuntu with Upstart. The respawn stanza in the configuration will do exactly what you need. I would recommend against the use of a less standard way of dealing with this.



              Without more details about the process you're trying to manage with it, it's hard to say what the configuration should look like. It depends on whether it forks and puts itself in the background for example. The Upstart documentation on the respawn stanza should give you more information.



              Unfortunately, it's not yet possible to run User Jobs properly: cannot get upstart to run user job



              Example



              Let's assume we want to keep the Calculator app running, even when it's being killed with fire (signal 9).





              1. Create a configuration file in /etc/init/calculator.conf (based on this article):



                #!upstart
                description "Calculator"

                # Start job via the daemon control script. Replace "gert" with your username.
                exec su -l gert -c 'export DISPLAY=:0; /usr/bin/gnome-calculator'

                # Restart the process if it dies with a signal
                # or exit code not given by the 'normal exit' stanza.
                respawn

                # Give up if restart occurs 10 times in 90 seconds.
                respawn limit 10 90



              2. Start it by running



                sudo start calculator



              3. It opens on your current display (:0) and enjoy the awesomeness by seeing it restarting after closing it.





                • Identify the process ID, e.g. by doing ps aux | grep calculator:



                  gert  13695 0.2 0.4 349744 16460 ?   Sl   13:38   0:00 /usr/bin/gnome-calculator



                • Kill it with fire.



                  sudo kill -9 13695



                • Watch it reappearing:



                  gert  16059 4.6 0.4 349736 16448 ?   Sl   13:40   0:00 /usr/bin/gnome-calculator





              Note that this will be more elegant with the plans for the Ubuntu 13.04 plans with proper User Job support.






              share|improve this answer


























              • I get unknown job when i try to start it ? any ideea . i have placed the file in /etc/init

                – opc0de
                Feb 5 '13 at 13:19













              • @opc0de The name of the file servicename.conf has to match the command to start start servicename. I suspect you have chosen a different name.

                – gertvdijk
                Feb 5 '13 at 13:23













              • nope, it matches but I didn't follow your example so i think I might have an syntax error.

                – opc0de
                Feb 5 '13 at 13:26











              • @opc0de Well, start by explaining more about what you're trying to accomplish in the question: what kind of application/process and how you run it for example, as well as the details about your current attempt.

                – gertvdijk
                Feb 5 '13 at 15:18











              • Solved with your example my mistake was that i probably had a mistake into the exec statament. Thanks for your help!

                – opc0de
                Feb 5 '13 at 17:58














              28












              28








              28







              This answer applies to Ubuntu versions with Upstart (<= 14.10). Use another approach for versions with Systemd (>= 15.04).



              It seems you're looking for a functionality already provided in Ubuntu with Upstart. The respawn stanza in the configuration will do exactly what you need. I would recommend against the use of a less standard way of dealing with this.



              Without more details about the process you're trying to manage with it, it's hard to say what the configuration should look like. It depends on whether it forks and puts itself in the background for example. The Upstart documentation on the respawn stanza should give you more information.



              Unfortunately, it's not yet possible to run User Jobs properly: cannot get upstart to run user job



              Example



              Let's assume we want to keep the Calculator app running, even when it's being killed with fire (signal 9).





              1. Create a configuration file in /etc/init/calculator.conf (based on this article):



                #!upstart
                description "Calculator"

                # Start job via the daemon control script. Replace "gert" with your username.
                exec su -l gert -c 'export DISPLAY=:0; /usr/bin/gnome-calculator'

                # Restart the process if it dies with a signal
                # or exit code not given by the 'normal exit' stanza.
                respawn

                # Give up if restart occurs 10 times in 90 seconds.
                respawn limit 10 90



              2. Start it by running



                sudo start calculator



              3. It opens on your current display (:0) and enjoy the awesomeness by seeing it restarting after closing it.





                • Identify the process ID, e.g. by doing ps aux | grep calculator:



                  gert  13695 0.2 0.4 349744 16460 ?   Sl   13:38   0:00 /usr/bin/gnome-calculator



                • Kill it with fire.



                  sudo kill -9 13695



                • Watch it reappearing:



                  gert  16059 4.6 0.4 349736 16448 ?   Sl   13:40   0:00 /usr/bin/gnome-calculator





              Note that this will be more elegant with the plans for the Ubuntu 13.04 plans with proper User Job support.






              share|improve this answer















              This answer applies to Ubuntu versions with Upstart (<= 14.10). Use another approach for versions with Systemd (>= 15.04).



              It seems you're looking for a functionality already provided in Ubuntu with Upstart. The respawn stanza in the configuration will do exactly what you need. I would recommend against the use of a less standard way of dealing with this.



              Without more details about the process you're trying to manage with it, it's hard to say what the configuration should look like. It depends on whether it forks and puts itself in the background for example. The Upstart documentation on the respawn stanza should give you more information.



              Unfortunately, it's not yet possible to run User Jobs properly: cannot get upstart to run user job



              Example



              Let's assume we want to keep the Calculator app running, even when it's being killed with fire (signal 9).





              1. Create a configuration file in /etc/init/calculator.conf (based on this article):



                #!upstart
                description "Calculator"

                # Start job via the daemon control script. Replace "gert" with your username.
                exec su -l gert -c 'export DISPLAY=:0; /usr/bin/gnome-calculator'

                # Restart the process if it dies with a signal
                # or exit code not given by the 'normal exit' stanza.
                respawn

                # Give up if restart occurs 10 times in 90 seconds.
                respawn limit 10 90



              2. Start it by running



                sudo start calculator



              3. It opens on your current display (:0) and enjoy the awesomeness by seeing it restarting after closing it.





                • Identify the process ID, e.g. by doing ps aux | grep calculator:



                  gert  13695 0.2 0.4 349744 16460 ?   Sl   13:38   0:00 /usr/bin/gnome-calculator



                • Kill it with fire.



                  sudo kill -9 13695



                • Watch it reappearing:



                  gert  16059 4.6 0.4 349736 16448 ?   Sl   13:40   0:00 /usr/bin/gnome-calculator





              Note that this will be more elegant with the plans for the Ubuntu 13.04 plans with proper User Job support.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 13 '17 at 12:24









              Community

              1




              1










              answered Feb 5 '13 at 12:11









              gertvdijkgertvdijk

              51.5k18145240




              51.5k18145240













              • I get unknown job when i try to start it ? any ideea . i have placed the file in /etc/init

                – opc0de
                Feb 5 '13 at 13:19













              • @opc0de The name of the file servicename.conf has to match the command to start start servicename. I suspect you have chosen a different name.

                – gertvdijk
                Feb 5 '13 at 13:23













              • nope, it matches but I didn't follow your example so i think I might have an syntax error.

                – opc0de
                Feb 5 '13 at 13:26











              • @opc0de Well, start by explaining more about what you're trying to accomplish in the question: what kind of application/process and how you run it for example, as well as the details about your current attempt.

                – gertvdijk
                Feb 5 '13 at 15:18











              • Solved with your example my mistake was that i probably had a mistake into the exec statament. Thanks for your help!

                – opc0de
                Feb 5 '13 at 17:58



















              • I get unknown job when i try to start it ? any ideea . i have placed the file in /etc/init

                – opc0de
                Feb 5 '13 at 13:19













              • @opc0de The name of the file servicename.conf has to match the command to start start servicename. I suspect you have chosen a different name.

                – gertvdijk
                Feb 5 '13 at 13:23













              • nope, it matches but I didn't follow your example so i think I might have an syntax error.

                – opc0de
                Feb 5 '13 at 13:26











              • @opc0de Well, start by explaining more about what you're trying to accomplish in the question: what kind of application/process and how you run it for example, as well as the details about your current attempt.

                – gertvdijk
                Feb 5 '13 at 15:18











              • Solved with your example my mistake was that i probably had a mistake into the exec statament. Thanks for your help!

                – opc0de
                Feb 5 '13 at 17:58

















              I get unknown job when i try to start it ? any ideea . i have placed the file in /etc/init

              – opc0de
              Feb 5 '13 at 13:19







              I get unknown job when i try to start it ? any ideea . i have placed the file in /etc/init

              – opc0de
              Feb 5 '13 at 13:19















              @opc0de The name of the file servicename.conf has to match the command to start start servicename. I suspect you have chosen a different name.

              – gertvdijk
              Feb 5 '13 at 13:23







              @opc0de The name of the file servicename.conf has to match the command to start start servicename. I suspect you have chosen a different name.

              – gertvdijk
              Feb 5 '13 at 13:23















              nope, it matches but I didn't follow your example so i think I might have an syntax error.

              – opc0de
              Feb 5 '13 at 13:26





              nope, it matches but I didn't follow your example so i think I might have an syntax error.

              – opc0de
              Feb 5 '13 at 13:26













              @opc0de Well, start by explaining more about what you're trying to accomplish in the question: what kind of application/process and how you run it for example, as well as the details about your current attempt.

              – gertvdijk
              Feb 5 '13 at 15:18





              @opc0de Well, start by explaining more about what you're trying to accomplish in the question: what kind of application/process and how you run it for example, as well as the details about your current attempt.

              – gertvdijk
              Feb 5 '13 at 15:18













              Solved with your example my mistake was that i probably had a mistake into the exec statament. Thanks for your help!

              – opc0de
              Feb 5 '13 at 17:58





              Solved with your example my mistake was that i probably had a mistake into the exec statament. Thanks for your help!

              – opc0de
              Feb 5 '13 at 17:58













              13














              An extremely simple tool that can accomplish the same effect without needing configuration is immortal: https://immortal.run/



              Simply execute the command like this:



              immortal <cmd>



              It will run in the background and restart automatically if it exits.





              • immortalctl: View the status of running jobs. There is a name column which will be printed here, you can use this to refer to the job with other control commands.


              • immortalctl stop <name>: Stops monitoring the job with the given name (it will not be automatically restarted, but the current process will continue to execute)


              • immortalctl -k <name>: Sends SIGKILL to the current process.


              • immortalctl exit <name>: Stops monitoring the job with the given name and removes it from the list of jobs.






              share|improve this answer





















              • 1





                Thanks, this worked great for my use case in 16.04. Putting this in my bag of useful tools.

                – Quentin Skousen
                Jun 13 '17 at 16:30








              • 2





                Indeed, this looks more lightweight than upstart/respawn.

                – Sridhar-Sarnobat
                Jul 26 '17 at 5:14











              • Is there a way to get it to display stdout and stderr in the foreground?

                – David S.
                Aug 7 '17 at 17:24











              • I'm not aware of one, since it's usually used to run a process in the background. However, you can use immortalctl -l out.log <cmd> && tail -f out.log to achieve the same effect.

                – extropic-engine
                Aug 8 '17 at 18:53











              • @DavidS. you could get a combined log or have stdout and stderr immortal.run/post/stderr

                – nbari
                Nov 11 '17 at 15:20
















              13














              An extremely simple tool that can accomplish the same effect without needing configuration is immortal: https://immortal.run/



              Simply execute the command like this:



              immortal <cmd>



              It will run in the background and restart automatically if it exits.





              • immortalctl: View the status of running jobs. There is a name column which will be printed here, you can use this to refer to the job with other control commands.


              • immortalctl stop <name>: Stops monitoring the job with the given name (it will not be automatically restarted, but the current process will continue to execute)


              • immortalctl -k <name>: Sends SIGKILL to the current process.


              • immortalctl exit <name>: Stops monitoring the job with the given name and removes it from the list of jobs.






              share|improve this answer





















              • 1





                Thanks, this worked great for my use case in 16.04. Putting this in my bag of useful tools.

                – Quentin Skousen
                Jun 13 '17 at 16:30








              • 2





                Indeed, this looks more lightweight than upstart/respawn.

                – Sridhar-Sarnobat
                Jul 26 '17 at 5:14











              • Is there a way to get it to display stdout and stderr in the foreground?

                – David S.
                Aug 7 '17 at 17:24











              • I'm not aware of one, since it's usually used to run a process in the background. However, you can use immortalctl -l out.log <cmd> && tail -f out.log to achieve the same effect.

                – extropic-engine
                Aug 8 '17 at 18:53











              • @DavidS. you could get a combined log or have stdout and stderr immortal.run/post/stderr

                – nbari
                Nov 11 '17 at 15:20














              13












              13








              13







              An extremely simple tool that can accomplish the same effect without needing configuration is immortal: https://immortal.run/



              Simply execute the command like this:



              immortal <cmd>



              It will run in the background and restart automatically if it exits.





              • immortalctl: View the status of running jobs. There is a name column which will be printed here, you can use this to refer to the job with other control commands.


              • immortalctl stop <name>: Stops monitoring the job with the given name (it will not be automatically restarted, but the current process will continue to execute)


              • immortalctl -k <name>: Sends SIGKILL to the current process.


              • immortalctl exit <name>: Stops monitoring the job with the given name and removes it from the list of jobs.






              share|improve this answer















              An extremely simple tool that can accomplish the same effect without needing configuration is immortal: https://immortal.run/



              Simply execute the command like this:



              immortal <cmd>



              It will run in the background and restart automatically if it exits.





              • immortalctl: View the status of running jobs. There is a name column which will be printed here, you can use this to refer to the job with other control commands.


              • immortalctl stop <name>: Stops monitoring the job with the given name (it will not be automatically restarted, but the current process will continue to execute)


              • immortalctl -k <name>: Sends SIGKILL to the current process.


              • immortalctl exit <name>: Stops monitoring the job with the given name and removes it from the list of jobs.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 17 '17 at 23:38

























              answered May 16 '17 at 18:58









              extropic-engineextropic-engine

              23127




              23127








              • 1





                Thanks, this worked great for my use case in 16.04. Putting this in my bag of useful tools.

                – Quentin Skousen
                Jun 13 '17 at 16:30








              • 2





                Indeed, this looks more lightweight than upstart/respawn.

                – Sridhar-Sarnobat
                Jul 26 '17 at 5:14











              • Is there a way to get it to display stdout and stderr in the foreground?

                – David S.
                Aug 7 '17 at 17:24











              • I'm not aware of one, since it's usually used to run a process in the background. However, you can use immortalctl -l out.log <cmd> && tail -f out.log to achieve the same effect.

                – extropic-engine
                Aug 8 '17 at 18:53











              • @DavidS. you could get a combined log or have stdout and stderr immortal.run/post/stderr

                – nbari
                Nov 11 '17 at 15:20














              • 1





                Thanks, this worked great for my use case in 16.04. Putting this in my bag of useful tools.

                – Quentin Skousen
                Jun 13 '17 at 16:30








              • 2





                Indeed, this looks more lightweight than upstart/respawn.

                – Sridhar-Sarnobat
                Jul 26 '17 at 5:14











              • Is there a way to get it to display stdout and stderr in the foreground?

                – David S.
                Aug 7 '17 at 17:24











              • I'm not aware of one, since it's usually used to run a process in the background. However, you can use immortalctl -l out.log <cmd> && tail -f out.log to achieve the same effect.

                – extropic-engine
                Aug 8 '17 at 18:53











              • @DavidS. you could get a combined log or have stdout and stderr immortal.run/post/stderr

                – nbari
                Nov 11 '17 at 15:20








              1




              1





              Thanks, this worked great for my use case in 16.04. Putting this in my bag of useful tools.

              – Quentin Skousen
              Jun 13 '17 at 16:30







              Thanks, this worked great for my use case in 16.04. Putting this in my bag of useful tools.

              – Quentin Skousen
              Jun 13 '17 at 16:30






              2




              2





              Indeed, this looks more lightweight than upstart/respawn.

              – Sridhar-Sarnobat
              Jul 26 '17 at 5:14





              Indeed, this looks more lightweight than upstart/respawn.

              – Sridhar-Sarnobat
              Jul 26 '17 at 5:14













              Is there a way to get it to display stdout and stderr in the foreground?

              – David S.
              Aug 7 '17 at 17:24





              Is there a way to get it to display stdout and stderr in the foreground?

              – David S.
              Aug 7 '17 at 17:24













              I'm not aware of one, since it's usually used to run a process in the background. However, you can use immortalctl -l out.log <cmd> && tail -f out.log to achieve the same effect.

              – extropic-engine
              Aug 8 '17 at 18:53





              I'm not aware of one, since it's usually used to run a process in the background. However, you can use immortalctl -l out.log <cmd> && tail -f out.log to achieve the same effect.

              – extropic-engine
              Aug 8 '17 at 18:53













              @DavidS. you could get a combined log or have stdout and stderr immortal.run/post/stderr

              – nbari
              Nov 11 '17 at 15:20





              @DavidS. you could get a combined log or have stdout and stderr immortal.run/post/stderr

              – nbari
              Nov 11 '17 at 15:20











              0














              There is a way without "Upstart". The keyword is "inittab" :-). Although that's a file not usually altered from default, it can be used to achieve the desired respawning on SYSV machines.






              share|improve this answer
























              • I don't understand why someone REJECTED this solution. If you don't understand it, just google it; it's pointless to cut and paste here the man pages of initttab, you can read them yourself on your system! just type "man inittab"...

                – cepal67
                Jun 16 '15 at 14:26








              • 13





                High quality answers detail more than "use this, figure it out on your own" :)

                – Seth
                Jun 17 '15 at 0:13
















              0














              There is a way without "Upstart". The keyword is "inittab" :-). Although that's a file not usually altered from default, it can be used to achieve the desired respawning on SYSV machines.






              share|improve this answer
























              • I don't understand why someone REJECTED this solution. If you don't understand it, just google it; it's pointless to cut and paste here the man pages of initttab, you can read them yourself on your system! just type "man inittab"...

                – cepal67
                Jun 16 '15 at 14:26








              • 13





                High quality answers detail more than "use this, figure it out on your own" :)

                – Seth
                Jun 17 '15 at 0:13














              0












              0








              0







              There is a way without "Upstart". The keyword is "inittab" :-). Although that's a file not usually altered from default, it can be used to achieve the desired respawning on SYSV machines.






              share|improve this answer













              There is a way without "Upstart". The keyword is "inittab" :-). Although that's a file not usually altered from default, it can be used to achieve the desired respawning on SYSV machines.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 15 '15 at 16:08









              cepal67cepal67

              271




              271













              • I don't understand why someone REJECTED this solution. If you don't understand it, just google it; it's pointless to cut and paste here the man pages of initttab, you can read them yourself on your system! just type "man inittab"...

                – cepal67
                Jun 16 '15 at 14:26








              • 13





                High quality answers detail more than "use this, figure it out on your own" :)

                – Seth
                Jun 17 '15 at 0:13



















              • I don't understand why someone REJECTED this solution. If you don't understand it, just google it; it's pointless to cut and paste here the man pages of initttab, you can read them yourself on your system! just type "man inittab"...

                – cepal67
                Jun 16 '15 at 14:26








              • 13





                High quality answers detail more than "use this, figure it out on your own" :)

                – Seth
                Jun 17 '15 at 0:13

















              I don't understand why someone REJECTED this solution. If you don't understand it, just google it; it's pointless to cut and paste here the man pages of initttab, you can read them yourself on your system! just type "man inittab"...

              – cepal67
              Jun 16 '15 at 14:26







              I don't understand why someone REJECTED this solution. If you don't understand it, just google it; it's pointless to cut and paste here the man pages of initttab, you can read them yourself on your system! just type "man inittab"...

              – cepal67
              Jun 16 '15 at 14:26






              13




              13





              High quality answers detail more than "use this, figure it out on your own" :)

              – Seth
              Jun 17 '15 at 0:13





              High quality answers detail more than "use this, figure it out on your own" :)

              – Seth
              Jun 17 '15 at 0:13











              0














              ps-watcher is a tool that watches which processes are running and executes an action on defined circumstances. Let’s install it:



              apt-get install ps-watcher


              See the bottom of Running HHVM with fallback to PHP-FPM for details - this has worked well for me.






              share|improve this answer


























              • Since it's not very long please add a summary of the code instead of the article because only a very short section applies to this question.

                – derHugo
                Sep 19 '17 at 5:48
















              0














              ps-watcher is a tool that watches which processes are running and executes an action on defined circumstances. Let’s install it:



              apt-get install ps-watcher


              See the bottom of Running HHVM with fallback to PHP-FPM for details - this has worked well for me.






              share|improve this answer


























              • Since it's not very long please add a summary of the code instead of the article because only a very short section applies to this question.

                – derHugo
                Sep 19 '17 at 5:48














              0












              0








              0







              ps-watcher is a tool that watches which processes are running and executes an action on defined circumstances. Let’s install it:



              apt-get install ps-watcher


              See the bottom of Running HHVM with fallback to PHP-FPM for details - this has worked well for me.






              share|improve this answer















              ps-watcher is a tool that watches which processes are running and executes an action on defined circumstances. Let’s install it:



              apt-get install ps-watcher


              See the bottom of Running HHVM with fallback to PHP-FPM for details - this has worked well for me.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Sep 19 '17 at 6:56









              Eliah Kagan

              83.5k22229369




              83.5k22229369










              answered Sep 19 '17 at 1:33









              FiregardenFiregarden

              1011




              1011













              • Since it's not very long please add a summary of the code instead of the article because only a very short section applies to this question.

                – derHugo
                Sep 19 '17 at 5:48



















              • Since it's not very long please add a summary of the code instead of the article because only a very short section applies to this question.

                – derHugo
                Sep 19 '17 at 5:48

















              Since it's not very long please add a summary of the code instead of the article because only a very short section applies to this question.

              – derHugo
              Sep 19 '17 at 5:48





              Since it's not very long please add a summary of the code instead of the article because only a very short section applies to this question.

              – derHugo
              Sep 19 '17 at 5:48











              0














              Startup and respawning processes are managed by "systemd" since Ubuntu 15.04, a good introduction can be found here



              https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal



              an example that get you started is available on



              https://www.devdungeon.com/content/creating-systemd-service-files



              This approach supersedes older ones based on /etc/inittab and upstart.






              share|improve this answer






























                0














                Startup and respawning processes are managed by "systemd" since Ubuntu 15.04, a good introduction can be found here



                https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal



                an example that get you started is available on



                https://www.devdungeon.com/content/creating-systemd-service-files



                This approach supersedes older ones based on /etc/inittab and upstart.






                share|improve this answer




























                  0












                  0








                  0







                  Startup and respawning processes are managed by "systemd" since Ubuntu 15.04, a good introduction can be found here



                  https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal



                  an example that get you started is available on



                  https://www.devdungeon.com/content/creating-systemd-service-files



                  This approach supersedes older ones based on /etc/inittab and upstart.






                  share|improve this answer















                  Startup and respawning processes are managed by "systemd" since Ubuntu 15.04, a good introduction can be found here



                  https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal



                  an example that get you started is available on



                  https://www.devdungeon.com/content/creating-systemd-service-files



                  This approach supersedes older ones based on /etc/inittab and upstart.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 4 '18 at 20:31

























                  answered Jul 4 '18 at 15:24









                  Nikolaus CorrellNikolaus Correll

                  11




                  11























                      0














                      If you don't need daemon/service/background process functionality and just want to do it in the console then create a file called autorestart.sh:



                      #!/bin/bash

                      while [ 1 ]; do
                      some_command
                      done


                      Then ./autorestart.sh will automatically restart some_command if it exits or crashes. CTRL-C breaks the loop and quits the program cleanly.



                      Tested on Ubuntu 18.04.






                      share|improve this answer








                      New contributor




                      Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        If you don't need daemon/service/background process functionality and just want to do it in the console then create a file called autorestart.sh:



                        #!/bin/bash

                        while [ 1 ]; do
                        some_command
                        done


                        Then ./autorestart.sh will automatically restart some_command if it exits or crashes. CTRL-C breaks the loop and quits the program cleanly.



                        Tested on Ubuntu 18.04.






                        share|improve this answer








                        New contributor




                        Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          If you don't need daemon/service/background process functionality and just want to do it in the console then create a file called autorestart.sh:



                          #!/bin/bash

                          while [ 1 ]; do
                          some_command
                          done


                          Then ./autorestart.sh will automatically restart some_command if it exits or crashes. CTRL-C breaks the loop and quits the program cleanly.



                          Tested on Ubuntu 18.04.






                          share|improve this answer








                          New contributor




                          Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          If you don't need daemon/service/background process functionality and just want to do it in the console then create a file called autorestart.sh:



                          #!/bin/bash

                          while [ 1 ]; do
                          some_command
                          done


                          Then ./autorestart.sh will automatically restart some_command if it exits or crashes. CTRL-C breaks the loop and quits the program cleanly.



                          Tested on Ubuntu 18.04.







                          share|improve this answer








                          New contributor




                          Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 2 hours ago









                          Jan ŚwięckiJan Święcki

                          101




                          101




                          New contributor




                          Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Jan Święcki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f251577%2fhow-to-supervise-and-automatically-restart-a-process%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Why do type traits not work with types in namespace scope?What are POD types in C++?Why can templates only be...

                              Will tsunami waves travel forever if there was no land?Why do tsunami waves begin with the water flowing away...

                              Should I use Docker or LXD?How to cache (more) data on SSD/RAM to avoid spin up?Unable to get Windows File...