https://wiki.uniformserver.com/index.php?title=US_Tray_Menu:_Start_Stop&feed=atom&action=historyUS Tray Menu: Start Stop - Revision history2024-03-29T12:41:12ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=US_Tray_Menu:_Start_Stop&diff=4241&oldid=prevRic: New page: {{Nav US Tray Menu}} '''''US Tray Menu Start and Stop''''' == Introduction == Our generic menu is lacking in terms of controllability, not a problem for its intended use as a standard tray...2010-05-31T12:17:00Z<p>New page: {{Nav US Tray Menu}} '''''US Tray Menu Start and Stop''''' == Introduction == Our generic menu is lacking in terms of controllability, not a problem for its intended use as a standard tray...</p>
<p><b>New page</b></p><div>{{Nav US Tray Menu}}<br />
'''''US Tray Menu Start and Stop'''''<br />
== Introduction ==<br />
Our generic menu is lacking in terms of controllability, not a problem for its intended use as a standard tray men. All that is required is the ability to start it.<br />
<br />
However for a Uniform Server specific version we require finer control.<br />
<br />
This page covers modifications providing finer control using a set of predefined functions. These allow independent start and stop via batch files and corresponding scripts. A user requires only a top-level executable to run the menu while a script such as move-servers requires full remote control.<br />
<br />
== Configuration files ==<br />
Folder unicon\tray_menu_2\'''includes''' contains two new files relating to menu control.<br />
<br />
'''''[[#top | Top]]'''''<br />
=== config2.inc.php ===<br />
We will include configuration files from the main controller however one constant is not defined, path to our new menu.<br />
<br />
This is defined in a separate configuration file along with any other constants we will require.<br />
<pre><br />
/* Path variables - NO BACKSLASH */<br />
// All paths are absolute referenced to folder UniServer <br />
<br />
$path_array2 = explode("\\unicon",dirname(__FILE__)); // Split at folder unicon<br />
$base2 = "$path_array2[0]"; // find drive letter and any sub-folders <br />
$base2_f = preg_replace('/\\\/','/', $base2); // Replace \ with /<br />
<br />
//=== FOLDERS ===<br />
define("US_BASE2_F", "$base2_f"); // Uniform server base folder forward slash<br />
<br />
define("US_UNICON_TRAY_MENU2", US_BASE2_F."/unicon/tray_menu_2"); // UniTray menu folder<br />
</pre><br />
<br />
'''''[[#top | Top]]'''''<br />
=== functions2.php ===<br />
This file contains common functions there are four functions relating to our tray menu.<br />
<br />
File UniTray1.exe is dynamically renamed (digit incremented) during move servers see [[US Tray Menu: Move Servers | '''next page''']] for details.<br />
<br />
'''''[[#top | Top]]'''''<br />
==== get_unitray2_exe() ====<br />
Before starting or stopping menu the name is acquired using the following function:<br />
<pre><br />
function get_unitray2_exe(){<br />
$dir_handle=opendir(US_UNICON_TRAY_MENU2); // Get handle to Base dir <br />
while($file=readdir($dir_handle)){ // Loop through folder names <br />
if(preg_match("/^UniTray.+exe/", $file)){ // Search for executable name <br />
$UniTray_exe=$file; // Match found save<br />
break; // Noting else to do give up <br />
}<br />
}<br />
closedir($dir_handle);<br />
return $UniTray_exe; // Return executable UniTray*.exe<br />
}<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
==== start_unitray2() ====<br />
UniTray is started or restarted from a number of scripts.<br />
<br />
The following function starts UniTray. Note it always assumes executable name has changed.<br />
<pre><br />
function start_unitray2(){<br />
<br />
$UniTray_exe = get_unitray2_exe(); // get program name <br />
$cmd1 = "start $UniTray_exe"; // start program<br />
$cmd2 = ' -n '; // pass onfiguration file <br />
$cmd3 = 'UniTray.phpw'; // pass script<br />
$cmd = $cmd1 . $cmd2 . $cmd3 ; // Build command<br />
<br />
pclose(popen($cmd,'r')); // run and detatch<br />
}<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
==== stop_unitray2() ====<br />
UniTray is stopped from a number of scripts.<br />
<br />
The following function stops UniTray.<br />
<br />
Note it always assumes executable name has changed.<br />
<br />
Generally tray menu is minimised, it needs to be maximised for a clean kill otherwise artefacts (image) remain in the system tray. Hence it is first started and then killed using pskill.<br />
<pre><br />
function stop_unitray2(){<br />
<br />
$UniTray_exe = get_unitray2_exe(); // get program name <br />
start_unitray2(); // Forces min to max before killing<br />
sleep(2); // Give it a chance to pop-up<br />
<br />
$cmd = USF_PSKILL_EXE." $UniTray_exe" .' c'; // Create command c=kill command <br />
exec($cmd,$dummy,$return); // run command to kill app <br />
}<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
==== unitray2_running() ====<br />
There are occasions where it is desirable to check if UniTray is running the following function returns true if running.<br />
<pre><br />
function unitray2_running(){<br />
$UniTray_exe = get_unitray2_exe(); // get program name ; <br />
<br />
$cmd = USF_PSKILL_EXE." $UniTray_exe"; // command line to be run <br />
exec($cmd,$dummy,$return); // 0=running 1=not-running <br />
<br />
if($return == 0){ // Check return value<br />
return true; // UniTray is running<br />
}<br />
else{<br />
return false; // UniTray not running<br />
}<br />
}<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
<br />
== Independent control ==<br />
For testing and portability PHP scripts are run using batch files. The following batch files and scripts start and stop our tray menu:<br />
'''''[[#top | Top]]'''''<br />
<br />
=== Start ===<br />
Tray menu is started using the following batch file:<br />
<br />
==== Start_UniTray.bat ====<br />
<pre><br />
:php-win.exe -n start_unitray.php<br />
php.exe -n start_unitray.php<br />
pause<br />
</pre><br />
This batch file runs the following script:<br />
==== start_unitray.php ====<br />
<pre><br />
chdir(dirname(__FILE__)); // Change wd to this files location<br />
include_once "../main/includes/config.inc.php";<br />
include_once "../main/includes/functions.php";<br />
<br />
include_once "includes/config2.inc.php";<br />
include_once "includes/functions2.php";<br />
<br />
run_location_tracker(); // Have servers moved if moved<br />
// update configuration accordingly<br />
<br />
start_unitray2();<br />
<br />
exit;<br />
</pre><br />
Function start_unitray2() starts UniTray.<br />
<br />
'''''Note 1'':'''<br />
<br />
Any script that can potentially runs our servers first checks to see if servers have been relocated and rewrites paths accordingly.<br />
<br />
'''''Note 2'':'''<br />
<br />
The above script is common and run from folder UniServer see later. <br />
<br />
'''''[[#top | Top]]'''''<br />
=== Stop ===<br />
The following two scripts stop UniTray<br />
==== stop_unitray.bat ====<br />
<pre><br />
:php-win.exe -n stop_unitray.php<br />
php.exe -n stop_unitray.php<br />
<br />
pause<br />
</pre><br />
This batch file runs the following script:<br />
==== stop_unitray.php ====<br />
<pre><br />
chdir(dirname(__FILE__)); // Change wd to this files location<br />
include_once "../main/includes/config.inc.php";<br />
include_once "../main/includes/functions.php";<br />
<br />
include_once "includes/config2.inc.php";<br />
include_once "includes/functions2.php";<br />
<br />
run_location_tracker(); // Have servers moved if moved<br />
// update configuration accordingly<br />
<br />
stop_unitray2();<br />
<br />
exit;<br />
</pre><br />
Function stop_unitray2() stopps UniTray.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Top-level control ==<br />
Folder UniServer\unicon\tray_menu_2\top_level contains the following two files:<br />
<br />
* Start_UniTray_2.exe<br />
* Start_UniTray_2.bat<br />
<br />
These both can be copied to the top-level folder UniServer to start UniTray.<br />
<br />
Generally only Start_UniTray_2.exe needs to be copied. The batch file is povided for testing.<br />
<br />
=== Start_UniTray_2.bat ===<br />
This is a very simple script:<br />
<pre><br />
CD unicon\tray_menu_2 <br />
php.exe -n start_unitray.php<br />
</pre> <br />
It runs start_unitray.php script. For convenience the batch file is converted to an exe. <br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
The above provides several ways to control our new tray menu.<br />
<br />
The fine control (functions) is put to good use on the next page, which coversenabling [[US Tray Menu: Move Servers | '''move servers''']]<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Tutorials]]<br />
[[Category: How To]]<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric