1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
Cron
=============================
<!--
This file is written in Markdown syntax.
For more information about how to use the Markdown syntax, read here:
http://daringfireball.net/projects/markdown/syntax
-->
<!-- {{TOC}} -->
Introduction
------------
The cron module allows you to do tasks regularly, by setting up a cron
job that calls a hook in SimpleSAMLphp. This will invoke
`hooks/hook_cron.php` in any enabled modules
Preparations
------------
You need to enable the module and copy the `config-templates` files of the module into the global `config/` directory.
[root@simplesamlphp] cd /var/simplesamlphp
[root@simplesamlphp simplesamlphp] touch modules/cron/enable
[root@simplesamlphp simplesamlphp] cp modules/cron/config-templates/*.php config/
Configuring the cron module
---------------------------
The configuration (`config/module_cron.php`) should look similar to this:
$config = array (
'key' => 'RANDOM_KEY',
'allowed_tags' => array('daily', 'hourly', 'frequent'),
'debug_message' => TRUE,
'sendemail' => TRUE,
);
Bear in mind that the key is used as a security feature, to restrict
access to your cron. Therefore, you need to make sure that the string
here is a random key available to no one but you. Additionally, make
sure that you include here the appropriate tags - for example any tags
that you previously told metarefresh to use in the `cron` directive.
Triggering Cron
---------------------------
You can trigger the cron hooks through HTTP or CLI. The HTTP method
is the original technique, and it is recommended if you don't need to
trigger CPU or memory intensive cron hooks. The CLI option is
recommended if you need more control over memory, CPU limits and
process priority.
### With HTTP
`cron` functionality can be invoked by making an HTTP request to the
cron module. Use your web browser to go to
`https://YOUR_SERVER/simplesaml/module.php/cron/croninfo.php`. Make
sure to properly set your server's address, as well as use HTTP or
HTTPS accordingly, and also to specify the correct path to the root of
your SimpleSAMLphp installation.
Now, copy the cron configuration suggested on that page:
# Run cron [daily]
02 0 * * * curl --silent "https://YOUR_SERVER/simplesaml/module.php/cron/cron.php?key=RANDOM_KEY&tag=daily" > /dev/null 2>&1
# Run cron [hourly]
01 * * * * curl --silent "https://YOUR_SERVER/simplesaml/module.php/cron/cron.php?key=RANDOM_KEY&tag=hourly" > /dev/null 2>&1
Finally, add it to your crontab by going back to the terminal, and editing with:
[root@simplesamlphp config]# crontab -e
This will open up your favourite editor. If an editor different than
the one you use normally appears, exit, and configure the `EDITOR`
variable to tell the command line which editor it should use:
[root@simplesamlphp config]# export EDITOR=emacs
If you want to trigger a job manually, you can do
so by going back to the cron page in the web interface. Then, just
follow the appropriate links to execute the cron jobs you want. The
page will take a while loading, and eventually show a blank page.
### With CLI
You can invoke cron functionality by running
`/var/simplesamlphp/modules/cron/bin/cron.php` and providing a tag
with the `-t ` argument.
It is strongly recommended that you run the cron cli script as the
same user as the web server. Several cron hooks created files and
those files may have the wrong permissions if you run the job as root.
**note:** Logging behavior in SSP when running from CLI varies by
version. The latest version logs to PHP's error log and ignores any
logging configuration from `config.php`
Below is an example of invoking the script. It will:
* Run a command as the `apache` user
* `-s` specifies `apache` user's shell, since the default is non-interactive
* Override INI entries to increase memory and execution time.
* This allows for processing large metadata files in metarefresh
* Run the `cron.php` script with the `hourly` tag
* Use `nice` to lower the priority below that of web server processes
```
su -s "/bin/sh" \
-c "nice -n 10 \
php -d max_execution_time=120 -d memory_limit=600M \
/var/simplesamlphp/modules/cron/bin/cron.php -t hourly" \
apache
```
|