GithubHelp home page GithubHelp logo

homer6 / frequent-cron Goto Github PK

View Code? Open in Web Editor NEW
47.0 5.0 8.0 39 KB

A linux daemon that you can call scripts more frequently than once per minute. This is extremely stable and runs in production for a number of systems.

C++ 100.00%

frequent-cron's Introduction

Overview

frequent-cron is a linux daemon under the MIT License. It is designed to run crons by millisecond in linux. Calls to the script or commands block, meaning that if you have a 500ms frequent-cron and your script runs for 3 minutes, your script will run once every 3 minutes.

Dependencies

  • Boost 1.37 (apt-get install libboost-all-dev)
  • cmake 2.8.2 (apt-get install cmake)

Installation

Starting the Service (Simple)

  • ./frequent-cron --frequency=1000 --command="/usr/local/bin/php /home/ssperandeo/dev/homer6/frequent-cron/test.php"

Stopping the Service (Simple)

  • ps aux | grep frequent
  • kill 3423

Starting the Service (Using init.d)

  • sudo cp init_script.tpl /etc/init.d/frequent_service
  • edit "command", "frequency" and "pid-file" (make sure both the "command" and the "pid-file" are absolute paths)
  • sudo chmod ugo+x /etc/init.d/frequent_service
  • sudo update-rc.d frequent_service defaults (optional; will automatically restart this service on system restart)
  • sudo /etc/init.d/frequent_service start

Stopping the Service (Using init.d)

  • sudo /etc/init.d/frequent_service stop

frequent-cron's People

Contributors

e2 avatar homer6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

frequent-cron's Issues

Question: run as cron at minutes interval

Dear Homer6,
Do you know how can i run your daemon as scheduling job?
Example:
Run every 5 minutes: at 0,5,15,20,....55 minutes
Run every 2 minutes: at 0,2,4....58

After Ubuntu 18.04 upgrade, libboost cannot be found and frequent cron must be rebuilt

This is not a bug report per say, but something which might help others.

After upgrading from 16.04 LTS to 18.04 LTS today I had to rebuild frequent-cron as I got this message when attempting to start the daemon:

/root/frequent-cron/frequent-cron: error while loading shared libraries: libboost_system.so.1.58.0: cannot open shared object file: No such file or directory

I basically just had to re-run the make process:

cd /root/frequent-cron; cmake .; make;

And frequent-cron is happy again ๐Ÿ‘

Update service file for systemd

I have to say I love frequent-cron: I have it running scripts that I needed running more frequently than cron and this has yet to let me down, and I've been using it for about 4 years. However, I've recently upgraded a system from Ubuntu 14 to 16 and I read that systemd is the preferred way of doing things, rather than init.d.

So I've gone through the included template file and attempted to get this running with systemd and - well, nothing seems to be spawning.

Here's my /var/www/app/services/testService.service unit file:

Description=A test service running frequent-cron under systemd
After=syslog.service
[Service]
ExecStart=/usr/local/bin/frequent-cron --frequency=3000 --command="/var/www/app/services/testService.php"
PIDFile=/var/run/testService.pid
[Install]
WantedBy=multi-user.target

Here's my simple testService.php (which basically just posts the time to a defined log file):

#!/usr/bin/php
<?php
require_once 'config/define.php';
require_once 'fn/fnDebug.php';
debugPrint('The time is now ' . date('H:i:s') . ' on ' . date('l, jS \of F Y'));
?>

Invocation:

  1. systemctl daemon-reload
  2. systemctl enable /var/www/app/services/testService.service

When I run systemctl status testService, I'm told that the script ran and exited - just once, with no output to my log file.

When I run via command line, also nothing happens:

/usr/local/bin/frequent-cron --frequency=1000 --command="/var/www/app/services/testService.php"

When I run the PHP file itself, it prints the time (just once, as expected).

On the same server, I have about 4 other frequent-cron services running just fine, using the template supplied and the instructions to invoke using init.d and update-rc.d and believe me, it works just fine. I'm just trying to get this working in systemd so that, should Ubuntu remove support for init.d scripts, I've covered my bases already.

Any way to run frequent-cron non-blocking?

I have always seen the default behavior of frequent-cron as a strength as it has been what I needed in past projects.

However, I have a scenario now where I basically want a script to be run every 500ms regardless of whether there is a copy of the script running already.

Is there a way to tell frequent cron to be non-blocking and just run the requested command ever Xms regardless?

Maybe some other daemon you know of which does this, in case this is not do-able with frequent-cron?

Thanks! :)

Feature request: option to limit number of running command processes

It would be useful to have an option to limit how many processes of "command" can run simultaneously.

For example, if I run a command every second, but it takes 3 seconds for that process to complete and I specify that I only want one process for it ever running, then with a limit of 1:

0s: command runs
1s: skips (1 still running)
2s: skips (1 still running)
3s: command runs

This is particularly useful for queues. It seems to me that frequent-cron could more reliably limit the number of running processes to prevent a queued item from being processed twice.

nothing happens when I run this...?

Hi,
I've compiled frequent-cron and it seems to be running (it shows up in ps -A happily), but, it doesn't seem to do anything.

I've got a simple script that just has
/usr/bin/echo data >> /home/usr/out.txt
in it.. and I try and start frequent-cron with
./frequent-cron --frequency=100 --command="/usr/bin/bash /home/usr/echoout.sh"

but absolutely nothing happens.

What am I missing?

Does not build on Ubuntu Focal Fossa

Howdy

Love Frequent Cron. Anyway, it no longer builds on the latest Ubuntu:

# cd /root/frequent-cron; cmake .; make;
CMake Warning (dev) at src/CMakeLists.txt:3 (add_executable):
  Policy CMP0037 is not set: Target names should not be reserved and should
  match a validity pattern.  Run "cmake --help-policy CMP0037" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  The target name "../frequent-cron" is reserved or not valid for certain
  CMake features, such as generator expressions, and may result in undefined
  behavior.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- GCC detected, adding compile flags
-- Configuring done
-- Generating done
-- Build files have been written to: /root/frequent-cron
[ 50%] Linking CXX executable ../frequent-cron
/usr/bin/ld: CMakeFiles/../frequent-cron.dir/frequent.cc.o: undefined reference to symbol 'pthread_condattr_setclock@@GLIBC_2.3.3'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/../frequent-cron.dir/build.make:86: src/../frequent-cron] Error 1
make[1]: *** [CMakeFiles/Makefile2:94: src/CMakeFiles/../frequent-cron.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Googling reveals this seems to be Boost related. apt reports:

# apt-get install libboost-all-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libboost-all-dev is already the newest version (1.71.0.0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.

Thanks :)

undaemon for docker

Thanks for this much needed project.
I want to run this in a docker container: perhaps it would be useful to have an "undaemonized" mode. For example, with cron, you can run it with the -f flag to have it run in the front (undaemonized) for long-running containers.

Unable to find the requested Boost libraries.

I am trying to install this and everything went well until the part where I run "cmake ."
This is what I'm getting. Tried everything and always the same.
Does anyone know what the issue is ?

vagrant@homestead:~/frequent-cron$ cmake .
-- The CXX compiler identification is GNU
-- The C compiler identification is GNU
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
CMake Error at /opt/cmake/share/cmake-2.8/Modules/FindBoost.cmake:1123 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.58.0

  Boost include path: /usr/include

  The following Boost libraries could not be found:

          boost_system
          boost_program_options

  No Boost libraries were found.  You may need to set Boost_LIBRARYDIR to the
  directory containing Boost libraries or BOOST_ROOT to the location of
  Boost.
Call Stack (most recent call first):
  src/CMakeLists.txt:6 (find_package)


-- GCC detected, adding compile flags
-- Configuring incomplete, errors occurred!

Feature request: Run as service with config file

It would be really handy to have frequent-cron run as a service and automatically set up its tasks from a file should the system be rebooted.

The tasks file could live somewhere in /etc and contain a list of commands & frequencies to start automatically.

service frequent-cron start would start the tasks
service frequent-cron stop would kill the processes

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.