Using supervisor as CRON












27














Is there any way to configure supervisor to run some command every X seconds(like CRON)?



I see example with eventlistener and TICK_ event



[eventlistener:memmon]
command=memmon -a 200MB -m bob@example.com
events=TICK_60


But it runs the command only once.










share|improve this question






















  • The answer is no, supervisord cannot run jobs like cron. Events does not do what you want.
    – aaa90210
    Mar 18 '15 at 22:12
















27














Is there any way to configure supervisor to run some command every X seconds(like CRON)?



I see example with eventlistener and TICK_ event



[eventlistener:memmon]
command=memmon -a 200MB -m bob@example.com
events=TICK_60


But it runs the command only once.










share|improve this question






















  • The answer is no, supervisord cannot run jobs like cron. Events does not do what you want.
    – aaa90210
    Mar 18 '15 at 22:12














27












27








27


10





Is there any way to configure supervisor to run some command every X seconds(like CRON)?



I see example with eventlistener and TICK_ event



[eventlistener:memmon]
command=memmon -a 200MB -m bob@example.com
events=TICK_60


But it runs the command only once.










share|improve this question













Is there any way to configure supervisor to run some command every X seconds(like CRON)?



I see example with eventlistener and TICK_ event



[eventlistener:memmon]
command=memmon -a 200MB -m bob@example.com
events=TICK_60


But it runs the command only once.







cron supervisord






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 7 '14 at 10:48









barbushin

3,08542939




3,08542939












  • The answer is no, supervisord cannot run jobs like cron. Events does not do what you want.
    – aaa90210
    Mar 18 '15 at 22:12


















  • The answer is no, supervisord cannot run jobs like cron. Events does not do what you want.
    – aaa90210
    Mar 18 '15 at 22:12
















The answer is no, supervisord cannot run jobs like cron. Events does not do what you want.
– aaa90210
Mar 18 '15 at 22:12




The answer is no, supervisord cannot run jobs like cron. Events does not do what you want.
– aaa90210
Mar 18 '15 at 22:12












5 Answers
5






active

oldest

votes


















18














Problem



As you are seeing in the memmon example, supervisord is not executing memmon -a 200MB -m bob@example.com at each event. Rather, it is starting this event listener once (or potentially a few times if you configure a pool) and then sends each new event over standard input of an existing process.



Solution



Consequently, you really need to find or write a supervisor compatible event listener for each additional type of capability you want to trigger on events.



Example Method of Implementation



Setup the configuration and write a listener



write a supervisord.cfg event section



[eventlistener:passthru]
command=/tmp/simple.py /bin/date -u +"%%s %%S:%%H:%%d:%%m"
events=TICK_60


(note- the escaping of % for configParser )



write a simple.py Event Listener



Create this simple.py listener by making changes to the example listener from the docs so it executes its first argument with any remaining arguments:



#! /usr/bin/python
import sys
import subprocess

def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()

def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()

def main(args):
while 1:
write_stdout('READYn') # transition from ACKNOWLEDGED to READY
line = sys.stdin.readline() # read header line from stdin
write_stderr(line) # print it out to stderr
headers = dict([ x.split(':') for x in line.split() ])
data = sys.stdin.read(int(headers['len'])) # read the event payload
res = subprocess.call(args, stdout=sys.stderr); # don't mess with real stdout
write_stderr(data)
write_stdout('RESULT 2nOK') # transition from READY to ACKNOWLEDGED

if __name__ == '__main__':
main(sys.argv[1:])
import sys


Make sure the supervisor configuration works



$ supervisorctl [-c cfg]
supervisor> status
passthru RUNNING pid 4471, uptime 0:00:32
supervisor> tail passthru
OKREADY
RESULT 2
OKREADY
...
supervisor> tail passthru stderr
supervisor> tail passthru stderr
ver:3.0 server:supervisor serial:0 pool:passthru poolserial:0 eventname:TICK_60 len:15
1451411161 01:17:29:12 <--- output
when:1451411160ver:3.0 server:supervisor serial:1 pool:passthru poolserial:1 eventname:TICK_60 len:15
1451411220 00:17:29:12 <--- output
when:1451411220


Now date -u +"%s %S:%H:%d:%m" is running every 60 seconds.



Swapping in the desired command



create an executable script



/tmp/hiworld.php:



#! /usr/bin/php
<?= "hiyan";


(chmod +x ...)



change the listener's arguments in supervisord.cfg



[eventlistener:passthru]
command=/tmp/simple.py /tmp/hiworld.php
;stdout_logfile=/tmp/passthru
events=TICK_60
;autorestart=true
;startsecs=0


reload supervisord and test
(reread seems not to detect this change)



supervisor> reload
Really restart the remote supervisord process y/N? y
Restarted supervisord
supervisor> status
passthru RUNNING pid 6017, uptime 0:00:10
supervisor> tail passthru stderr
supervisor> status
passthru RUNNING pid 6017, uptime 0:00:21
supervisor> status
passthru RUNNING pid 6017, uptime 0:01:01
supervisor> tail passthru stderr
ver:3.0 server:supervisor serial:316 pool:passthru poolserial:0 eventname:TICK_60 len:15
hiya
when:1418926740
supervisor>


End



Now the desired command is running every 60 seconds. You are now read to adjust particulars of permissions, locations, logs, etc.






share|improve this answer























  • I tried command=python /home/supervisor.py "php -f /home/test.php" and it does not work. I mean supervisorctl says that it's RUNNING, but test.php is never called. Can you provide some working example?
    – barbushin
    Dec 18 '14 at 0:51












  • In my example I would change: command=/tmp/simple.py /bin/date => command=/tmp/simple.py /home/test.php and put #! /.../php at the top of test.php. But removing the quotes and using the full path of php would probably work too.
    – lossleader
    Dec 18 '14 at 8:59










  • I tried everything. It does not work :(
    – barbushin
    Dec 18 '14 at 14:26










  • So it works only with commands without any arguments?
    – barbushin
    Dec 20 '14 at 11:58










  • It works fine with a command and its arguments, where the command is the first argument. As I said in my last comment, your attempt to quote a command and its arguments makes a single argument that is not an executable if you insist on quotes you must unwrap that with a shell. command= listener mycommand arg1 arg2 or command=listener /bin/sh -c "mycommand arg1 arg2" make sense, command=listener "mycommand arg1 arg2" does not.
    – lossleader
    Dec 20 '14 at 13:46



















6














Supervisor does not support this easily.



But to achieve your goal you can just use supervisor to start cron (for a docker container for instance):



https://gist.github.com/martinrusev/7015e393d46647dbad15






share|improve this answer





























    4














    Why invent the wheel? You can use cron and supervisord together.



    In supervisord, create a task with autostart=false



    In cron, use * * * * * supervisorctl start <taskname> to start the task every minute






    share|improve this answer





















    • Alex, following you solution, how we can manage task running schedule?
      – barbushin
      Aug 25 '17 at 8:02










    • Cron manages the schedule, the *'s mean once per minute.
      – kmarsh
      Mar 20 '18 at 14:24



















    1














    You can use crobtab to manage and schedule your supervisor programs.



    Use command supervisorctl start <program_name>



    Note: This will start only single instance of supervisor program. If it's already running and crontab tries to trigger it again, supervisorctl start command will not start a new instance.






    share|improve this answer





















    • This was already part of an answer nearly a year ago - is there anything additional you'd like to add?
      – Nico Haase
      Jun 21 '18 at 8:53






    • 1




      Yes, the part that cron will be able to run only one instance of supervisor program at any given time. Even if cron is triggered while supervisor program is still running, cron will not be able to start a new instance.
      – Raman
      Jun 21 '18 at 9:03



















    0














    You can call bash sleep command:



    [program:mycmd]
    command=bash -c 'sleep 300 && exec <your command here>'


    This will run your command every 5 minutes. Do not forget exec part to replace bash process with your command so supervisor will get correct exit code.






    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',
      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%2fstackoverflow.com%2fquestions%2f27341846%2fusing-supervisor-as-cron%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      18














      Problem



      As you are seeing in the memmon example, supervisord is not executing memmon -a 200MB -m bob@example.com at each event. Rather, it is starting this event listener once (or potentially a few times if you configure a pool) and then sends each new event over standard input of an existing process.



      Solution



      Consequently, you really need to find or write a supervisor compatible event listener for each additional type of capability you want to trigger on events.



      Example Method of Implementation



      Setup the configuration and write a listener



      write a supervisord.cfg event section



      [eventlistener:passthru]
      command=/tmp/simple.py /bin/date -u +"%%s %%S:%%H:%%d:%%m"
      events=TICK_60


      (note- the escaping of % for configParser )



      write a simple.py Event Listener



      Create this simple.py listener by making changes to the example listener from the docs so it executes its first argument with any remaining arguments:



      #! /usr/bin/python
      import sys
      import subprocess

      def write_stdout(s):
      sys.stdout.write(s)
      sys.stdout.flush()

      def write_stderr(s):
      sys.stderr.write(s)
      sys.stderr.flush()

      def main(args):
      while 1:
      write_stdout('READYn') # transition from ACKNOWLEDGED to READY
      line = sys.stdin.readline() # read header line from stdin
      write_stderr(line) # print it out to stderr
      headers = dict([ x.split(':') for x in line.split() ])
      data = sys.stdin.read(int(headers['len'])) # read the event payload
      res = subprocess.call(args, stdout=sys.stderr); # don't mess with real stdout
      write_stderr(data)
      write_stdout('RESULT 2nOK') # transition from READY to ACKNOWLEDGED

      if __name__ == '__main__':
      main(sys.argv[1:])
      import sys


      Make sure the supervisor configuration works



      $ supervisorctl [-c cfg]
      supervisor> status
      passthru RUNNING pid 4471, uptime 0:00:32
      supervisor> tail passthru
      OKREADY
      RESULT 2
      OKREADY
      ...
      supervisor> tail passthru stderr
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:0 pool:passthru poolserial:0 eventname:TICK_60 len:15
      1451411161 01:17:29:12 <--- output
      when:1451411160ver:3.0 server:supervisor serial:1 pool:passthru poolserial:1 eventname:TICK_60 len:15
      1451411220 00:17:29:12 <--- output
      when:1451411220


      Now date -u +"%s %S:%H:%d:%m" is running every 60 seconds.



      Swapping in the desired command



      create an executable script



      /tmp/hiworld.php:



      #! /usr/bin/php
      <?= "hiyan";


      (chmod +x ...)



      change the listener's arguments in supervisord.cfg



      [eventlistener:passthru]
      command=/tmp/simple.py /tmp/hiworld.php
      ;stdout_logfile=/tmp/passthru
      events=TICK_60
      ;autorestart=true
      ;startsecs=0


      reload supervisord and test
      (reread seems not to detect this change)



      supervisor> reload
      Really restart the remote supervisord process y/N? y
      Restarted supervisord
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:10
      supervisor> tail passthru stderr
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:21
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:01:01
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:316 pool:passthru poolserial:0 eventname:TICK_60 len:15
      hiya
      when:1418926740
      supervisor>


      End



      Now the desired command is running every 60 seconds. You are now read to adjust particulars of permissions, locations, logs, etc.






      share|improve this answer























      • I tried command=python /home/supervisor.py "php -f /home/test.php" and it does not work. I mean supervisorctl says that it's RUNNING, but test.php is never called. Can you provide some working example?
        – barbushin
        Dec 18 '14 at 0:51












      • In my example I would change: command=/tmp/simple.py /bin/date => command=/tmp/simple.py /home/test.php and put #! /.../php at the top of test.php. But removing the quotes and using the full path of php would probably work too.
        – lossleader
        Dec 18 '14 at 8:59










      • I tried everything. It does not work :(
        – barbushin
        Dec 18 '14 at 14:26










      • So it works only with commands without any arguments?
        – barbushin
        Dec 20 '14 at 11:58










      • It works fine with a command and its arguments, where the command is the first argument. As I said in my last comment, your attempt to quote a command and its arguments makes a single argument that is not an executable if you insist on quotes you must unwrap that with a shell. command= listener mycommand arg1 arg2 or command=listener /bin/sh -c "mycommand arg1 arg2" make sense, command=listener "mycommand arg1 arg2" does not.
        – lossleader
        Dec 20 '14 at 13:46
















      18














      Problem



      As you are seeing in the memmon example, supervisord is not executing memmon -a 200MB -m bob@example.com at each event. Rather, it is starting this event listener once (or potentially a few times if you configure a pool) and then sends each new event over standard input of an existing process.



      Solution



      Consequently, you really need to find or write a supervisor compatible event listener for each additional type of capability you want to trigger on events.



      Example Method of Implementation



      Setup the configuration and write a listener



      write a supervisord.cfg event section



      [eventlistener:passthru]
      command=/tmp/simple.py /bin/date -u +"%%s %%S:%%H:%%d:%%m"
      events=TICK_60


      (note- the escaping of % for configParser )



      write a simple.py Event Listener



      Create this simple.py listener by making changes to the example listener from the docs so it executes its first argument with any remaining arguments:



      #! /usr/bin/python
      import sys
      import subprocess

      def write_stdout(s):
      sys.stdout.write(s)
      sys.stdout.flush()

      def write_stderr(s):
      sys.stderr.write(s)
      sys.stderr.flush()

      def main(args):
      while 1:
      write_stdout('READYn') # transition from ACKNOWLEDGED to READY
      line = sys.stdin.readline() # read header line from stdin
      write_stderr(line) # print it out to stderr
      headers = dict([ x.split(':') for x in line.split() ])
      data = sys.stdin.read(int(headers['len'])) # read the event payload
      res = subprocess.call(args, stdout=sys.stderr); # don't mess with real stdout
      write_stderr(data)
      write_stdout('RESULT 2nOK') # transition from READY to ACKNOWLEDGED

      if __name__ == '__main__':
      main(sys.argv[1:])
      import sys


      Make sure the supervisor configuration works



      $ supervisorctl [-c cfg]
      supervisor> status
      passthru RUNNING pid 4471, uptime 0:00:32
      supervisor> tail passthru
      OKREADY
      RESULT 2
      OKREADY
      ...
      supervisor> tail passthru stderr
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:0 pool:passthru poolserial:0 eventname:TICK_60 len:15
      1451411161 01:17:29:12 <--- output
      when:1451411160ver:3.0 server:supervisor serial:1 pool:passthru poolserial:1 eventname:TICK_60 len:15
      1451411220 00:17:29:12 <--- output
      when:1451411220


      Now date -u +"%s %S:%H:%d:%m" is running every 60 seconds.



      Swapping in the desired command



      create an executable script



      /tmp/hiworld.php:



      #! /usr/bin/php
      <?= "hiyan";


      (chmod +x ...)



      change the listener's arguments in supervisord.cfg



      [eventlistener:passthru]
      command=/tmp/simple.py /tmp/hiworld.php
      ;stdout_logfile=/tmp/passthru
      events=TICK_60
      ;autorestart=true
      ;startsecs=0


      reload supervisord and test
      (reread seems not to detect this change)



      supervisor> reload
      Really restart the remote supervisord process y/N? y
      Restarted supervisord
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:10
      supervisor> tail passthru stderr
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:21
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:01:01
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:316 pool:passthru poolserial:0 eventname:TICK_60 len:15
      hiya
      when:1418926740
      supervisor>


      End



      Now the desired command is running every 60 seconds. You are now read to adjust particulars of permissions, locations, logs, etc.






      share|improve this answer























      • I tried command=python /home/supervisor.py "php -f /home/test.php" and it does not work. I mean supervisorctl says that it's RUNNING, but test.php is never called. Can you provide some working example?
        – barbushin
        Dec 18 '14 at 0:51












      • In my example I would change: command=/tmp/simple.py /bin/date => command=/tmp/simple.py /home/test.php and put #! /.../php at the top of test.php. But removing the quotes and using the full path of php would probably work too.
        – lossleader
        Dec 18 '14 at 8:59










      • I tried everything. It does not work :(
        – barbushin
        Dec 18 '14 at 14:26










      • So it works only with commands without any arguments?
        – barbushin
        Dec 20 '14 at 11:58










      • It works fine with a command and its arguments, where the command is the first argument. As I said in my last comment, your attempt to quote a command and its arguments makes a single argument that is not an executable if you insist on quotes you must unwrap that with a shell. command= listener mycommand arg1 arg2 or command=listener /bin/sh -c "mycommand arg1 arg2" make sense, command=listener "mycommand arg1 arg2" does not.
        – lossleader
        Dec 20 '14 at 13:46














      18












      18








      18






      Problem



      As you are seeing in the memmon example, supervisord is not executing memmon -a 200MB -m bob@example.com at each event. Rather, it is starting this event listener once (or potentially a few times if you configure a pool) and then sends each new event over standard input of an existing process.



      Solution



      Consequently, you really need to find or write a supervisor compatible event listener for each additional type of capability you want to trigger on events.



      Example Method of Implementation



      Setup the configuration and write a listener



      write a supervisord.cfg event section



      [eventlistener:passthru]
      command=/tmp/simple.py /bin/date -u +"%%s %%S:%%H:%%d:%%m"
      events=TICK_60


      (note- the escaping of % for configParser )



      write a simple.py Event Listener



      Create this simple.py listener by making changes to the example listener from the docs so it executes its first argument with any remaining arguments:



      #! /usr/bin/python
      import sys
      import subprocess

      def write_stdout(s):
      sys.stdout.write(s)
      sys.stdout.flush()

      def write_stderr(s):
      sys.stderr.write(s)
      sys.stderr.flush()

      def main(args):
      while 1:
      write_stdout('READYn') # transition from ACKNOWLEDGED to READY
      line = sys.stdin.readline() # read header line from stdin
      write_stderr(line) # print it out to stderr
      headers = dict([ x.split(':') for x in line.split() ])
      data = sys.stdin.read(int(headers['len'])) # read the event payload
      res = subprocess.call(args, stdout=sys.stderr); # don't mess with real stdout
      write_stderr(data)
      write_stdout('RESULT 2nOK') # transition from READY to ACKNOWLEDGED

      if __name__ == '__main__':
      main(sys.argv[1:])
      import sys


      Make sure the supervisor configuration works



      $ supervisorctl [-c cfg]
      supervisor> status
      passthru RUNNING pid 4471, uptime 0:00:32
      supervisor> tail passthru
      OKREADY
      RESULT 2
      OKREADY
      ...
      supervisor> tail passthru stderr
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:0 pool:passthru poolserial:0 eventname:TICK_60 len:15
      1451411161 01:17:29:12 <--- output
      when:1451411160ver:3.0 server:supervisor serial:1 pool:passthru poolserial:1 eventname:TICK_60 len:15
      1451411220 00:17:29:12 <--- output
      when:1451411220


      Now date -u +"%s %S:%H:%d:%m" is running every 60 seconds.



      Swapping in the desired command



      create an executable script



      /tmp/hiworld.php:



      #! /usr/bin/php
      <?= "hiyan";


      (chmod +x ...)



      change the listener's arguments in supervisord.cfg



      [eventlistener:passthru]
      command=/tmp/simple.py /tmp/hiworld.php
      ;stdout_logfile=/tmp/passthru
      events=TICK_60
      ;autorestart=true
      ;startsecs=0


      reload supervisord and test
      (reread seems not to detect this change)



      supervisor> reload
      Really restart the remote supervisord process y/N? y
      Restarted supervisord
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:10
      supervisor> tail passthru stderr
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:21
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:01:01
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:316 pool:passthru poolserial:0 eventname:TICK_60 len:15
      hiya
      when:1418926740
      supervisor>


      End



      Now the desired command is running every 60 seconds. You are now read to adjust particulars of permissions, locations, logs, etc.






      share|improve this answer














      Problem



      As you are seeing in the memmon example, supervisord is not executing memmon -a 200MB -m bob@example.com at each event. Rather, it is starting this event listener once (or potentially a few times if you configure a pool) and then sends each new event over standard input of an existing process.



      Solution



      Consequently, you really need to find or write a supervisor compatible event listener for each additional type of capability you want to trigger on events.



      Example Method of Implementation



      Setup the configuration and write a listener



      write a supervisord.cfg event section



      [eventlistener:passthru]
      command=/tmp/simple.py /bin/date -u +"%%s %%S:%%H:%%d:%%m"
      events=TICK_60


      (note- the escaping of % for configParser )



      write a simple.py Event Listener



      Create this simple.py listener by making changes to the example listener from the docs so it executes its first argument with any remaining arguments:



      #! /usr/bin/python
      import sys
      import subprocess

      def write_stdout(s):
      sys.stdout.write(s)
      sys.stdout.flush()

      def write_stderr(s):
      sys.stderr.write(s)
      sys.stderr.flush()

      def main(args):
      while 1:
      write_stdout('READYn') # transition from ACKNOWLEDGED to READY
      line = sys.stdin.readline() # read header line from stdin
      write_stderr(line) # print it out to stderr
      headers = dict([ x.split(':') for x in line.split() ])
      data = sys.stdin.read(int(headers['len'])) # read the event payload
      res = subprocess.call(args, stdout=sys.stderr); # don't mess with real stdout
      write_stderr(data)
      write_stdout('RESULT 2nOK') # transition from READY to ACKNOWLEDGED

      if __name__ == '__main__':
      main(sys.argv[1:])
      import sys


      Make sure the supervisor configuration works



      $ supervisorctl [-c cfg]
      supervisor> status
      passthru RUNNING pid 4471, uptime 0:00:32
      supervisor> tail passthru
      OKREADY
      RESULT 2
      OKREADY
      ...
      supervisor> tail passthru stderr
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:0 pool:passthru poolserial:0 eventname:TICK_60 len:15
      1451411161 01:17:29:12 <--- output
      when:1451411160ver:3.0 server:supervisor serial:1 pool:passthru poolserial:1 eventname:TICK_60 len:15
      1451411220 00:17:29:12 <--- output
      when:1451411220


      Now date -u +"%s %S:%H:%d:%m" is running every 60 seconds.



      Swapping in the desired command



      create an executable script



      /tmp/hiworld.php:



      #! /usr/bin/php
      <?= "hiyan";


      (chmod +x ...)



      change the listener's arguments in supervisord.cfg



      [eventlistener:passthru]
      command=/tmp/simple.py /tmp/hiworld.php
      ;stdout_logfile=/tmp/passthru
      events=TICK_60
      ;autorestart=true
      ;startsecs=0


      reload supervisord and test
      (reread seems not to detect this change)



      supervisor> reload
      Really restart the remote supervisord process y/N? y
      Restarted supervisord
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:10
      supervisor> tail passthru stderr
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:00:21
      supervisor> status
      passthru RUNNING pid 6017, uptime 0:01:01
      supervisor> tail passthru stderr
      ver:3.0 server:supervisor serial:316 pool:passthru poolserial:0 eventname:TICK_60 len:15
      hiya
      when:1418926740
      supervisor>


      End



      Now the desired command is running every 60 seconds. You are now read to adjust particulars of permissions, locations, logs, etc.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jun 29 '17 at 13:28









      mkobit

      20.4k68499




      20.4k68499










      answered Dec 13 '14 at 20:37









      lossleader

      9,28011829




      9,28011829












      • I tried command=python /home/supervisor.py "php -f /home/test.php" and it does not work. I mean supervisorctl says that it's RUNNING, but test.php is never called. Can you provide some working example?
        – barbushin
        Dec 18 '14 at 0:51












      • In my example I would change: command=/tmp/simple.py /bin/date => command=/tmp/simple.py /home/test.php and put #! /.../php at the top of test.php. But removing the quotes and using the full path of php would probably work too.
        – lossleader
        Dec 18 '14 at 8:59










      • I tried everything. It does not work :(
        – barbushin
        Dec 18 '14 at 14:26










      • So it works only with commands without any arguments?
        – barbushin
        Dec 20 '14 at 11:58










      • It works fine with a command and its arguments, where the command is the first argument. As I said in my last comment, your attempt to quote a command and its arguments makes a single argument that is not an executable if you insist on quotes you must unwrap that with a shell. command= listener mycommand arg1 arg2 or command=listener /bin/sh -c "mycommand arg1 arg2" make sense, command=listener "mycommand arg1 arg2" does not.
        – lossleader
        Dec 20 '14 at 13:46


















      • I tried command=python /home/supervisor.py "php -f /home/test.php" and it does not work. I mean supervisorctl says that it's RUNNING, but test.php is never called. Can you provide some working example?
        – barbushin
        Dec 18 '14 at 0:51












      • In my example I would change: command=/tmp/simple.py /bin/date => command=/tmp/simple.py /home/test.php and put #! /.../php at the top of test.php. But removing the quotes and using the full path of php would probably work too.
        – lossleader
        Dec 18 '14 at 8:59










      • I tried everything. It does not work :(
        – barbushin
        Dec 18 '14 at 14:26










      • So it works only with commands without any arguments?
        – barbushin
        Dec 20 '14 at 11:58










      • It works fine with a command and its arguments, where the command is the first argument. As I said in my last comment, your attempt to quote a command and its arguments makes a single argument that is not an executable if you insist on quotes you must unwrap that with a shell. command= listener mycommand arg1 arg2 or command=listener /bin/sh -c "mycommand arg1 arg2" make sense, command=listener "mycommand arg1 arg2" does not.
        – lossleader
        Dec 20 '14 at 13:46
















      I tried command=python /home/supervisor.py "php -f /home/test.php" and it does not work. I mean supervisorctl says that it's RUNNING, but test.php is never called. Can you provide some working example?
      – barbushin
      Dec 18 '14 at 0:51






      I tried command=python /home/supervisor.py "php -f /home/test.php" and it does not work. I mean supervisorctl says that it's RUNNING, but test.php is never called. Can you provide some working example?
      – barbushin
      Dec 18 '14 at 0:51














      In my example I would change: command=/tmp/simple.py /bin/date => command=/tmp/simple.py /home/test.php and put #! /.../php at the top of test.php. But removing the quotes and using the full path of php would probably work too.
      – lossleader
      Dec 18 '14 at 8:59




      In my example I would change: command=/tmp/simple.py /bin/date => command=/tmp/simple.py /home/test.php and put #! /.../php at the top of test.php. But removing the quotes and using the full path of php would probably work too.
      – lossleader
      Dec 18 '14 at 8:59












      I tried everything. It does not work :(
      – barbushin
      Dec 18 '14 at 14:26




      I tried everything. It does not work :(
      – barbushin
      Dec 18 '14 at 14:26












      So it works only with commands without any arguments?
      – barbushin
      Dec 20 '14 at 11:58




      So it works only with commands without any arguments?
      – barbushin
      Dec 20 '14 at 11:58












      It works fine with a command and its arguments, where the command is the first argument. As I said in my last comment, your attempt to quote a command and its arguments makes a single argument that is not an executable if you insist on quotes you must unwrap that with a shell. command= listener mycommand arg1 arg2 or command=listener /bin/sh -c "mycommand arg1 arg2" make sense, command=listener "mycommand arg1 arg2" does not.
      – lossleader
      Dec 20 '14 at 13:46




      It works fine with a command and its arguments, where the command is the first argument. As I said in my last comment, your attempt to quote a command and its arguments makes a single argument that is not an executable if you insist on quotes you must unwrap that with a shell. command= listener mycommand arg1 arg2 or command=listener /bin/sh -c "mycommand arg1 arg2" make sense, command=listener "mycommand arg1 arg2" does not.
      – lossleader
      Dec 20 '14 at 13:46













      6














      Supervisor does not support this easily.



      But to achieve your goal you can just use supervisor to start cron (for a docker container for instance):



      https://gist.github.com/martinrusev/7015e393d46647dbad15






      share|improve this answer


























        6














        Supervisor does not support this easily.



        But to achieve your goal you can just use supervisor to start cron (for a docker container for instance):



        https://gist.github.com/martinrusev/7015e393d46647dbad15






        share|improve this answer
























          6












          6








          6






          Supervisor does not support this easily.



          But to achieve your goal you can just use supervisor to start cron (for a docker container for instance):



          https://gist.github.com/martinrusev/7015e393d46647dbad15






          share|improve this answer












          Supervisor does not support this easily.



          But to achieve your goal you can just use supervisor to start cron (for a docker container for instance):



          https://gist.github.com/martinrusev/7015e393d46647dbad15







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 10 '15 at 16:02









          wid

          18614




          18614























              4














              Why invent the wheel? You can use cron and supervisord together.



              In supervisord, create a task with autostart=false



              In cron, use * * * * * supervisorctl start <taskname> to start the task every minute






              share|improve this answer





















              • Alex, following you solution, how we can manage task running schedule?
                – barbushin
                Aug 25 '17 at 8:02










              • Cron manages the schedule, the *'s mean once per minute.
                – kmarsh
                Mar 20 '18 at 14:24
















              4














              Why invent the wheel? You can use cron and supervisord together.



              In supervisord, create a task with autostart=false



              In cron, use * * * * * supervisorctl start <taskname> to start the task every minute






              share|improve this answer





















              • Alex, following you solution, how we can manage task running schedule?
                – barbushin
                Aug 25 '17 at 8:02










              • Cron manages the schedule, the *'s mean once per minute.
                – kmarsh
                Mar 20 '18 at 14:24














              4












              4








              4






              Why invent the wheel? You can use cron and supervisord together.



              In supervisord, create a task with autostart=false



              In cron, use * * * * * supervisorctl start <taskname> to start the task every minute






              share|improve this answer












              Why invent the wheel? You can use cron and supervisord together.



              In supervisord, create a task with autostart=false



              In cron, use * * * * * supervisorctl start <taskname> to start the task every minute







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 23 '17 at 5:01









              AlexM

              1,96611114




              1,96611114












              • Alex, following you solution, how we can manage task running schedule?
                – barbushin
                Aug 25 '17 at 8:02










              • Cron manages the schedule, the *'s mean once per minute.
                – kmarsh
                Mar 20 '18 at 14:24


















              • Alex, following you solution, how we can manage task running schedule?
                – barbushin
                Aug 25 '17 at 8:02










              • Cron manages the schedule, the *'s mean once per minute.
                – kmarsh
                Mar 20 '18 at 14:24
















              Alex, following you solution, how we can manage task running schedule?
              – barbushin
              Aug 25 '17 at 8:02




              Alex, following you solution, how we can manage task running schedule?
              – barbushin
              Aug 25 '17 at 8:02












              Cron manages the schedule, the *'s mean once per minute.
              – kmarsh
              Mar 20 '18 at 14:24




              Cron manages the schedule, the *'s mean once per minute.
              – kmarsh
              Mar 20 '18 at 14:24











              1














              You can use crobtab to manage and schedule your supervisor programs.



              Use command supervisorctl start <program_name>



              Note: This will start only single instance of supervisor program. If it's already running and crontab tries to trigger it again, supervisorctl start command will not start a new instance.






              share|improve this answer





















              • This was already part of an answer nearly a year ago - is there anything additional you'd like to add?
                – Nico Haase
                Jun 21 '18 at 8:53






              • 1




                Yes, the part that cron will be able to run only one instance of supervisor program at any given time. Even if cron is triggered while supervisor program is still running, cron will not be able to start a new instance.
                – Raman
                Jun 21 '18 at 9:03
















              1














              You can use crobtab to manage and schedule your supervisor programs.



              Use command supervisorctl start <program_name>



              Note: This will start only single instance of supervisor program. If it's already running and crontab tries to trigger it again, supervisorctl start command will not start a new instance.






              share|improve this answer





















              • This was already part of an answer nearly a year ago - is there anything additional you'd like to add?
                – Nico Haase
                Jun 21 '18 at 8:53






              • 1




                Yes, the part that cron will be able to run only one instance of supervisor program at any given time. Even if cron is triggered while supervisor program is still running, cron will not be able to start a new instance.
                – Raman
                Jun 21 '18 at 9:03














              1












              1








              1






              You can use crobtab to manage and schedule your supervisor programs.



              Use command supervisorctl start <program_name>



              Note: This will start only single instance of supervisor program. If it's already running and crontab tries to trigger it again, supervisorctl start command will not start a new instance.






              share|improve this answer












              You can use crobtab to manage and schedule your supervisor programs.



              Use command supervisorctl start <program_name>



              Note: This will start only single instance of supervisor program. If it's already running and crontab tries to trigger it again, supervisorctl start command will not start a new instance.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 21 '18 at 8:29









              Raman

              113




              113












              • This was already part of an answer nearly a year ago - is there anything additional you'd like to add?
                – Nico Haase
                Jun 21 '18 at 8:53






              • 1




                Yes, the part that cron will be able to run only one instance of supervisor program at any given time. Even if cron is triggered while supervisor program is still running, cron will not be able to start a new instance.
                – Raman
                Jun 21 '18 at 9:03


















              • This was already part of an answer nearly a year ago - is there anything additional you'd like to add?
                – Nico Haase
                Jun 21 '18 at 8:53






              • 1




                Yes, the part that cron will be able to run only one instance of supervisor program at any given time. Even if cron is triggered while supervisor program is still running, cron will not be able to start a new instance.
                – Raman
                Jun 21 '18 at 9:03
















              This was already part of an answer nearly a year ago - is there anything additional you'd like to add?
              – Nico Haase
              Jun 21 '18 at 8:53




              This was already part of an answer nearly a year ago - is there anything additional you'd like to add?
              – Nico Haase
              Jun 21 '18 at 8:53




              1




              1




              Yes, the part that cron will be able to run only one instance of supervisor program at any given time. Even if cron is triggered while supervisor program is still running, cron will not be able to start a new instance.
              – Raman
              Jun 21 '18 at 9:03




              Yes, the part that cron will be able to run only one instance of supervisor program at any given time. Even if cron is triggered while supervisor program is still running, cron will not be able to start a new instance.
              – Raman
              Jun 21 '18 at 9:03











              0














              You can call bash sleep command:



              [program:mycmd]
              command=bash -c 'sleep 300 && exec <your command here>'


              This will run your command every 5 minutes. Do not forget exec part to replace bash process with your command so supervisor will get correct exit code.






              share|improve this answer


























                0














                You can call bash sleep command:



                [program:mycmd]
                command=bash -c 'sleep 300 && exec <your command here>'


                This will run your command every 5 minutes. Do not forget exec part to replace bash process with your command so supervisor will get correct exit code.






                share|improve this answer
























                  0












                  0








                  0






                  You can call bash sleep command:



                  [program:mycmd]
                  command=bash -c 'sleep 300 && exec <your command here>'


                  This will run your command every 5 minutes. Do not forget exec part to replace bash process with your command so supervisor will get correct exit code.






                  share|improve this answer












                  You can call bash sleep command:



                  [program:mycmd]
                  command=bash -c 'sleep 300 && exec <your command here>'


                  This will run your command every 5 minutes. Do not forget exec part to replace bash process with your command so supervisor will get correct exit code.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 16:09









                  mixel

                  15.4k584122




                  15.4k584122






























                      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%2f27341846%2fusing-supervisor-as-cron%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

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      TypeError: fit_transform() missing 1 required positional argument: 'X'