GithubHelp home page GithubHelp logo

isabella232 / infra-role-systemd-timer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from status-im/infra-role-systemd-timer

0.0 0.0 0.0 45 KB

Ansible role for configuring a Systemd timer and service

License: MIT License

Shell 52.47% Jinja 47.53%

infra-role-systemd-timer's Introduction

Description

This role configures a systemd timer along with a oneshot service for running a provided script.

Configuration

systemd_timer_name: my-test
systemd_timer_description: 'Just a timer creation test.'
systemd_timer_user: 'root'
systemd_timer_frequency: 'hourly'
systemd_timer_timeout_sec: 120
systemd_timer_nice_priority: 10
systemd_timer_requires_extra: 'network.target'
systemd_timer_after_extra: 'network.target'
systemd_timer_work_dir: '/tmp/somedir'
systemd_timer_environment:
  MY_ENV_VAR: 'some_value'
systemd_timer_script_content: |
  #!/usr/bin/env bash
  echo "My Timer Script!"

The frequency accepts systemd time specification format.

You can also customize the Consul service definition:

systemd_timer_consul_service_id: 'my-test-abc'
systemd_timer_consul_service_name: 'my-test'
systemd_timer_consul_extra_tags: ['test', 'abc']
systemd_timer_consul_meta: { my_meta: 'metadata' }

The service runs the check.sh script to verify timer health..

Usage

The the timer starts the service with configured frequency. Assuming our backup target is called database you can do:

 $ sudo systemctl status my-test.service
โ— my-test.service - Just a timer creation test.
   Loaded: loaded (/lib/systemd/system/my-test.service; static; vendor preset: enabled)
   Active: inactive (dead) since Mon 2020-02-17 13:14:53 UTC; 6s ago
     Docs: https://github.com/status-im/infra-role-systemd-timer
  Process: 26001 ExecStart=/usr/local/bin/my-test (code=exited, status=0/SUCCESS)
 Main PID: 26001 (code=exited, status=0/SUCCESS)

Feb 17 13:14:53 host.example.org systemd[1]: Starting Just a timer creation test....
Feb 17 13:14:53 host.example.org systemd[1]: Started Just a timer creation test..
Feb 17 13:14:53 host.example.org my-test[26001]: My Timer Script!

You can check the timer status too:

 $ sudo systemctl list-timers my-test.timer     
NEXT                         LEFT       LAST PASSED UNIT          ACTIVATES
Mon 2020-02-17 14:00:00 UTC  44min left n/a  n/a    my-test.timer my-test.service

infra-role-systemd-timer's People

Contributors

jakubgs 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.