Code Monkey home page Code Monkey logo

crono's Introduction

Crono

This repo will help you to schedule to restart containers at the same way as crontab, but inside the docker-compose file.

Requirements

A distro Linux, docker, docker-compose, some knowledg about it and Crontab.

Create your docker-compose.yml file.

version: '3'
services:

  service1:
    image: "postgres"
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=myStr0ngP4ssw0rd
    labels:
        crono: "* * * * *"

  service2:
    image: "postgres"
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=myStr0ngP4ssw0rd
    labels:
        crono: "@hourly"

  service3:
    image: "postgres"
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=myStr0ngP4ssw0rd
    labels:
        crono: "5 0 * 8 *"

  service4:
    image: "postgres"
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=myStr0ngP4ssw0rd
    labels:
        crono: "50-59 * * * 1-5"

See that inside each service I put a label called 'crono'. This will call to Crono that we want to restart it. The value of this will be the same like Crontab.
For help you, you can see crontab.guru at https://crontab.guru
You can infform some keys like @yearly, @annually, @monthly, @weekly, @daily or @hourly.

Put the Crono service

  crono:
    image: hudsonventura/crono:latest
    restart: always
    volumes:
        - "./docker-compose.yml:/app/docker-compose.yml" # point you docker-compose file
        - "/var/run/docker.sock:/var/run/docker.sock:ro"
    
    environment: 
        - TIMEZONE=America/Sao_Paulo
        - WAIT=3

The first one volume, you have to link your docker-compose file. Crono will read this file to work.

The second one volume, will used from Crono to call Docker Api.

The first one environment, you can identify a timezone. In my tests the default timezone inside container was +0UTC, so I created this.

The second one environment is the time that Crono will wait until all containers be up.
You also can use the docker-compose params called links.

The volumes params are mandatories, but the environments are optional.


The complete example file is in the directory examples.

If you want to compile you image ...


Change docker compose file to get local image:

crono:
    image: crono  #HERE
    restart: always
    volumes:
        - "./docker-compose.yml:/app/docker-compose.yml"
        - "/var/run/docker.sock:/var/run/docker.sock:ro"
    
    environment: 
        - TIMEZONE=America/Sao_Paulo
        - WAIT=3

On example directory, run it to build:
sudo docker compose down && \
cd .. && \
sudo docker build -t crono -f ./app/Dockerfile_x64_x86/Dockerfile ./app/ && \
cd example/ && \
sudo docker compose up

crono's People

Contributors

hudsonventura avatar

Watchers

 avatar

crono's Issues

Wrong scheduling

The scheduling below is not being respected. Today, 04/24, the container is being restarted.

*/5 6-20 1-10,25-31 * 1-5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.