Cron with interval 1 second, yaml based configs http://gogocron.blindage.org/
go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Vladimir Smagin c3f3e72f52 added gracefulstop period 7 kuukautta sitten
config added configuration file with adjustable precision and tasks location 7 kuukautta sitten
configs added gracefulstop period 7 kuukautta sitten
debian added gracefulstop period 7 kuukautta sitten
website readme and redirect page for landing 8 kuukautta sitten
.gitignore build debian package 8 kuukautta sitten
build.sh added gracefulstop period 7 kuukautta sitten
config.go added gracefulstop period 7 kuukautta sitten
file_utils.go added gracefulstop period 7 kuukautta sitten
gogocron.go added gracefulstop period 7 kuukautta sitten
readme.md added gracefulstop period 7 kuukautta sitten
timing.go added configuration file with adjustable precision and tasks location 7 kuukautta sitten

readme.md

gogocron - one second crontab daemon

Cron daemon with crontab syntax, small interval and execution timeout for each task. Report bugs here 21h@blindage.org.

Features

  • customizing tasks files location
  • traditional crontab syntax for defining run intervals
  • 1 second minimal interval
  • your own ENV variables for whole task
  • adjustable run precision from 10 ms to 500 ms
  • batch of commands to run in one task
  • run task commands as other user
  • timeout for whole task with default graceful period 10s
  • SIGHUP process to reload config files
  • adjustable graceful timeout period for each command in task

Installation

Requires:

  • root user privileges to run su command
  • available su command in $PATH

Ubuntu\Debian repository

Check before that curl and tee installed.

curl http://deb.blindage.org/gpg-key.asc | sudo apt-key add -
echo "deb http://deb.blindage.org bionic main" | sudo tee /etc/apt/sources.list.d/21h.list
sudo apt install gogocron

Manual deb package installation

You can find binary code in Releases tab or build code yourself.

Installation example (change download url to last release):

$ wget --content-disposition "https://git.blindage.org/attachments/deaaa74f-efbe-4254-bf10-18e108b81065"
$ dpkg -i gogocron-1.1.deb
$ systemctl enable gogocron
$ systemctl start gogocron

Build code yourself

Install Golang, then build:

go get github.com/kr/pty
go get gopkg.in/yaml.v2
./build.sh

Configuration

Global configuration options

All global options loads once at daemon start and HUP signal have no effect on them, use restart command: systemctl restart gogocron.

Precision

Run precision means how frequently gogocron checks that second was incremented. What this means to you? Answer is how fast task will run after new second begin + some delta time for filtering tasks to run. Default value is 100 ms, but if you lower this value the checking circle get more CPU resources because checks to be more frequent.

Edit /etc/gogocron/gogocron.yml:

ticktack_precision: 100ms

Tasks location

Set location where tasks files stored.

Edit /etc/gogocron/gogocron.yml:

tasks_location: /etc/gogocron/configs

Tasks configuration options

gogocron reloads all tasks configurations after receiving HUP signal, use reload or restart command to apply new task configuration: systemctl reload gogocron.

Interval

Set interval how often run task (whole batch of commands in task). Use traditional crontab syntax.

runsecond // second
runminute // minute
runhour   // hour
rundom    // day of month
runmonth  // month
rundow    // day of week

Timeout

If whole task (not one command in task) running more than timeout cron send SIGTERM signal, by default timeout is turned off.

timeout: 3h12m4s

It’s a golang’s time.Duration definition, string:

  • 1s - one second
  • 1m10s - one minute and 10 seconds

Graceful stop

By default if task’s command not die after SIGTERM in 10s cron send SIGKILL signal. You may need this if your program receiving signals but internal queue not empty for immidiately stop.

You can change this time with:

gracefulstop: 30s

It’s a golang’s time.Duration definition, string:

  • 1s - one second
  • 1m10s - one minute and 10 seconds

ENV

Array of environment variables (strings). Defines additional to gogocron’s env variables for each command in commands array.

Syntax:

env:
  - TESTVAR="test variable"

Commands

Array of commands (strings). Commands in one task running line by line with environment variables defined in ENV.

Syntax:

commands: 
  - whoami
  - sleep 3
  - head -c 20 /dev/urandom |base64
  - ls
  - echo $TESTVAR

Logging of task

logtype can accept:

  • info (default, logging only fact of run)
  • full (log fact of run and stdout/stderr, useful for debugging)
  • disabled (completely disable logs)

Sample task configuration file

You never see variable value because timeout kill this task earlier.

---
name: "Print base64 of 20 random symbols"
runsecond: "*/5"
logtype: info
timeout: 10s
user: vlad
env:
  - TESTVAR="text you never see"
commands: 
  - whoami
  - sleep 3
  - head -c 20 /dev/urandom |base64
  - ls
  - sleep 10
  - echo $TESTVAR