Ecentria Crontab Bundle
Crontab Functionality of scheduling cron jobs.
The software utility cron is a time-based job scheduler in Unix-like computer operating systems.
People who set up and maintain software environments use cron to schedule jobs to run periodically
at fixed times, dates, or intervals.
This bundle provides a simple possibility to control crontab on application level.
Provides a possibility to auto-setup cron jobs required for project based on configuration file., (*1)
, (*2)
Table of Contents
- Installation
- Configuration
- Usage
- License
- Important Notice
, (*3)
, (*4)
Installation
console, (*5)
$ composer require ecentria/crontab-bundle
php, (*6)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Ecentria\Bundle\CrontabBundle\EcentriaCrontabBundle()
);
// ...
}
}
, (*7)
, (*8)
Configuration
Bundle supports defining configuration by using regular expressions.
Sequence of consumers collecting:
- Exact match will go first, if match is found collecting is finished.
- Searching for first match by regular expression, (*9)
config/packages/ecentria_crontab.yml, (*10)
ecentria_crontab:
path: 'home/sites/shared/crontab'
user: 'project_specific_user'
mailto: 'your.email@address.com'
jobs:
backend.example.com: # It must contain valid hostname, see Services/StaticJobProvider::provide()
-
description: 'Backend'
frequency: '* * * * *'
command: 'php /home/sites/current/bin/console backend'
parameters: '--env=prod --no-debug'
node-\d+.example.com:
-
description: 'Node job 1'
frequency: '* * * * *'
command: 'php /home/sites/current/bin/console node'
parameters: '--execute=foo --env=prod --no-debug'
-
description: 'Node job 2'
frequency: '* * * * *'
command: 'php /home/sites/current/bin/console node'
parameters: '--execute=bar --env=prod --no-debug'
, (*11)
, (*12)
Usage
Setup your crontab after deployment, (*13)
php bin/console ecentria:crontab:install --env=prod --no-debug
After command finished it's job you can check crontab with:, (*14)
crontab -l
And if everything is correct you should see, (*15)
node-1.example.com, (*16)
# This file has been generated dynamically
# All manual changes will be erased soon
MAILTO="your.email@address.com"
# Node job 1
* * * * * php /home/sites/current/bin/console node --execute=foo --env=prod --no-debug
# Node job 2
* * * * * php /home/sites/current/bin/console node --execute=bar --env=prod --no-debug
, (*17)
, (*18)
License
The MIT License
Copyright (c) 1999-2018 Ecentria Group http://www.ecentria.com
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.
, (*19)
Important Notice
Ecentria Crontab Bundle schedules jobs using Crontab.
A best practice for two or more applications that run on the same node is to assign a different user per application., (*20)
The best practice mentioned above prevents different applications overwriting each other's configurations.
One user has only one cron table file, normally stored on /var/spool/cron/, (*21)