5.3-Nano: Portable Cron

From The Uniform Server Wiki
Revision as of 16:36, 9 October 2009 by Ric (talk | contribs) (New page: {{Nav 5.3-Nano}} Portable Cron was integrated into Uniform Server 5-Nano although useful suffered from a number of limitations. A new design has addressed these issues and offers more flex...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 

Portable Cron was integrated into Uniform Server 5-Nano although useful suffered from a number of limitations. A new design has addressed these issues and offers more flexibility.

Background

Before looking at configuration the following provides a quick overview what portable Cron is and what it is not.

Cron

Cron originated from a Unix environment it is a job scheduler allowing scripts to be run automatically at a certain time or date.

Cron (chronograph) has become a more general term referring to a periodic tick.

Top

Portable Cron

Why portable Cron? A permanent installation of UniServer running as a service you can set-up Windows to schedule a task similar to Unix Cron check out How To Schedule Tasks in Windows XP for details?

This is not practical when running UniServer from a USB memory stick which implies portability you need to reconfigure each new machine. UniServer 5.0-Nano resolves this with a small script scheduler referred to as portable Cron.

It’s fully integrated into UniServers’s control architecture allowing it to be run from either batch files or UniTray.

If you are interested there are design notes, which can be found here.

Top

Configuration

To run each individual script a number of parameters are set in a configuration file cron.ini This file has a standard format making it very easy to use and set up

Each script to be run is defined in a self-contained block. Each block starts with a unique header see following example:

[moodle] 
start  = 2009-09-21 2:56:00
period = hourly
path   = http://localhost/moodle/admin/cron.php
ref =

Top

Explanation

[moodle] - Header a unique name enclosed in square brackets.
start - Time you initially want the script to start (seconds are ignored)
period - How often the script is to be run after the initial start
path - Full path and name of the script to be run
ref - A tracker set by Cron script effectively time to next run. Deleting this value allows a new start time to be set (covered later)

Top

Detail

[moodle]

 

Header uniquely names this block note no spaces allowed in name.

start

Initial start time when script is to be run it has the following format:
Y-M-D H:M:S - Note: A 24 hour clock is used, seconds are ignored hence set to 00

period

=

How often to run script from the above reference start time
Valid values are: hourly, daily, weekly, monthly
Fine control is offered by using a numeric specified in seconds

path

=

Two types of scripts are runnable with paths as follows:

  • For a web application full URL of the script e.g. http://localhost/drupal/cron.php
  • Local CLI scripts relative path and name e.g. ..\..\plugins\cron_test\dtdns_updater.php

ref

=

A time stamp updated by the Cron script. Initial value is set by a user value blank.

Note 1: Cron automatically updates ref with the initial start time set and
period. Every time a script is run the value is updated with a new Cron reference
this defines when the next run is to start.

Note 2: To specify a new start time first set a new value for start and
delete the ref number (if there is one), save the file. The script will run at the
date and time set and thereafter at a period you defined

Top

Configuration file (cron.ini)

Each script that requires running is added to the cron configuration file cron.ini located in folder UniServer\unicon\main

Configuration file includes four examples two for server scripts (Drupal and Moodle) and two for inbuilt CLI script (DtDNS updater and db_backup).

Top

Server Script Example

 [drupal]
 start  = 2009-09-21 2:56:52
 period = hourly
 path   = http://localhost/drupal/cron.php
 ref = 

Note 1:

If you have installed the application to different folder use the appropriate folder names.

Note 2:

If you have moved the servers remember to add a port number to the url.

For example moving the servers once, Apache port becomes 81 and the above line need to change as follows:


path = http://localhost:81/drupal/cron.php

Top

CLI Script Example

 [dtdns]
 start  = 2009-09-21 2:56:52
 period = 600                 ; 10 Mins as required by DtDNS
 path   = ..\..\plugins\dtdns_updater\dtdns_updater.php
 ref = 

Note 1:

For portability always use relative paths as shown (..\..\)

Path is relative to cron.ini (Note ..\ moves up one folder level)

Top

How to run portable Cron

Manually

Portable Cron is run from one of two locations.

UniTray:

  • Left or Right mouse click tray icon
  • To run Cron: Advanced > Start Portable Cron
  • To stop Cron: Advanced > Stop Portable Cron

Alternative Control:

  • Navigate to folder UniServer\alternative_control
  • To run Cron: Double click on Start_Cron.bat
  • To stop Cron: Double click on Stop_Cron.bat

Top

Automatic

Cron can be configured to run automatically when the servers are started.

Edit file UniServer\unicon\tray_menu\UniTray1.ini

These four lines (lines three and four split on purpose to prevent breaking the Wiki) control Server Start and Stop.

Change binary code from 7 to 23 for lines three and four.

;=== LEFT MENU ============
[Menu.Left]

Type: item; Caption: "Start UniServer (Apache MySQL)"; Action: shellexecute; FileName:
 "%PHP%\php.exe"; Parameters: " -n %ServerConMain%\start_servers.php 7";ShowCmd: hidden; Glyph: 9

Type: item; Caption: "Stop  UniServer (Apache MySQL)"; Action: shellexecute; FileName:
 "%PHP%\php.exe"; Parameters: " -n %ServerConMain%\stop_servers.php 7";ShowCmd: hidden; Glyph: 11

Top

Logging

Cron logs the fooling information:

  • Time Cron was started
  • Start time and path of a script that is run
  • Time Cron was stopped. Note if missing from log means servers were not shut down before tuning PC off

Cron logging is enabled by default this can be disabled by editing the following file:

UniServer\unicon\main\run_cron.php

  • Change line: $logging = true;
  • To: $logging = false;

Note: Name and location of log file is : UniServer\unicon\main\cron_log.txt

Top

Summary

The above has shown how easy Cron is to use and configure.

If you enable either or both inbuilt CLI scripts (DtDNS updater, db_backup) remember to configure their configuration files.

Configure DtDNS updater and or Configure db_backup

Top