US Tray Menu: Start Stop

From The Uniform Server Wiki
Revision as of 12:17, 31 May 2010 by Ric (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 

UniServer 5-Nano
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 men. All that is required is the ability to start it.

However for a Uniform Server specific version we require finer control.

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.

Configuration files

Folder unicon\tray_menu_2\includes contains two new files relating to menu control.

Top

config2.inc.php

We will include configuration files from the main controller however one constant is not defined, path to our new menu.

This is defined in a separate configuration file along with any other constants we will require.

/* Path variables - NO BACKSLASH */
// All paths are absolute referenced to folder UniServer 

$path_array2  = explode("\\unicon",dirname(__FILE__));   // Split at folder unicon
$base2        = "$path_array2[0]";                       // find drive letter and any sub-folders 
$base2_f      = preg_replace('/\\\/','/', $base2);       // Replace \ with /

//=== FOLDERS ===
define("US_BASE2_F",             "$base2_f");            // Uniform server base folder forward slash

define("US_UNICON_TRAY_MENU2",    US_BASE2_F."/unicon/tray_menu_2"); // UniTray menu folder

Top

functions2.php

This file contains common functions there are four functions relating to our tray menu.

File UniTray1.exe is dynamically renamed (digit incremented) during move servers see next page for details.

Top

get_unitray2_exe()

Before starting or stopping menu the name is acquired using the following function:

function get_unitray2_exe(){
  $dir_handle=opendir(US_UNICON_TRAY_MENU2);   // Get handle to Base dir 
  while($file=readdir($dir_handle)){           // Loop through folder names 
    if(preg_match("/^UniTray.+exe/", $file)){  // Search for executable name 
     $UniTray_exe=$file;                       // Match found save
     break;                                    // Noting else to do give up 
    }
  }
  closedir($dir_handle);
  return $UniTray_exe;                        // Return executable UniTray*.exe
}

Top

start_unitray2()

UniTray is started or restarted from a number of scripts.

The following function starts UniTray. Note it always assumes executable name has changed.

function start_unitray2(){

  $UniTray_exe = get_unitray2_exe();    // get program name  
  $cmd1 = "start $UniTray_exe";         // start program
  $cmd2 = ' -n ';                       // pass onfiguration file 
  $cmd3 = 'UniTray.phpw';               // pass script
  $cmd  = $cmd1 . $cmd2 . $cmd3  ;      // Build command

  pclose(popen($cmd,'r'));             // run and detatch
}

Top

stop_unitray2()

UniTray is stopped from a number of scripts.

The following function stops UniTray.

Note it always assumes executable name has changed.

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.

function stop_unitray2(){

  $UniTray_exe = get_unitray2_exe();            // get program name  
  start_unitray2();                             // Forces min to max before killing
  sleep(2);                                     // Give it a chance to pop-up

  $cmd = USF_PSKILL_EXE." $UniTray_exe" .'  c';  // Create command c=kill command 
  exec($cmd,$dummy,$return);                     // run command to kill app 
}

Top

unitray2_running()

There are occasions where it is desirable to check if UniTray is running the following function returns true if running.

function unitray2_running(){
  $UniTray_exe = get_unitray2_exe();       // get program name ;   

  $cmd = USF_PSKILL_EXE." $UniTray_exe";  // command line to be run  
  exec($cmd,$dummy,$return);              // 0=running 1=not-running 

  if($return == 0){                       // Check return value
   return true;                           // UniTray is running
  }
  else{
   return false;                          // UniTray not running
 }
}

Top

Independent control

For testing and portability PHP scripts are run using batch files. The following batch files and scripts start and stop our tray menu: Top

Start

Tray menu is started using the following batch file:

Start_UniTray.bat

:php-win.exe -n  start_unitray.php
php.exe -n  start_unitray.php
pause

This batch file runs the following script:

start_unitray.php

chdir(dirname(__FILE__)); // Change wd to this files location
include_once "../main/includes/config.inc.php";
include_once "../main/includes/functions.php";

include_once "includes/config2.inc.php";
include_once "includes/functions2.php";

run_location_tracker();   // Have servers moved if moved
                          // update configuration accordingly

start_unitray2();

exit;

Function start_unitray2() starts UniTray.

Note 1:

Any script that can potentially runs our servers first checks to see if servers have been relocated and rewrites paths accordingly.

Note 2:

The above script is common and run from folder UniServer see later.

Top

Stop

The following two scripts stop UniTray

stop_unitray.bat

:php-win.exe -n  stop_unitray.php
php.exe -n  stop_unitray.php

pause

This batch file runs the following script:

stop_unitray.php

chdir(dirname(__FILE__)); // Change wd to this files location
include_once "../main/includes/config.inc.php";
include_once "../main/includes/functions.php";

include_once "includes/config2.inc.php";
include_once "includes/functions2.php";

run_location_tracker();   // Have servers moved if moved
                          // update configuration accordingly

stop_unitray2();

exit;

Function stop_unitray2() stopps UniTray.

Top

Top-level control

Folder UniServer\unicon\tray_menu_2\top_level contains the following two files:

  • Start_UniTray_2.exe
  • Start_UniTray_2.bat

These both can be copied to the top-level folder UniServer to start UniTray.

Generally only Start_UniTray_2.exe needs to be copied. The batch file is povided for testing.

Start_UniTray_2.bat

This is a very simple script:

CD unicon\tray_menu_2 
php.exe -n start_unitray.php

It runs start_unitray.php script. For convenience the batch file is converted to an exe.

Top

Summary

The above provides several ways to control our new tray menu.

The fine control (functions) is put to good use on the next page, which coversenabling move servers

Top