Oily Rag 1: CD Part 1

From The Uniform Server Wiki
Jump to navigation Jump to search

MPG UniCenter

MPG UniCenter

Oily Rag: Be prepared to get your hands dirty.

Uniform Server 3.5-Apollo running from a CD

Uniform Server’s architecture allows it to be run without making any changes from any location on any read/write media. CD's although writable are write once only components, you cannot write to the same location more that once hence are not true read/writable. It is possible to run Uniform Server from a CD however some fundamental changes are required.

Basic idea separate out any elements that require read/write functionality and direct them to an appropriate device, For this tutorial I will be using C drive (I had considered a RAM drive however XP requires special drivers installable by a user in addition possible conflicts with virtual memory switching ruled this out). I do not propose to provide a definitive solution but to give you building blocks you can tailor to your own requirements.

Specification

I see this as a self-contained development server. With a web site completed click a button to convert the servers to run from a CD (CD Mode). Burn your project to a CD once completed click another button to revert back to normal mode of operation. Restrict functionality for CD mode (apanel wants to write and update too many files). Not a complex specification but now we know there are two components or modes of operation. It also suggests some form of file switching will be required. This tutorial covers this awitching technique I start by isolating components, create some glue elements and finally assemble them to give you an idea how it all fits together.

Isolate

First thing to look at are components that require read/write access and to ascertain any complexity involved to convert these. Before starting lets hammer a peg in the ground and define a location where writable elements will be re-directed. I will use a folder on C drive, c:/us35temp I hope the folder name is unique enough to avoid any conflicts, this name will be hard coded into our solution (an alternative to hard coding is to use search and replace scripts however that's just added complexity keep it simple is my motto).

Top

Files naming convention

I mentioned file switching, for this we need a copy of the original and a new version. I am going to use the following naming convention old_filename and new_filename respectively these will be saved to a folder named uscd for later when components are assembled.

Top For example: old_httpd.conf this will be used to revert back to a standard copy of Uniform Server while new_httpd.conf will be used for the CD version of Uniform Server.

Top

Preparation

It is possible to apply the following mods to an existing installation of Uniform Server make sure you work on a copy alternatively extract a fresh copy of Uniform Server.

Update the servers by downloading the Combined bug fix file. After running the fix check the servers function correctly.

Shutdown the servers, create a new folder in folder Uniform Server named uscd this will store our two file (new_ and old_) versions.

Top

Apache Server

Apache is reasonable to convert however it likes writing to log files well lets say its dogmatic. If it cannot create and write to these files will flatly refuse to start. Also tracks its own process hence writes to a PID file. For a CD version we do not need any custom logs, Apache is happy with this commented out.

Make the following changes to httpd.conf located in *\udrive\usr\local\apache2\conf first save the original to folder (Uniform Server/uscd) and name it old_httpd.conf.

Line Action Comment

83

Change from:
To:

PidFile logs/httpd.pid
PidFile c:/us35temp/apache/logs/httpd.pid

457

Change from:
To:

ErrorLog logs/error.log
ErrorLog c:/us35temp/apache/logs/error.log

483

Change from:
To:

CustomLog logs/access.log combined
#CustomLog logs/access.log combined

After making the changes copy httpd.conf to folder (Uniform Server/uscd) and name it new_httpd.conf

Note 1: If you are using virtual host with separate logging change the appropriate lines accordingly.

Note 2: If the files do not exist Apache will create them, hence no need to specifically create these files you only need to specify a destination folder.

MySQL Server

The MySQL server by its very nature writes vast amounts of data making it the most unlikely component to run from a CD. However by changing a single line in its configuration file that data can be located just about anywhere you like. For intermediate processing a temporary file is used and that also needs redirecting.

For CD operations you need to first dump the data (databases) to c:/us35temp/mysql/data and then start the MySQL server. This data are picked up from the new location, further the MySQL server will be fully functional. You can save the new database created and install to your working server if needed.


Make the following changes to my-small.cnf located in *\udrive\usr\local\mysql\bin first save the original to folder (Uniform Server/uscd) and name it old_my-small.cnf.

Note: The chances are you will not see the file extension .cnf, don’t worry about it, for some reason Windows likes to hide this.

Line Action Comment

35

Change from:
To:

datadir = "/usr/local/mysql/data/"
datadir = "c:/us35temp/mysql/data/"

36

Change from:
To:

tmpdir = "/tmp"
tmpdir = "c:/us35temp/mysql/tmp"

After making the changes copy my-small.cnf to folder (Uniform Server/uscd) and name it new_my-small.cnf

Top

PHP

PHP requires three locations to be changed.

Make the following changes to php.ini located in *\udrive\usr\local\php first save the original to folder (Uniform Server/uscd) and name it old_php.ini.

Line Action Comment

348

Change from:
To:

error_log = logs/logs.log
error_log = c:/us35temp/php/logs/logs.log

499

Change from:
To:

upload_tmp_dir = /tmp
upload_tmp_dir = c:/us35temp/php/tmp

884

Change from:
To:

session.save_path = "/tmp"
session.save_path = "c:/us35temp/php/tmp"

After making the changes copy php.ini to folder (Uniform Server/uscd) and name it new_php.ini

Top

phpMyAdmin

phpMyAdmin requires three locations to be changed.

Make the following changes to config.inc.php located in *\udrive\home\admin\www\phpMyAdmin first save the original to folder (Uniform Server/uscd) and name it old_config.inc.php .

Line Action Comment

449

Change from:
To:

$cfg['UploadDir'] = '/etc/phpmyadmin';
$cfg['UploadDir'] = 'c:/us35temp/phpmyadmin/etc/phpmyadmin';

452

Change from:
To:

$cfg['SaveDir'] = '/etc/phpmyadmin';
$cfg['SaveDir'] = 'c:/us35temp/phpmyadmin/etc/phpmyadmin';

458

Change from:
To:

$cfg['TempDir'] = '/tmp';
$cfg['TempDir'] = 'c:/us35temp/phpmyadmin/tmp';

After making the changes copy php.ini to folder (Uniform Server/uscd) and name it new_config.inc.php

Top

BATch files

With the core components in place we need to start and stop the servers, the original files with minor modifications are suitable for CD operation.

Server_Start.bat

Obviously no changes are required for standard operation however some modification are needed to run from a CD. When run; our new Server_Start.bat needs to perform some additional tasks:

  • Create folder c:\us35temp and any sub-folders
(This caters for both MySQL and Apache, Apache needs nothing else it will happily create the necessary files here)
  • Copy the entire data (database) from MySQL
(The only thing of importance files copied from a CD will have their read attribute set to avoid this potential problem use xcopy.)


Before making any changes save the old file to folder Uniform Server/uscd as old_Server_Start.bat

Use this link to view the new batch file (its a text file) save as new_Server_Start.bat

Below I have provided a detailed description of the new commands added to Server_Start.bat. These are placed towards the top of the file.

set ustemp=c:\us35temp Using the set command a variable ustemp is created its value is the complete path c:\us35temp to our temporary file on the c drive. To use this variable in a batch file it is contained between two % symbols.
IF NOT EXIST %ustemp% md %ustemp% When the batch file is run it checks to see if' the folder already exists on the c drive if not it makes a drive (folder) defined by our variable %ustemp%
IF NOT EXIST %ustemp% goto :ABORT Because this folder is so important we check to see if it was created. If it does not exist we jump to the line named :ABORT and start running code from there. If it exists continue to execute next line of code.
Several sub-folders are now created. For sub-folders the process is similar, create and check.
XCOPY "%CD%\udrive\usr\local\mysql\data" %ustemp%\data\ /s /q

Note: Any path that contains a space MUST be enclosed in quotes.
XCOPY is a powerful command its general syntax is XCOPY source destination switches
Source: We want to copy everything in the MySQL data folder, including sub-folders hence the switch /s Windows likes to have a complete path (relative paths are a problem). This batch file can be placed anywhere, to find anywhere we use the variable %CD% current directory (folder) this is created automatically when this batch file is run. It's the complete path up to and including the folder name.

Destination: Complete path to the folder where the database is to be copied, %ustemp%\data\ gives c:\us35temp\data\ without the ending back slash Windows can not decide if its a folder or file hence that back slash is needed.

Switches: I have covered /s which forces all sub-folders and their content to be copied. Unless you like to see rows upon rows of commands flashing by make sure you add a /q switch this stands for quite mode and stops all this unwanted information.

goto :CONTINUE Jump pass the next few lines and resume at the line named :CONTINUE
:ABORT A line or location where you can jump to using the go to command in this case our abort section, we found an error so give up.
echo Sorry the folder %ustemp% or one of its sub-folders could not be created.
echo Can not continue hence aborting
pause
EXIT
A few lines that we echo back to a user informing why we are given up. To give that person a chance to read the message pause halts the program and waits for a key to be pressed. At that point the EXIT command is executed and the batch file terminates.
:CONTINUE A line or location where you can jump to using the go to command in this case our new lines of code are complete and appear to be working hence continue to run Uniserver batch file

Top

new_Server_Start.bat

rem File Name: new_Server_Start.bat
rem Location: Uniform Server
rem Created By: The Uniform Server Development Team
rem Edited  By: Olajide Olaolorun (empirex)
rem Comment: After start, go to apanel directly.
rem To Developers: Implemented %www%, and %apanel% :)
rem Edited Last By: Mike Gleaves (Ric)
rem Comment: Proposed mods MPG (Ric) 14-4-2008
rem Proposed enhancement MPG 3-7-08
rem Added new section for CD ROM 29-06-08
rem Tutorial Oily Rag 1: CD Part 1

@echo off
rem working directory current folder 
pushd %~dp0

rem  Command line parameters:
rem  Server_Start.bat %1 %2 %3
rem  %1 = Drive letter to use
rem  %2 = mysql (run MySql server) or nomysql (do not run MySql server)
rem  %3 = console (Open a command prompt at folder MySQL Bin)
rem Note: If using %2 you must set a value for %1
rem Note: If using %3 you must set values for %1 and %2
rem Note: Default, uses drive W, runs the MySQL server and does not a command prompt.

rem === MPG new code added for CD ROM ================================================
set ustemp=c:\us35temp

:Create main folder on C
IF NOT EXIST %ustemp% md %ustemp%
IF NOT EXIST %ustemp% goto :ABORT

IF NOT EXIST %ustemp%\tmp md %ustemp%\tmp
IF NOT EXIST %ustemp%\tmp goto :ABORT

:Apache
IF NOT EXIST %ustemp%\apache\logs md %ustemp%\apache\logs
IF NOT EXIST %ustemp%\apache\logs goto :ABORT

:MySQL
IF NOT EXIST %ustemp%\mysql\data md %ustemp%\mysql\data
IF NOT EXIST %ustemp%\mysql\data goto :ABORT

IF NOT EXIST %ustemp%\mysql\tmp md %ustemp%\mysql\tmp
IF NOT EXIST %ustemp%\mysql\tmp goto :ABORT

:php ini
IF NOT EXIST %ustemp%\php\logs md %ustemp%\php\logs
IF NOT EXIST %ustemp%\php\logs goto :ABORT
IF NOT EXIST %ustemp%\php\tmp md %ustemp%\php\tmp
IF NOT EXIST %ustemp%\php\tmp goto :ABORT

:phpMyAdmin config.ini.php
IF NOT EXIST %ustemp%\phpmyadmin\etc\phpmyadmin md %ustemp%\phpmyadmin\etc\phpmyadmin
IF NOT EXIST %ustemp%\phpmyadmin\etc\phpmyadmin goto :ABORT
IF NOT EXIST %ustemp%\phpmyadmin\tmp md %ustemp%\phpmyadmin\tmp
IF NOT EXIST %ustemp%\phpmyadmin\tmp goto :ABORT

:Copy complete database 
XCOPY "%CD%\udrive\usr\local\mysql\data" %ustemp%\mysql\data\ /s /q

goto :CONTINUE
:ABORT
echo Sorry the folder %ustemp% or one of its sub-folders could not be created.
echo Can not continue hence aborting
pause
EXIT

:CONTINUE

rem === END CD ROM ============================================================

rem ### Is Apache running if it is jump to STARTED 
rem ### First check for system error jump to Pause allows error message to be displayed.
udrive\home\admin\program\pskill.exe Apache.exe
if errorlevel 2 goto :PAUSE
if not errorlevel 1 goto :STARTED

rem ### Apache not running. Check for drive letter if not set (%1) use default.
set Disk=%1
if "%Disk%"=="" set Disk=w

rem ### Create the virtual disk, if it fails go to Hint
subst %Disk%: "udrive"
if errorlevel 1 goto :HINT

rem ### Drive was created. Create variables for paths and programs 
set apachepath=\usr\local\apache2\
set apacheit=%Disk%:%apachepath%bin\Apache.exe -f %apachepath%conf\httpd.conf -d %apachepath%.
set programit=%Disk%:\home\admin\program\
set closeit=%programit%close.bat %Disk%

rem ### Change path to PHP - Required for running scripts
%Disk%:
cd \usr\local\php

rem ### Provide feedback to user
CLS
echo The server is working on the disk %Disk%:\ [http/127.0.0.1/apanel/]

rem ### Start Apache server
start %programit%uniserv.exe "%apacheit%" "%closeit%"

rem ### Start Apanel
start \home\admin\www\redirect.html

rem ### Start MySQL server - skip if requested not to start (%2)
if "%2"=="nomysql" goto :NOMYSQL
start \usr\local\mysql\bin\mysqld-opt.exe --defaults-file=/usr/local/mysql/bin/my-small.cnf
:NOMYSQL

rem ### Does user want to run a command prompt, if not END 
if "%3"=="console" goto :CONSOLE
goto :END

:CONSOLE
rem ### User wants to run a command prompt. Opens in MySQL bin
rem ### Allows command clients to be used (musql.exe and mysqladmin.exe ) 
%Disk%:
cd \usr\local\mysql\bin
start cmd.exe
goto :END

:HINT
CLS
echo The disk %Disk% is busy. Use start.bat [disk letter]
goto :PAUSE

:STARTED
CLS
echo ERROR!!! 
echo One of the instances of Apache server is started. Use stop.bat

:PAUSE
echo .
pause

:END
rem restore original working directory
popd

Top

Stop.bat

UniServer boast that it leaves no dust behind in keeping with this philosophy the last thing our new Stop.bat file does is to delete the temporary folder and all its content.

Before making any changes save the old file to folder Uniform Server/uscd as old_Stop.bat

Use this link to view the new batch file (its a text file) save as new_Stop.bat

Below I have provided a detailed description of the new commands added to Stop.bat. These are placed at the end of the file.

ping -n 20 localhost > nul This line serves no other purpose than to introduce a delay. Our temporary folder cannot be deleted until process using it terminate. I have found no way of detecting when a process ends from a batch file and then continue to the next command. Hence this little kludge delays for a certain time in the hope the processes have terminated before attempting to delete the folder. A last resort is to run stop.bat again, not elegant but works. Results returned from ping are dumped to the black hole file named nul.

-n count Number of echo requests to send

RMDIR /s /q c:\us35tempset RMDIR Remove directory (deletes a named folder) we provide the full path to that folder.
Switches: There are two switches without /s you are requested to confirm each sub-folder deletion. Quite mode is enable by /q this prevents the display of every deletion.

Top

new_Stop.bat

rem File Name: new_Sop.bat
rem Location: Uniform Server
rem Created By: The Uniform Server Development Team
rem Edited  By: Olajide Olaolorun (empirex)
rem Comment: Tara's new syetm of shutting down the server
rem To Developers: Implemented a new system of server shutdown
rem Edited Last By: Mike Gleaves (Ric)
rem Comment: Proposed mods MPG (Ric) 14-4-2008
rem Proposed enhancement MPG 3-7-08
rem Added new section for CD ROM 29-06-08
rem Tutorial Oily Rag 1: CD Part 1

@echo off
rem working directory current folder 
pushd %~dp0

rem Stop Apache indirectly stops MySQL
udrive\home\admin\program\pskill.exe Apache.exe c

rem ### Check for system error jump to Pause allows error message to be displayed.
if errorlevel 2 goto :PAUSE
goto :END
:PAUSE
echo .
pause

:END

rem === MPG new code added for CD ROM ============================
rem This intruduces a delay allowing processes to end
rem otherwise RMDIR fails and the bat must be re-run 
echo Please Wait removing files
ping -n 15 localhost > nul
:clean up remove dir
RMDIR /s /q c:\us35temp
rem ===END CD ROM ================================================
rem restore original working directory
popd

Top

Top

Download

If you have problems consider downloading this overlay file CD Part 1 copy the file to folder Uniform Server before running the file make sure you are using a copy of your servers otherwise you will need to manually reverse the above changes to return to your original servers.

Top

Testing

Start the servers using new_Server_Start.bat check they function correctly. Stop the servers using new_Stop.bat make sure the folder c:/us35temp is deleted.

That completes testing all that remains is to burn folder Uniform Server (and all its content) to a CD.

To run Uniform Server from a CD navigate to folder Uniform Server and use new_Server_Start.bat remember to run new_Stop.bat

Top

Summary

Take one clean copy of Uniform Server, add your site including database; make the above changes, burn to a CD and enjoy. I have tested the above using a copy of Uniform Server running MediaWiki with no problems.

The CD mode has a few limitations notably certain elements in apanel and phpMyBackupPro will not work; however the three core components Apache, MySQL and phpMyAdmin do.

Well what happened to this mode switching thing? Remember that folder you diligently filled with old and new files seems a pointless exercise however on the next page I put these to good use where I cover mode switching.

Top


Ric