Code Monkey home page Code Monkey logo

rpi-cron's Introduction

rpi-cron

Images for running cron jobs inside Docker on your RaspberryPi. These come in two flavors: raspbian (Raspbian based) and alpine (Alpine Linux based).

docker pull b00gizm/rpi-cron:raspbian
docker pull b00gizm/rpi-cron:alpine

(Pulling b00gizm/rpi-cron without a tag defaults to b00gizm/rpi-cron:raspbian.)

Usage

rpi-cron:raspbian

For simply running some cron jobs, just call:

docker run -it --rm -v /path/to/jobs:/crons b00gizm/rpi-cron

Or create your own image with b00gizm/rpi-cron:raspbian as your base:

FROM b00gizm/rpi-cron:raspbian

COPY jobs /etc/cron.d

You might ask, why not just use /etc/cron.d as a volume? Well, you'll run into some weird issues with that. So I used /crons, which is just a directory from where cron scripts will be copied to /etc/cron.d, as a kind of work around.

ENV Variables

Since cron always runs with a mostly empty environment, all environment variables will be stored inside /env.sh during docker run. You can then easily source them inside your shell scripts, if you need them:

docker run -it --rm \
    -e MYVAR=foo \
    -v /path/to/jobs:/crons \
  b00gizm/rpi-cron:raspbian

Cron script

* * * * * root /my_script >> /var/log/cron.log 2>&1

The actual shell script to run

#!/bin/bash

source /env.sh

echo $MYVAR; # prints 'foo'

rpi-cron:alpine

Running jobs periodically inside the alpine flavored rpi-cron is much simpler, but also less flexible. You can choose between running jobs every 15 minutes, hourly, daily, weekly, or monthly by putting them into their appropriate directories inside the container /etc/periodic/{15min,hourly,daily,weekly,monthly}

docker run -it --rm -v /path/to/jobs:/etc/periodic b00gizm/rpi-cron

Or create your own image with b00gizm/rpi-cron:alpine as your base:

FROM b00gizm/rpi-cron:alpine

COPY jobs /etc/periodic

ENV Variables

Since cron always runs with a mostly empty environment, all environment variables will be stored inside /env.sh during docker run. You can then easily source them inside your jobs, if you need them:

docker run -it --rm \
    -e MYVAR=foo \
    -v /path/to/jobs:/etc/periodic \
  b00gizm/rpi-cron:alpine

The actual job to run

#!/bin/bash

source /env.sh

echo $MYVAR; # prints 'foo'

Maintainer

Pascal Cremer

License

The MIT License (MIT)

Copyright (c) 2016 Pascal Cremer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rpi-cron's People

Contributors

b00gizm avatar

Watchers

 avatar  avatar

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.