• Stars
    star
    3,002
  • Rank 15,052 (Top 0.3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A docker job scheduler (aka. crontab for docker)

Ofelia - a job scheduler GitHub version Test

Ofelia is a modern and low footprint job scheduler for docker environments, built on Go. Ofelia aims to be a replacement for the old fashioned cron.

Why?

It has been a long time since cron was released, actually more than 28 years. The world has changed a lot and especially since the Docker revolution. Vixie's cron works great but it's not extensible and it's hard to debug when something goes wrong.

Many solutions are available: ready to go containerized crons, wrappers for your commands, etc. but in the end simple tasks become complex.

How?

The main feature of Ofelia is the ability to execute commands directly on Docker containers. Using Docker's API Ofelia emulates the behavior of exec, being able to run a command inside of a running container. Also you can run the command in a new container destroying it at the end of the execution.

Configuration

Jobs

Scheduling format is the same as the Go implementation of cron. E.g. @every 10s or 0 0 1 * * * (every night at 1 AM).

Note: the format starts with seconds, instead of minutes.

you can configure four different kind of jobs:

  • job-exec: this job is executed inside of a running container.
  • job-run: runs a command inside of a new container, using a specific image.
  • job-local: runs the command inside of the host running ofelia.
  • job-service-run: runs the command inside a new "run-once" service, for running inside a swarm

See Jobs reference documentation for all available parameters.

INI-style config

Run with ofelia daemon --config=/path/to/config.ini

[job-exec "job-executed-on-running-container"]
schedule = @hourly
container = my-container
command = touch /tmp/example

[job-run "job-executed-on-new-container"]
schedule = @hourly
image = ubuntu:latest
command = touch /tmp/example

[job-local "job-executed-on-current-host"]
schedule = @hourly
command = touch /tmp/example


[job-service-run "service-executed-on-new-container"]
schedule = 0,20,40 * * * *
image = ubuntu
network = swarm_network
command =  touch /tmp/example

Docker labels configurations

In order to use this type of configurations, ofelia need access to docker socket.

docker run -it --rm \
    -v /var/run/docker.sock:/var/run/docker.sock:ro \
    --label ofelia.job-local.my-test-job.schedule="@every 5s" \
    --label ofelia.job-local.my-test-job.command="date" \
        mcuadros/ofelia:latest daemon --docker

Labels format: ofelia.<JOB_TYPE>.<JOB_NAME>.<JOB_PARAMETER>=<PARAMETER_VALUE>. This type of configuration supports all the capabilities provided by INI files.

Also, it is possible to configure job-exec by setting labels configurations on the target container. To do that, additional label ofelia.enabled=true need to be present on the target container.

For example, we want ofelia to execute uname -a command in the existing container called my_nginx. To do that, we need to we need to start my_nginx container with next configurations:

docker run -it --rm \
    --label ofelia.enabled=true \
    --label ofelia.job-exec.test-exec-job.schedule="@every 5s" \
    --label ofelia.job-exec.test-exec-job.command="uname -a" \
        nginx

Now if we start ofelia container with the command provided above, it will pickup 2 jobs:

  • Local - date
  • Exec - uname -a

Or with docker-compose:

version: "3"
services:
  ofelia:
    image: mcuadros/ofelia:latest
    depends_on:
      - nginx
    command: daemon --docker
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    labels:
      ofelia.job-local.my-test-job.schedule: "@every 5s"
      ofelia.job-local.my-test-job.command: "date"

  nginx:
    image: nginx
    labels:
      ofelia.enabled: "true"
      ofelia.job-exec.datecron.schedule: "@every 5s"
      ofelia.job-exec.datecron.command: "uname -a"

Logging

Ofelia comes with three different logging drivers that can be configured in the [global] section:

  • mail to send mails
  • save to save structured execution reports to a directory
  • slack to send messages via a slack webhook

Options

  • smtp-host - address of the SMTP server.

  • smtp-port - port number of the SMTP server.

  • smtp-user - user name used to connect to the SMTP server.

  • smtp-password - password used to connect to the SMTP server.

  • smtp-tls-skip-verify - when true ignores certificate signed by unknown authority error.

  • email-to - mail address of the receiver of the mail.

  • email-from - mail address of the sender of the mail.

  • mail-only-on-error - only send a mail if the execution was not successful.

  • save-folder - directory in which the reports shall be written.

  • save-only-on-error - only save a report if the execution was not successful.

  • slack-webhook - URL of the slack webhook.

  • slack-only-on-error - only send a slack message if the execution was not successful.

Overlap

Ofelia can prevent that a job is run twice in parallel (e.g. if the first execution didn't complete before a second execution was scheduled. If a job has the option no-overlap set, it will not be run concurrently.

Installation

The easiest way to deploy ofelia is using Docker. See examples above.

If don't want to run ofelia using our Docker image you can download a binary from releases page.

Why the project is named Ofelia? Ofelia is the name of the office assistant from the Spanish comic Mortadelo y Filemón

More Repositories

1

go-syslog

Syslog server library for go.
Go
513
star
2

go-candyjs

fully transparent bridge between Go and the JavaScript
Go
455
star
3

dockership

dead simple docker deploy tool
Go
302
star
4

go-defaults

Go structures with default values using tags
Go
274
star
5

OctoPrint-TFT

A OctoPrint touch interface for TFT touch modules based on GTK+3
Go
171
star
6

go-version

Version normalizer and comparison library for go
Go
136
star
7

go-jsonschema-generator

json-schemas generator based on Go types
Go
118
star
8

ascode

AsCode - Terraform Alternative Syntax
Go
111
star
9

homebrew-hhvm

HHVM repository for Homebrew
Ruby
103
star
10

go-rpi-rgb-led-matrix

Go binding for rpi-rgb-led-matrix an excellent C++ library to control RGB LED displays with Raspberry Pi GPIO.
Go
83
star
11

pynats

[Abandoned] A Python client for the NATS messaging system.
Python
75
star
12

gce-docker

Google Cloud Engine integration for Docker
Go
59
star
13

go-rpi-ws281x

Go bindings for Raspberry Pi PWM library for WS281X LEDs
Go
41
star
14

go-lookup

Small library on top of reflect for make lookups to any Structs or Maps
Go
36
star
15

go-monitor

a simple and extensible way to build monitorizable go process via HTTP.
Go
32
star
16

rocketizer

[Abandoned] Painless Dockerfile transformation to Rocket containers
Go
28
star
17

go-stable

Golang fixed versions tool for your private and public dependencies
Go
23
star
18

passage

SSH tunnels on steroids
Go
22
star
19

go-crxmake

CRX Package generator
Go
19
star
20

currency-detector

Class to detect the currency from any string
PHP
19
star
21

go-rat

tar extension for random access
Go
19
star
22

php-cayley

PHP wrapper of the Google's Cayley graph database REST interface
PHP
18
star
23

go-octoprint

Go library for accessing the OctoPrint's REST API
Go
17
star
24

go-composer

Basic replacement of Composer, the Dependency Manager for PHP
Go
16
star
25

harvester

Harvesterd is a low footprint collector and parser for events and logs
Go
12
star
26

fabric-composer

Deploy system for PHP composer based projects made with Fabric
Python
11
star
27

silex-hateoas

A RESTful example based on Hateoas and Silex
PHP
8
star
28

lemondb

Extensible MongoDB proxy
Go
8
star
29

go-git-aerospike

Example of go-git backed by a Aerospike
Go
7
star
30

go-raa

fast random access filesystem archive
Go
5
star
31

pimple-hack

A Pimple version in Hack/HHVM, just for fun!
PHP
4
star
32

python-solid-example

Simple example implementing SOLID principles with Python
Python
4
star
33

go-etcd-hydrator

Go
4
star
34

bson-hni

C++
3
star
35

pgwire

Go
3
star
36

ansi-slides

Slide with ANSI style!
PHP
3
star
37

go-time-aggregator

Go
3
star
38

bson-php-cpp

Libbson + PHP-CPP
C++
2
star
39

go-personal

A tiny library to score strings as fullnames or emails.
Go
2
star
40

go-mgo-cache

MongoDB interface for a Go cache
Go
2
star
41

dotfiles

Coming back to Linux! My new config files.
C
2
star
42

golang-arm

Docker Image packaging for golang for ARM platforms.
Shell
2
star
43

dockership-site

Dockership documentation
HTML
1
star
44

natstress

A stress tool for NATS Servers
Go
1
star
45

yCrawler

PHP
1
star
46

cli-array-editor

This class provides an easy way to edit arrays in CLI using vim or your preferred editor.
PHP
1
star
47

statsd-ducksboard-backend

A StatsD backend that sends metrics to Ducksboard
JavaScript
1
star
48

docker-arm

Dockerfiles for ARM
Shell
1
star
49

presentations

Repository of presentations
1
star
50

go-bson-schema

Go
1
star