Cron Design: Running Cron: Difference between revisions
Jump to navigation
Jump to search
m
Reverted edits by Upazixorys (Talk); changed back to last version by Ric
Upazixorys (talk | contribs) No edit summary |
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric) |
||
Line 1: | Line 1: | ||
{{Nav Cron Design}} | {{Nav Cron Design}} | ||
Both Cron start and stop requests are passed to a central control block for processing. This control block consists of two scripts '''start_servers.php''' and '''stop_servers.php''' these are located in folder UniServer\unicon\main. Further processing if required is handed on to the appropriate script or scripts. | Both Cron start and stop requests are passed to a central control block for processing. This control block consists of two scripts '''start_servers.php''' and '''stop_servers.php''' these are located in folder UniServer\unicon\main. Further processing if required is handed on to the appropriate script or scripts. | ||
Line 12: | Line 11: | ||
|- | |- | ||
| | | | ||
<pre> | |||
CODE Options are binary coded as follows: | CODE Options are binary coded as follows: | ||
Line 22: | Line 21: | ||
Cron 16 1 - Run cron 0 - ignore | Cron 16 1 - Run cron 0 - ignore | ||
</pre> | |||
| | | | ||
Binary bit coding does not conform to the classic definition where 1 means on and 0 means off. Uniform Server uses 1 to mean perform the function while 0 means ignore and do nothing. | Binary bit coding does not conform to the classic definition where 1 means on and 0 means off. Uniform Server uses 1 to mean perform the function while 0 means ignore and do nothing. | ||
Line 60: | Line 59: | ||
'''Start_Cron.bat''' contains the following line: | '''Start_Cron.bat''' contains the following line: | ||
<pre> | |||
..\usr\local\php\php.exe -n ..\unicon\main\start_servers.php 16 | ..\usr\local\php\php.exe -n ..\unicon\main\start_servers.php 16 | ||
</pre> | |||
* '''..\usr\local\php\php.exe -n''' Runs the PHP interpreter ('''php.exe''') with no ('''-n''') configuration file and runs the following file: | * '''..\usr\local\php\php.exe -n''' Runs the PHP interpreter ('''php.exe''') with no ('''-n''') configuration file and runs the following file: | ||
* '''..\unicon\main\start_servers.php 16''' Script start_servers.php is run with parameter 16 (Runs only Cron) | * '''..\unicon\main\start_servers.php 16''' Script start_servers.php is run with parameter 16 (Runs only Cron) | ||
Line 68: | Line 67: | ||
'''Stop_Cron.bat''' contains the following line: | '''Stop_Cron.bat''' contains the following line: | ||
<pre> | |||
..\usr\local\php\php.exe -n ..\unicon\main\stop_servers.php 16 | ..\usr\local\php\php.exe -n ..\unicon\main\stop_servers.php 16 | ||
</pre> | |||
* '''..\usr\local\php\php.exe -n''' Runs the PHP interpreter ('''php.exe''') with no ('''-n''') configuration file and runs the following file: | * '''..\usr\local\php\php.exe -n''' Runs the PHP interpreter ('''php.exe''') with no ('''-n''') configuration file and runs the following file: | ||
* '''..\unicon\main\stop_servers.php 16''' Script stop_servers.php is run with parameter 16 (Stops only Cron) | * '''..\unicon\main\stop_servers.php 16''' Script stop_servers.php is run with parameter 16 (Stops only Cron) | ||
Line 77: | Line 76: | ||
==== UniTray ==== | ==== UniTray ==== | ||
* Left or Right mouse click tray icon | * Left or Right mouse click tray icon | ||
* To run Cron: Advanced | * To run Cron: Advanced > Start Portable Cron | ||
* To stop Cron: Advanced | * To stop Cron: Advanced > Stop Portable Cron | ||
Have a peek inside Unitrays configuration file: UniServer\unicon\tray_menu\'''UniTray1.ini''' | Have a peek inside Unitrays configuration file: UniServer\unicon\tray_menu\'''UniTray1.ini''' | ||
These two lines (split on purpose to prevent breaking the Wiki) control Cron start and stop. Only thing worth of note is they use binary code '''16''' | These two lines (split on purpose to prevent breaking the Wiki) control Cron start and stop. Only thing worth of note is they use binary code '''16''' | ||
<pre> | |||
Type: item; Caption: | Type: item; Caption: "Start Portable Cron"; Action: shellexecute; FileName: | ||
"%PHP%\php-win.exe"; Parameters: " -n %ServerConMain%\start_servers.php 16"; Glyph: 9 | |||
Type: item; Caption: | Type: item; Caption: "Stop Portable Cron"; Action: shellexecute; FileName: | ||
"%PHP%\php-win.exe"; Parameters: " -n %ServerConMain%\stop_servers.php 16"; Glyph: 11 | |||
</pre> | |||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
Line 101: | Line 100: | ||
Change binary code from 7 to 23 for lines three and four. | Change binary code from 7 to 23 for lines three and four. | ||
<pre> | |||
;=== LEFT MENU ============ | ;=== LEFT MENU ============ | ||
[Menu.Left] | [Menu.Left] | ||
Type: item; Caption: | 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: | Type: item; Caption: "Stop UniServer (Apache MySQL)"; Action: shellexecute; FileName: | ||
"%PHP%\php.exe"; Parameters: " -n %ServerConMain%\stop_servers.php 7";ShowCmd: hidden; Glyph: 11 | |||
</pre> | |||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
Line 123: | Line 122: | ||
=== start_servers.php - Cron Section === | === start_servers.php - Cron Section === | ||
{| | {| | ||
|-valign= | |-valign="top" | ||
| | | | ||
* $server_operation contains either the parameter passed or default this is compared with binary 16 using the “binary & | * $server_operation contains either the parameter passed or default this is compared with binary 16 using the “binary & bit operator” On a match runs the block of code. | ||
* If Apache not running give up | * If Apache not running give up | ||
* If Cron already running again give up | * If Cron already running again give up | ||
Line 135: | Line 134: | ||
'''''Note 1'':''' For testing the command can be switch making the process visible. | '''''Note 1'':''' For testing the command can be switch making the process visible. | ||
'''''Note 2'':''' If a user turns PC off without closing the servers next time servers are run a clean up operation is performed. Hence this code is run '''set_cron_tracker( | '''''Note 2'':''' If a user turns PC off without closing the servers next time servers are run a clean up operation is performed. Hence this code is run '''set_cron_tracker("stop")''' see RUN APACHE SERVER section | ||
| | | | ||
& | | ||
| | | | ||
'''''start_servers.php''''' | '''''start_servers.php''''' | ||
<pre> | |||
// === RUN CRON ============================================================ | // === RUN CRON ============================================================ | ||
if ((int)$server_operation & | if ((int)$server_operation & 16 ){ // Cron enabled by config or parameter | ||
if(apache_running()){ // Only run cron if Apache running | if(apache_running()){ // Only run cron if Apache running | ||
// otherwise ignore and exit quietly | // otherwise ignore and exit quietly | ||
if(get_cron_tracker() == | if(get_cron_tracker() == "run"){ // Cron already running | ||
print | print " Cron already running\n"; // Already running, give up | ||
} | } | ||
else{ // not running | else{ // not running | ||
set_cron_tracker( | set_cron_tracker("run"); // set tracker to run | ||
print | print " Cron started \n"; // inform user | ||
// Test switch between the two: visibe | // Test switch between the two: visibe | ||
Line 158: | Line 157: | ||
// Test switch between the two: hidden | // Test switch between the two: hidden | ||
$cmd = 'start uniserv.exe | $cmd = 'start uniserv.exe "..\..\usr\local\php\php.exe run_cron.php"'; | ||
pclose(popen($cmd,'r')); // Start detatched process | pclose(popen($cmd,'r')); // Start detatched process | ||
Line 165: | Line 164: | ||
}//End Apache running | }//End Apache running | ||
}// End run cron | }// End run cron | ||
</pre> | |||
|} | |} | ||
Line 172: | Line 171: | ||
=== stop_servers.php - Cron Section === | === stop_servers.php - Cron Section === | ||
{| | {| | ||
|-valign= | |-valign="top" | ||
| | | | ||
* $server_operation contains either the parameter passed or default this is compared with binary 16 using the “binary & | * $server_operation contains either the parameter passed or default this is compared with binary 16 using the “binary & bit operator” On a match runs the block of code. | ||
* If Cron is running set the tracker to | * If Cron is running set the tracker to "stop" | ||
The cron script on detecting a tracker value of | The cron script on detecting a tracker value of "stop" breaks out of an inifinatent while loop thus killing the process. | ||
| | | | ||
& | | ||
| | | | ||
'''''stop_servers.php''''' | '''''stop_servers.php''''' | ||
<pre> | |||
// === Stop Cron ======================================================== | // === Stop Cron ======================================================== | ||
if ((int)$server_operation & | if ((int)$server_operation & 16 ){ // Cron enabled by config or parameter | ||
if(get_cron_tracker() == | if(get_cron_tracker() == "stop"){ // Already stopped or not running | ||
print | print " Cron not running\n"; | ||
} | } | ||
else{ | else{ | ||
set_cron_tracker( | set_cron_tracker("stop"); // Is running signal to stop | ||
print | print" Cron stopped.\n"; // Inform user | ||
} | } | ||
} | } | ||
</pre> | |||
|} | |} | ||