# Run an action every 30 seconds

**URL:** <https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884>\
**Category:** NGINX\
**Created:** [February 8, 2011, 11:38am UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884 "2011-02-08T11:38:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 8, 2011, 11:38am UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/1 "2011-02-08T11:38:57Z")

</div>

Hello,  
I would like my Nginx server to run every 30 seconds a service job. This  
job will just send a message to another server that the nginx is running  
and OK. Does anybody know how to do it?  
I have just one idea - to write a module that will send the OK message  
to another server. Then cron will run each 1 minute (unfortunately 30  
seconds is not possible) a script that will send a request to the  
module.

Thanks in advance for your ideas,  
Michal

Posted at Nginx Forum:

> **[run an action every 30 seconds](https://forum.nginx.org/read.php?2,173142,173142#msg-173142)**
>
> Hello, I would like my Nginx server to run every 30 seconds a service job. This job will just send a message to another server that the nginx is running and OK. Does anybody know how to do it? I have just one idea - to write a module that will send...

---

<div class="post-metadata">

**Author:** ![michalkraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@michalkraus](https://www.ruby-forum.com/u/michalkraus)\
**Post date:** [February 8, 2011, 11:59am UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/2 "2011-02-08T11:59:43Z")

</div>

how about linux crond?i think it will be much easier than moudle.

在 2011-2-8 下午6:37，“michalkraus” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)写道：

> Michal
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,173142,173142#msg-173142](http://forum.nginx.org/read.php?2,173142,173142#msg-173142)

---

<div class="post-metadata">

**Author:** ![michalkraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@michalkraus](https://www.ruby-forum.com/u/michalkraus)\
**Post date:** [February 8, 2011, 12:07pm UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/3 "2011-02-08T12:07:54Z")

</div>

Two options:

1. Use cron if you can accept minimum 1 minute between every launch.
2. Use a a script with a sleep() instruction and verify that the script  
is  
always running.
3. Use a heartbeat solution - [http://linux-ha.org/wiki/Main\_Page](http://linux-ha.org/wiki/Main_Page)

- Gregory

2011/2/8 baalchina [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![michalkraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@michalkraus](https://www.ruby-forum.com/u/michalkraus)\
**Post date:** [February 8, 2011, 12:08pm UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/4 "2011-02-08T12:08:31Z")

</div>

Three options:

1. Cron if you can wait 1 minute.
2. Script always running with sleep() instruction and check that the  
script  
is always running.
3. HA/Heartbeat - [http://linux-ha.org/wiki/Main\_Page](http://linux-ha.org/wiki/Main_Page)

- Gregory

2011/2/8 baalchina [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![michalkraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@michalkraus](https://www.ruby-forum.com/u/michalkraus)\
**Post date:** [February 8, 2011, 12:12pm UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/5 "2011-02-08T12:12:16Z")

</div>

On 08/02/11 11:05, Gregory Agerba wrote:

> Two options:
> 
> 1. Use cron if you can accept minimum 1 minute between every launch.
> 2. Use a a script with a sleep() instruction and verify that the script is  
> always running.
> 3. Use a heartbeat solution - [http://linux-ha.org/wiki/Main\_Page](http://linux-ha.org/wiki/Main_Page)

1. Use cron to start a script which does the test, sleeps for 30s, then  
does  
the test again, then dies (to be restarted by cron at the next minute)

–  
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450  
Registered in England (0456 0902) @ 13 Clarke Rd, Milton Keynes, MK1 1LG

---

<div class="post-metadata">

**Author:** ![michalkraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@michalkraus](https://www.ruby-forum.com/u/michalkraus)\
**Post date:** [February 8, 2011, 12:36pm UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/6 "2011-02-08T12:36:44Z")

</div>

Thanks for your options

> 1. Use a heartbeat solution - [http://linux-ha.org/wiki/Main\_Page](http://linux-ha.org/wiki/Main_Page)

I have API between the Nginx and the second (control) server. I use RPC  
interface. I need just send a RPC request (with status infrmation) to  
the control server. I think that heartbeat is too robust.

> 1. Use cron to start a script which does the test, sleeps for 30s,  
> then does  
> the test again, then dies (to be restarted by cron  
> at the next minute)

This option seems to be the best but is any possibility the nginx to do  
it in its own?

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,173142,173166#msg-173166](http://forum.nginx.org/read.php?2,173142,173166#msg-173166)

---

<div class="post-metadata">

**Author:** ![michalkraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@michalkraus](https://www.ruby-forum.com/u/michalkraus)\
**Post date:** [February 8, 2011, 12:26pm UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/7 "2011-02-08T12:26:06Z")

</div>

On 8 Fev 2011 10h37 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello, I would like my Nginx server to run every 30 seconds a  
> service job. This job will just send a message to another server  
> that the nginx is running and OK. Does anybody know how to do it? I  
> have just one idea - to write a module that will send the OK message  
> to another server. Then cron will run each 1 minute (unfortunately  
> 30 seconds is not possible) a script that will send a request to the  
> module.

Use the [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpEchoModule) and a cron job that  
checks a certain location and posts the message you wnat using curl to  
the other server.

Just an idea

— appa

---

<div class="post-metadata">

**Author:** ![michalkraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@michalkraus](https://www.ruby-forum.com/u/michalkraus)\
**Post date:** [February 8, 2011, 1:04pm UTC](https://www.ruby-forum.com/t/run-an-action-every-30-seconds/202884/8 "2011-02-08T13:04:26Z")

</div>

server {  
listen 8082;  
server\_name localhost;

```
    location = /a-help2 {
        content_by_lua 'ngx.say(ngx.time())';
    }
    location = /a-help {
        proxy_pass http://127.0.0.1:8082/a-help2;
    }
    location = /a {
        echo_location /a-help;
        echo_sleep 2;
        echo_location /a-help;
    }
}

```

start a cron job to curl localhost:8082/a  
just a sample conf.

require nginx-echo module( [GitHub - openresty/echo-nginx-module: An Nginx module for bringing the power of "echo", "sleep", "time" and more to Nginx's config file · GitHub](https://github.com/agentzh/echo-nginx-module)  
)

On Tue, Feb 8, 2011 at 7:35 PM, michalkraus [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > the test again, then dies (to be restarted by cron  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Regards,

林青(Kindy Lin)
