MongoDB Tutorial 2: Alternative control: Difference between revisions

From The Uniform Server Wiki
Jump to navigation Jump to search
No edit summary
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric)
 
Line 1: Line 1:
=[http://ezapazuhem.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
{{Nav MongoDB Tutorial 2}}
{{Nav MongoDB Tutorial 2}}
'''''MongoDB'''''
'''''MongoDB'''''
Line 22: Line 21:
In folder z_mongo\UniServer\unicon\'''tray_menu_2'''.
In folder z_mongo\UniServer\unicon\'''tray_menu_2'''.
  create a new file named '''''mongo_db_inc.php''''' from file  z_mongo\temp\'''''z_temp\mongo_db_inc.php''''' copy the following lines.
  create a new file named '''''mongo_db_inc.php''''' from file  z_mongo\temp\'''''z_temp\mongo_db_inc.php''''' copy the following lines.
<pre>
<pre>
$path_array      = explode(&quot;\\usr&quot;,getcwd());              // Split at folder usr
$path_array      = explode("\\usr",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                        // find drive letter and any sub-folders  
$mongo_base      = $path_array[0];                        // find drive letter and any sub-folders  
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /


//=== FOLDERS ===
//=== FOLDERS ===
define(&quot;MONGO_BIN&quot;&quot;$mongo_base_f/usr/local/mongo_tutorial/bin&quot;);  // Binaries for MongoDB
define("MONGO_BIN""$mongo_base_f/usr/local/mongo_tutorial/bin");  // Binaries for MongoDB


//=== FILES ===
//=== FILES ===
define(&quot;CONFIG_NO_AUTH_F&quot;&quot;$mongo_base_f/usr/local/mongo_tutorial/bin/config_no_auth.ini&quot;);  
define("CONFIG_NO_AUTH_F""$mongo_base_f/usr/local/mongo_tutorial/bin/config_no_auth.ini");  
define(&quot;CONFIG_AUTH_F&quot;,      &quot;$mongo_base_f/usr/local/mongo_tutorial/bin/config_auth.ini&quot;);  
define("CONFIG_AUTH_F",      "$mongo_base_f/usr/local/mongo_tutorial/bin/config_auth.ini");  
define(&quot;NAME_PWD_F&quot;,        &quot;$mongo_base_f/usr/local/mongo_tutorial/bin/mongo_name_password&quot;);  
define("NAME_PWD_F",        "$mongo_base_f/usr/local/mongo_tutorial/bin/mongo_name_password");  
define(&quot;UNISERV_EXE&quot;,        &quot;$mongo_base_f/usr/local/mongo_tutorial/bin/uniserv.exe&quot;); // Utility  
define("UNISERV_EXE",        "$mongo_base_f/usr/local/mongo_tutorial/bin/uniserv.exe"); // Utility  
define(&quot;UNISERV_EXE_B&quot;,      $mongo_base.'\usr\local\mongo_tutorial\bin\uniserv.exe');  // Utility  
define("UNISERV_EXE_B",      $mongo_base.'\usr\local\mongo_tutorial\bin\uniserv.exe');  // Utility  
define(&quot;MON_PSKILL_EXE&quot;,    &quot;$mongo_base_f/usr/local/mongo_tutorial/bin/pskill.exe&quot;);  // Utility  
define("MON_PSKILL_EXE",    "$mongo_base_f/usr/local/mongo_tutorial/bin/pskill.exe");  // Utility  
define(&quot;CMD_DUMMY_TXT&quot;,      &quot;$mongo_base_f/usr/local/mongo_tutorial/bin/cmd_dummy.txt&quot;); // Temp command fie
define("CMD_DUMMY_TXT",      "$mongo_base_f/usr/local/mongo_tutorial/bin/cmd_dummy.txt"); // Temp command fie
&lt;/pre&gt;
</pre>
It should be obvious all paths are incorrect and need updating added to this are items relating to authentication these need deleting.
It should be obvious all paths are incorrect and need updating added to this are items relating to authentication these need deleting.


First delete authentication related to give:
First delete authentication related to give:
&lt;pre&gt;
<pre>
$path_array      = explode(&quot;\\usr&quot;,getcwd());              // Split at folder usr
$path_array      = explode("\\usr",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                        // find drive letter and any sub-folders  
$mongo_base      = $path_array[0];                        // find drive letter and any sub-folders  
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /


//=== FOLDERS ===
//=== FOLDERS ===
define(&quot;MONGO_BIN&quot;&quot;$mongo_base_f/usr/local/mongo_tutorial/bin&quot;);  // Binaries for MongoDB
define("MONGO_BIN""$mongo_base_f/usr/local/mongo_tutorial/bin");  // Binaries for MongoDB


//=== FILES ===
//=== FILES ===
define(&quot;CONFIG_NO_AUTH_F&quot;&quot;$mongo_base_f/usr/local/mongo_tutorial/bin/config_no_auth.ini&quot;);  
define("CONFIG_NO_AUTH_F""$mongo_base_f/usr/local/mongo_tutorial/bin/config_no_auth.ini");  
define(&quot;UNISERV_EXE&quot;,        &quot;$mongo_base_f/usr/local/mongo_tutorial/bin/uniserv.exe&quot;); // Utility  
define("UNISERV_EXE",        "$mongo_base_f/usr/local/mongo_tutorial/bin/uniserv.exe"); // Utility  
define(&quot;UNISERV_EXE_B&quot;,      $mongo_base.'\usr\local\mongo_tutorial\bin\uniserv.exe');  // Utility  
define("UNISERV_EXE_B",      $mongo_base.'\usr\local\mongo_tutorial\bin\uniserv.exe');  // Utility  
define(&quot;MON_PSKILL_EXE&quot;,    &quot;$mongo_base_f/usr/local/mongo_tutorial/bin/pskill.exe&quot;);  // Utility  
define("MON_PSKILL_EXE",    "$mongo_base_f/usr/local/mongo_tutorial/bin/pskill.exe");  // Utility  
&lt;/pre&gt;
</pre>
First line splits current working directory at folder '''''usr''''' this requires changing. Choose a folder that is common to folders '''usr''' and '''unicon''', in this case use folder '''''UniServer'''''
First line splits current working directory at folder '''''usr''''' this requires changing. Choose a folder that is common to folders '''usr''' and '''unicon''', in this case use folder '''''UniServer'''''


Line 63: Line 62:
=== Paths ===
=== Paths ===
After making the changes section looks like this:
After making the changes section looks like this:
&lt;pre&gt;
<pre>
$path_array      = explode(&quot;\\UniServer&quot;,getcwd());              // Split at folder usr
$path_array      = explode("\\UniServer",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                        // find drive letter and any sub-folders  
$mongo_base      = $path_array[0];                        // find drive letter and any sub-folders  
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /


//=== FOLDERS ===
//=== FOLDERS ===
define(&quot;MONGO_BIN&quot;&quot;$mongo_base_f/UniServer/usr/local/mongo/bin&quot;);  // Binaries for MongoDB
define("MONGO_BIN""$mongo_base_f/UniServer/usr/local/mongo/bin");  // Binaries for MongoDB


//=== FILES ===
//=== FILES ===
define(&quot;CONFIG_NO_AUTH_F&quot;,  MONGO_BIN.&quot;/config_no_auth.ini&quot;);  
define("CONFIG_NO_AUTH_F",  MONGO_BIN."/config_no_auth.ini");  
define(&quot;UNISERV_EXE&quot;,        MONGO_BIN.&quot;/uniserv.exe&quot;); // Utility  
define("UNISERV_EXE",        MONGO_BIN."/uniserv.exe"); // Utility  
define(&quot;UNISERV_EXE_B&quot;,      $mongo_base.'\UniServer\usr\local\mongo\bin\uniserv.exe');  // Utility  
define("UNISERV_EXE_B",      $mongo_base.'\UniServer\usr\local\mongo\bin\uniserv.exe');  // Utility  
define(&quot;MON_PSKILL_EXE&quot;,    MONGO_BIN.&quot;/pskill.exe&quot;);  // Utility  
define("MON_PSKILL_EXE",    MONGO_BIN."/pskill.exe");  // Utility  


&lt;/pre&gt;
</pre>


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
Line 91: Line 90:
|-
|-
|
|
&lt;pre&gt;
<pre>
TITLE UNIFORM SERVER - Run Command Prompt
TITLE UNIFORM SERVER - Run Command Prompt
COLOR B0
COLOR B0
Line 102: Line 101:
pause
pause
EXIT
EXIT
&lt;/pre&gt;
</pre>
|
|
'''''Comments'':'''
'''''Comments'':'''
Line 121: Line 120:
|-
|-
|
|
&lt;pre&gt;
<pre>
&lt;?php
<?php


chdir(dirname(__FILE__)); // Change wd to this files location
chdir(dirname(__FILE__)); // Change wd to this files location
include_once &quot;../../../../unicon/tray_menu_2/mongo_db_inc.php&quot;;
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";


open_cmd_window(); // Run command prompt function
open_cmd_window(); // Run command prompt function


?&gt;
?>
&lt;/pre&gt;
</pre>
|
|
* Change folder to alt_control
* Change folder to alt_control
Line 166: Line 165:
Create the following scripts with content as shown
Create the following scripts with content as shown
=== Run_start_mongo.bat ===
=== Run_start_mongo.bat ===
&lt;pre&gt;
<pre>


TITLE UNIFORM SERVER - Run Start MongoDB
TITLE UNIFORM SERVER - Run Start MongoDB
Line 178: Line 177:
pause
pause
EXIT
EXIT
&lt;/pre&gt;
</pre>
=== run_start_mongo.php ===
=== run_start_mongo.php ===
&lt;pre&gt;
<pre>
&lt;?php
<?php


chdir(dirname(__FILE__)); // Change wd to this files location
chdir(dirname(__FILE__)); // Change wd to this files location
include_once &quot;../../../../unicon/tray_menu_2/mongo_db_inc.php&quot;;
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";


start_mongo_no_auth(); // Run start mongo function
start_mongo_no_auth(); // Run start mongo function
?&gt;
?>
&lt;/pre&gt;
</pre>
=== Run_stop_mongo.bat ===
=== Run_stop_mongo.bat ===
&lt;pre&gt;
<pre>


TITLE UNIFORM SERVER - Run Stop MongoDB
TITLE UNIFORM SERVER - Run Stop MongoDB
Line 202: Line 201:
pause
pause
EXIT
EXIT
&lt;/pre&gt;
</pre>
=== run_stop_mongo.php ===
=== run_stop_mongo.php ===
&lt;pre&gt;
<pre>
&lt;?php
<?php
chdir(dirname(__FILE__)); // Change wd to this files location
chdir(dirname(__FILE__)); // Change wd to this files location
include_once &quot;../../../../unicon/tray_menu_2/mongo_db_inc.php&quot;;
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";


stop_mongo_no_auth() ; // Run command prompt function
stop_mongo_no_auth() ; // Run command prompt function
?&gt;
?>
&lt;/pre&gt;
</pre>


=== Run_client.bat ===
=== Run_client.bat ===
&lt;pre&gt;
<pre>
TITLE UNIFORM SERVER - Run Mongo Client
TITLE UNIFORM SERVER - Run Mongo Client
COLOR B0
COLOR B0
Line 225: Line 224:
pause
pause
EXIT
EXIT
&lt;/pre&gt;
</pre>
=== run_client.php ===
=== run_client.php ===
&lt;pre&gt;
<pre>
&lt;?php
<?php
chdir(dirname(__FILE__)); // Change wd to this files location
chdir(dirname(__FILE__)); // Change wd to this files location
include_once &quot;../../../../unicon/tray_menu_2/mongo_db_inc.php&quot;;
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";


client_no_auth() ; // Run command prompt function
client_no_auth() ; // Run command prompt function
?&gt;
?>
&lt;/pre&gt;
</pre>


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''

Latest revision as of 08:17, 24 November 2010

 

MongoDB Plugin
UniServer 6-Carbo.

MongoDB

Introduction

Alternative control is a spin-off from testing the main application. These batch/scripts are worth keeping because users may prefer them.

Requirements

Scripts for alternative control are contained in folder z_mongo\UniServer\usr\local\mongo\alt_control\alt_control these scripts reflect functionality of our main program.

We require scripts that perform the following tasks:

  • Start MongoDB
  • Stop MongoDB
  • Run Mongo client
  • Open a command prompt

Four batch files and corresponding PHP scripts are required. These PHP scripts obtain their resources (paths function) from a shared include file located in folder z_mongo\UniServer\unicon\tray_menu_2.

Top

Main include file

During the introduction tutorial we created a file mongo_db_inc.php containing functions required for various application. A sub-set from this file is required for this application.

In folder z_mongo\UniServer\unicon\tray_menu_2.

create a new file named mongo_db_inc.php from file  z_mongo\temp\z_temp\mongo_db_inc.php copy the following lines.
$path_array      = explode("\\usr",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                         // find drive letter and any sub-folders 
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /

//=== FOLDERS ===
define("MONGO_BIN",   "$mongo_base_f/usr/local/mongo_tutorial/bin");  // Binaries for MongoDB

//=== FILES ===
define("CONFIG_NO_AUTH_F",   "$mongo_base_f/usr/local/mongo_tutorial/bin/config_no_auth.ini"); 
define("CONFIG_AUTH_F",      "$mongo_base_f/usr/local/mongo_tutorial/bin/config_auth.ini"); 
define("NAME_PWD_F",         "$mongo_base_f/usr/local/mongo_tutorial/bin/mongo_name_password"); 
define("UNISERV_EXE",        "$mongo_base_f/usr/local/mongo_tutorial/bin/uniserv.exe"); // Utility 
define("UNISERV_EXE_B",      $mongo_base.'\usr\local\mongo_tutorial\bin\uniserv.exe');  // Utility 
define("MON_PSKILL_EXE",     "$mongo_base_f/usr/local/mongo_tutorial/bin/pskill.exe");  // Utility 
define("CMD_DUMMY_TXT",      "$mongo_base_f/usr/local/mongo_tutorial/bin/cmd_dummy.txt"); // Temp command fie

It should be obvious all paths are incorrect and need updating added to this are items relating to authentication these need deleting.

First delete authentication related to give:

$path_array      = explode("\\usr",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                         // find drive letter and any sub-folders 
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /

//=== FOLDERS ===
define("MONGO_BIN",   "$mongo_base_f/usr/local/mongo_tutorial/bin");  // Binaries for MongoDB

//=== FILES ===
define("CONFIG_NO_AUTH_F",   "$mongo_base_f/usr/local/mongo_tutorial/bin/config_no_auth.ini"); 
define("UNISERV_EXE",        "$mongo_base_f/usr/local/mongo_tutorial/bin/uniserv.exe"); // Utility 
define("UNISERV_EXE_B",      $mongo_base.'\usr\local\mongo_tutorial\bin\uniserv.exe');  // Utility 
define("MON_PSKILL_EXE",     "$mongo_base_f/usr/local/mongo_tutorial/bin/pskill.exe");  // Utility 

First line splits current working directory at folder usr this requires changing. Choose a folder that is common to folders usr and unicon, in this case use folder UniServer

With this split we have a reference $mongo_base that is a path up to folder UniSerer hence this folder must be added to the paths being reconstructed.

Top

Paths

After making the changes section looks like this:

$path_array      = explode("\\UniServer",getcwd());              // Split at folder usr
$mongo_base      = $path_array[0];                         // find drive letter and any sub-folders 
$mongo_base_f    = preg_replace('/\\\/','/', $mongo_base); // Replace \ with /

//=== FOLDERS ===
define("MONGO_BIN",   "$mongo_base_f/UniServer/usr/local/mongo/bin");  // Binaries for MongoDB

//=== FILES ===
define("CONFIG_NO_AUTH_F",   MONGO_BIN."/config_no_auth.ini"); 
define("UNISERV_EXE",        MONGO_BIN."/uniserv.exe"); // Utility 
define("UNISERV_EXE_B",      $mongo_base.'\UniServer\usr\local\mongo\bin\uniserv.exe');  // Utility 
define("MON_PSKILL_EXE",     MONGO_BIN."/pskill.exe");  // Utility 

Top

Command Prompt

From z_mongo\temp\mongo_db_inc.php copy function open_cmd_window() to file z_mongo\UniServer\unicon\tray_menu_2\mongo_db_inc.php

In folder alt_control create the following two files with content as shown

Top

Run_cmd.bat

TITLE UNIFORM SERVER - Run Command Prompt
COLOR B0
@echo off
cls

cd ..\..\php
php.exe -c mongo_cli.ini ..\mongo\alt_control\run_cmd.php

pause
EXIT

Comments:

  • ..\..\php Changes working folder. From current folder ..\..\ move up two folder levels and down into folder php
  • php.exe Run PHP
  • -c mongo_cli.ini Use this configuration file
  • ..\mongo\alt_control\run_cmd.php Move up one folder level and down into folder alt_control and run script run_cmd.php

Note:

After testing you can comment out the pause.

run_cmd.php

<?php

chdir(dirname(__FILE__)); // Change wd to this files location
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";

open_cmd_window(); // Run command prompt function

?>
  • Change folder to alt_control
  • Include file. Move up four folder levels down into folder tray_menu_2 and include file mongo_db_inc.php
  • Run function open_cmd_window()

Top

Test

  • Run batch file. Double click on Run_cmd.bat
  • A command window opens displaying the content of folder bin

Above confirms we have a working structure and can add further components.

Top

Support Functions

A user can change server’s working port in the configuration file.

We have a function that determines this

From z_mongo\temp\mongo_db_inc.php copy function get_mongo_port_no_auth() to file z_mongo\UniServer\unicon\tray_menu_2\mongo_db_inc.php

We will require several functions hence copy the following:

  • set_mongo_port_no_auth($new_port)
  • start_mongo_no_auth()
  • stop_mongo_no_auth()
  • client_no_auth()
  • mongodb_running()
  • mongo_client_running()

Top

Additional Scripts

Create the following scripts with content as shown

Run_start_mongo.bat


TITLE UNIFORM SERVER - Run Start MongoDB
COLOR B0
@echo off
cls

cd ..\..\php
php.exe -c mongo_cli.ini ..\mongo\alt_control\run_start_mongo.php

pause
EXIT

run_start_mongo.php

<?php

chdir(dirname(__FILE__)); // Change wd to this files location
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";

start_mongo_no_auth(); // Run start mongo function
?>

Run_stop_mongo.bat


TITLE UNIFORM SERVER - Run Stop MongoDB
COLOR B0
@echo off
cls

cd ..\..\php
php.exe -c mongo_cli.ini ..\mongo\alt_control\run_stop_mongo.php

pause
EXIT

run_stop_mongo.php

<?php
chdir(dirname(__FILE__)); // Change wd to this files location
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";

stop_mongo_no_auth() ; // Run command prompt function
?>

Run_client.bat

TITLE UNIFORM SERVER - Run Mongo Client
COLOR B0
@echo off
cls

cd ..\..\php
php.exe -c mongo_cli.ini ..\mongo\alt_control\run_client.php

pause
EXIT

run_client.php

<?php
chdir(dirname(__FILE__)); // Change wd to this files location
include_once "../../../../unicon/tray_menu_2/mongo_db_inc.php";

client_no_auth() ; // Run command prompt function
?>

Top

Test

  • Start server double click on Run_start_mongo.bat wait a short time
  • Run client double click on Run_client.bat check connection is made. Type exit
  • Stop server double click on Run_stop_mongo.bat wait a short time
  • Run client double click on Run_client.bat check connection fails.

Top

Summary

I was asked why do you need the PHP CLI scripts? They were included only to test each associated function.

Thinking about that question the user had not missed the point what they wanted were pure batch files no PHP.

I have addressed the above on the next page Alternative control 2


Top