Daemons do not get restarted?









up vote
3
down vote

favorite












I am trying to run the same script in multiple daemons.



myapp.rb looks like this:



loop do
sleep 5
1 / 0 # crash it
end


my myapp_controller.rb:



require 'rubygems'
require 'daemons'

options =
:log_output => true,
:backtrace => true,
:monitor => true,
:multiple => true,
:log_dir => '/mnt/log/',
:hard_exit => true

Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


When I run ruby myapp_controller.rb start several times in a row, it creates that many daemons, as I expect. But, after a while, due to an error in myapp.rb the daemons crash and the monitor restarts just one and not all. So I end up with a single running daemon.



Why? What am I doing wrong?










share|improve this question



























    up vote
    3
    down vote

    favorite












    I am trying to run the same script in multiple daemons.



    myapp.rb looks like this:



    loop do
    sleep 5
    1 / 0 # crash it
    end


    my myapp_controller.rb:



    require 'rubygems'
    require 'daemons'

    options =
    :log_output => true,
    :backtrace => true,
    :monitor => true,
    :multiple => true,
    :log_dir => '/mnt/log/',
    :hard_exit => true

    Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


    When I run ruby myapp_controller.rb start several times in a row, it creates that many daemons, as I expect. But, after a while, due to an error in myapp.rb the daemons crash and the monitor restarts just one and not all. So I end up with a single running daemon.



    Why? What am I doing wrong?










    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I am trying to run the same script in multiple daemons.



      myapp.rb looks like this:



      loop do
      sleep 5
      1 / 0 # crash it
      end


      my myapp_controller.rb:



      require 'rubygems'
      require 'daemons'

      options =
      :log_output => true,
      :backtrace => true,
      :monitor => true,
      :multiple => true,
      :log_dir => '/mnt/log/',
      :hard_exit => true

      Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


      When I run ruby myapp_controller.rb start several times in a row, it creates that many daemons, as I expect. But, after a while, due to an error in myapp.rb the daemons crash and the monitor restarts just one and not all. So I end up with a single running daemon.



      Why? What am I doing wrong?










      share|improve this question















      I am trying to run the same script in multiple daemons.



      myapp.rb looks like this:



      loop do
      sleep 5
      1 / 0 # crash it
      end


      my myapp_controller.rb:



      require 'rubygems'
      require 'daemons'

      options =
      :log_output => true,
      :backtrace => true,
      :monitor => true,
      :multiple => true,
      :log_dir => '/mnt/log/',
      :hard_exit => true

      Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


      When I run ruby myapp_controller.rb start several times in a row, it creates that many daemons, as I expect. But, after a while, due to an error in myapp.rb the daemons crash and the monitor restarts just one and not all. So I end up with a single running daemon.



      Why? What am I doing wrong?







      ruby daemons






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 25 '13 at 16:58

























      asked Jan 25 '13 at 4:16









      akonsu

      16.4k2187154




      16.4k2187154






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          I was able to reproduce the behavior. It is not anything you are doing wrong; it is the way the daemons gem behaves.



          Going through the code for the daemons gem, turns out the :multiple option doesn't work well with the :monitor option.



          The :monitor option works only when the daemon is run in single mode.



          I have created a bug report on the daemons project page referencing this question as the source.



          More info about the reproduction of the issue:



          Multiple daemon processes are created when :multiple => true. Each process has its own pid file in the format of <scriptname>.rb<number>.pid.



          However, only one monitor process is created (with a single <scriptname>.rb_monitor.pid file.)



          Here are the list of processes started when I start the daemon process 3 times:



          $ ps -fe | grep my_server
          501 1758 1 0 12:25PM ?? 0:00.63 my_server.rb
          501 1759 1 0 12:25PM ?? 0:00.43 my_server.rb_monitor
          501 1764 1 0 12:25PM ?? 0:00.54 my_server.rb
          501 1834 1 0 12:51PM ?? 0:00.31 my_server.rb


          The files in the pid/log folder:



          $ ls /tmp/daemons-2013-01-25/
          my_server.rb.log my_server.rb1.pid my_server.rb_monitor.pid
          my_server.rb0.pid my_server.rb2.pid





          share|improve this answer




















          • The bug report given in the post appears to be a broken link. Here is an issue page on github. github.com/thuehlinger/daemons/issues/7
            – rude-n8
            Aug 25 '15 at 18:10


















          up vote
          0
          down vote













          Until the issue is resolved, you can change your code to something like this:



          #myapp_controller.rb
          require 'rubygems'
          require 'daemons'

          number = ARGV.fetch(1)

          options =
          :app_name => "daemon-#number" # provide app_name
          :log_output => true,
          :backtrace => true,
          :monitor => true,
          :multiple => false, # disable multiple option
          :log_dir => '/mnt/log/',
          :hard_exit => true

          Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


          And then start your daemons with these commands:



          ruby myapp_controller.rb start 1
          ruby myapp_controller.rb start 2
          ...


          This slightly changes your startup code, but now you will have a monitor process for each of your daemon processes.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            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',
            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%2fstackoverflow.com%2fquestions%2f14515250%2fdaemons-do-not-get-restarted%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            I was able to reproduce the behavior. It is not anything you are doing wrong; it is the way the daemons gem behaves.



            Going through the code for the daemons gem, turns out the :multiple option doesn't work well with the :monitor option.



            The :monitor option works only when the daemon is run in single mode.



            I have created a bug report on the daemons project page referencing this question as the source.



            More info about the reproduction of the issue:



            Multiple daemon processes are created when :multiple => true. Each process has its own pid file in the format of <scriptname>.rb<number>.pid.



            However, only one monitor process is created (with a single <scriptname>.rb_monitor.pid file.)



            Here are the list of processes started when I start the daemon process 3 times:



            $ ps -fe | grep my_server
            501 1758 1 0 12:25PM ?? 0:00.63 my_server.rb
            501 1759 1 0 12:25PM ?? 0:00.43 my_server.rb_monitor
            501 1764 1 0 12:25PM ?? 0:00.54 my_server.rb
            501 1834 1 0 12:51PM ?? 0:00.31 my_server.rb


            The files in the pid/log folder:



            $ ls /tmp/daemons-2013-01-25/
            my_server.rb.log my_server.rb1.pid my_server.rb_monitor.pid
            my_server.rb0.pid my_server.rb2.pid





            share|improve this answer




















            • The bug report given in the post appears to be a broken link. Here is an issue page on github. github.com/thuehlinger/daemons/issues/7
              – rude-n8
              Aug 25 '15 at 18:10















            up vote
            4
            down vote



            accepted










            I was able to reproduce the behavior. It is not anything you are doing wrong; it is the way the daemons gem behaves.



            Going through the code for the daemons gem, turns out the :multiple option doesn't work well with the :monitor option.



            The :monitor option works only when the daemon is run in single mode.



            I have created a bug report on the daemons project page referencing this question as the source.



            More info about the reproduction of the issue:



            Multiple daemon processes are created when :multiple => true. Each process has its own pid file in the format of <scriptname>.rb<number>.pid.



            However, only one monitor process is created (with a single <scriptname>.rb_monitor.pid file.)



            Here are the list of processes started when I start the daemon process 3 times:



            $ ps -fe | grep my_server
            501 1758 1 0 12:25PM ?? 0:00.63 my_server.rb
            501 1759 1 0 12:25PM ?? 0:00.43 my_server.rb_monitor
            501 1764 1 0 12:25PM ?? 0:00.54 my_server.rb
            501 1834 1 0 12:51PM ?? 0:00.31 my_server.rb


            The files in the pid/log folder:



            $ ls /tmp/daemons-2013-01-25/
            my_server.rb.log my_server.rb1.pid my_server.rb_monitor.pid
            my_server.rb0.pid my_server.rb2.pid





            share|improve this answer




















            • The bug report given in the post appears to be a broken link. Here is an issue page on github. github.com/thuehlinger/daemons/issues/7
              – rude-n8
              Aug 25 '15 at 18:10













            up vote
            4
            down vote



            accepted







            up vote
            4
            down vote



            accepted






            I was able to reproduce the behavior. It is not anything you are doing wrong; it is the way the daemons gem behaves.



            Going through the code for the daemons gem, turns out the :multiple option doesn't work well with the :monitor option.



            The :monitor option works only when the daemon is run in single mode.



            I have created a bug report on the daemons project page referencing this question as the source.



            More info about the reproduction of the issue:



            Multiple daemon processes are created when :multiple => true. Each process has its own pid file in the format of <scriptname>.rb<number>.pid.



            However, only one monitor process is created (with a single <scriptname>.rb_monitor.pid file.)



            Here are the list of processes started when I start the daemon process 3 times:



            $ ps -fe | grep my_server
            501 1758 1 0 12:25PM ?? 0:00.63 my_server.rb
            501 1759 1 0 12:25PM ?? 0:00.43 my_server.rb_monitor
            501 1764 1 0 12:25PM ?? 0:00.54 my_server.rb
            501 1834 1 0 12:51PM ?? 0:00.31 my_server.rb


            The files in the pid/log folder:



            $ ls /tmp/daemons-2013-01-25/
            my_server.rb.log my_server.rb1.pid my_server.rb_monitor.pid
            my_server.rb0.pid my_server.rb2.pid





            share|improve this answer












            I was able to reproduce the behavior. It is not anything you are doing wrong; it is the way the daemons gem behaves.



            Going through the code for the daemons gem, turns out the :multiple option doesn't work well with the :monitor option.



            The :monitor option works only when the daemon is run in single mode.



            I have created a bug report on the daemons project page referencing this question as the source.



            More info about the reproduction of the issue:



            Multiple daemon processes are created when :multiple => true. Each process has its own pid file in the format of <scriptname>.rb<number>.pid.



            However, only one monitor process is created (with a single <scriptname>.rb_monitor.pid file.)



            Here are the list of processes started when I start the daemon process 3 times:



            $ ps -fe | grep my_server
            501 1758 1 0 12:25PM ?? 0:00.63 my_server.rb
            501 1759 1 0 12:25PM ?? 0:00.43 my_server.rb_monitor
            501 1764 1 0 12:25PM ?? 0:00.54 my_server.rb
            501 1834 1 0 12:51PM ?? 0:00.31 my_server.rb


            The files in the pid/log folder:



            $ ls /tmp/daemons-2013-01-25/
            my_server.rb.log my_server.rb1.pid my_server.rb_monitor.pid
            my_server.rb0.pid my_server.rb2.pid






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 25 '13 at 9:22









            Prakash Murthy

            11k32859




            11k32859











            • The bug report given in the post appears to be a broken link. Here is an issue page on github. github.com/thuehlinger/daemons/issues/7
              – rude-n8
              Aug 25 '15 at 18:10

















            • The bug report given in the post appears to be a broken link. Here is an issue page on github. github.com/thuehlinger/daemons/issues/7
              – rude-n8
              Aug 25 '15 at 18:10
















            The bug report given in the post appears to be a broken link. Here is an issue page on github. github.com/thuehlinger/daemons/issues/7
            – rude-n8
            Aug 25 '15 at 18:10





            The bug report given in the post appears to be a broken link. Here is an issue page on github. github.com/thuehlinger/daemons/issues/7
            – rude-n8
            Aug 25 '15 at 18:10













            up vote
            0
            down vote













            Until the issue is resolved, you can change your code to something like this:



            #myapp_controller.rb
            require 'rubygems'
            require 'daemons'

            number = ARGV.fetch(1)

            options =
            :app_name => "daemon-#number" # provide app_name
            :log_output => true,
            :backtrace => true,
            :monitor => true,
            :multiple => false, # disable multiple option
            :log_dir => '/mnt/log/',
            :hard_exit => true

            Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


            And then start your daemons with these commands:



            ruby myapp_controller.rb start 1
            ruby myapp_controller.rb start 2
            ...


            This slightly changes your startup code, but now you will have a monitor process for each of your daemon processes.






            share|improve this answer
























              up vote
              0
              down vote













              Until the issue is resolved, you can change your code to something like this:



              #myapp_controller.rb
              require 'rubygems'
              require 'daemons'

              number = ARGV.fetch(1)

              options =
              :app_name => "daemon-#number" # provide app_name
              :log_output => true,
              :backtrace => true,
              :monitor => true,
              :multiple => false, # disable multiple option
              :log_dir => '/mnt/log/',
              :hard_exit => true

              Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


              And then start your daemons with these commands:



              ruby myapp_controller.rb start 1
              ruby myapp_controller.rb start 2
              ...


              This slightly changes your startup code, but now you will have a monitor process for each of your daemon processes.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Until the issue is resolved, you can change your code to something like this:



                #myapp_controller.rb
                require 'rubygems'
                require 'daemons'

                number = ARGV.fetch(1)

                options =
                :app_name => "daemon-#number" # provide app_name
                :log_output => true,
                :backtrace => true,
                :monitor => true,
                :multiple => false, # disable multiple option
                :log_dir => '/mnt/log/',
                :hard_exit => true

                Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


                And then start your daemons with these commands:



                ruby myapp_controller.rb start 1
                ruby myapp_controller.rb start 2
                ...


                This slightly changes your startup code, but now you will have a monitor process for each of your daemon processes.






                share|improve this answer












                Until the issue is resolved, you can change your code to something like this:



                #myapp_controller.rb
                require 'rubygems'
                require 'daemons'

                number = ARGV.fetch(1)

                options =
                :app_name => "daemon-#number" # provide app_name
                :log_output => true,
                :backtrace => true,
                :monitor => true,
                :multiple => false, # disable multiple option
                :log_dir => '/mnt/log/',
                :hard_exit => true

                Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)


                And then start your daemons with these commands:



                ruby myapp_controller.rb start 1
                ruby myapp_controller.rb start 2
                ...


                This slightly changes your startup code, but now you will have a monitor process for each of your daemon processes.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 17:18









                kolchan11

                11




                11



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2fstackoverflow.com%2fquestions%2f14515250%2fdaemons-do-not-get-restarted%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

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    ReactJS Fetched API data displays live - need Data displayed static

                    政党