Oily Rag 1: CD Part 4

From The Uniform Server Wiki
Jump to navigation Jump to search

MPG UniCenter

MPG UniCenter

Oily Rag: Be prepared to get your hands dirty.

USCD2 Plugin

On the previous page I introduced all Perl functions used in this unofficial plugin. My aim is to provide enough information allowing you to modify any part of the code to meet your own particular requirements.

To understand this plugin I start by explaining how to install and run it. I think this will make it easier to understand.

Install and run

Install

  1. Unpack a new copy of Uniform Server 3.5-Apollo.
  2. Apply Combined bug fix details and download
  3. Download uscd4.exe from Oily Rag Download page. Save to folder Uniform Server double click to extract files.
  4. This creates a new folder named uscd2 located in folder *\Uniform Server\udrive\plugins

Mode Switching

Navigate to folder *\Uniform Server\udrive\plugins\uscd2 where you will find two batch files us_mode.bat and cd_mode.bat these switch the servers between normal or CD configuration.

Note: Do not use these batch files with your servers running always close down servers first.

Top

US-Mode

This mode is the standard installation of Uniform Server if you have previously ran cd-mode running us-mode restores your servers to full operation with the configuration prior to running cd-mode. In this mode any changes you make to your servers configuration will be captured when running in CD-mode.

Top

CD-mode

Running Uniform Server from a CD a temporary folder is created on the host PC. Any temporary files including the MySQL databases are written to this folder its default is c:\us35temp.

Every time you run cd_mode.bat you are given the opportunity to change this default folder. To accept the defaults press the enter key twice alternatively enter a new drive letter and folder name. After either selecting the default or entering a new temporary folder the servers are re-configured for CD operation.

Uniform server’s configuration files are updated to reflect this new temporary folder path. Files new_Server_Start.bat and new_Stop.bat are updated accordingly these are copied and renamed replacing corresponding files in folder Uniform Server. The tracking file cd_data.txt is changed to reflect mode selected including new and old temporary paths used. This information is used when restoring the server by running us-mode.

Before committing to a CD you can start the servers and perform any tests to confirm correct operation. After testing remember to stop the servers before burning a CD.

Top

Running in CD mode

After switching to CD mode, running the servers either locally or from a CD you will notice some differences in operation.

  • Server_Start.bat: First creates a temporary folder on the host machine and then copies the MySQL databases to it. With this process complete the servers are started.
  • Stop.bat: First the servers are stopped as normal and the temporary folder and all its content are deleted.
  • Apanel: Opening apanel will reveal a reduced set of menu options and a new home page. You can modify this home page open file new_start.php found in folder uscd and edit as required.

Top

Burn to CD

Before burning a CD burn make sure the servers are not running. There is nothing special to do once cd_mode.bat has been run the servers have been configured for CD operation hence all you need to is burn the folder Uniform Server and all its content to a CD.

Run the servers using the normal Server_Start.bat and Stop.bat files on the CD.

Top

Folder and file structure

The following lists all files used; any with a prefix old_ are Uniform Server originals do not change these; they are used to restore the server, other files feel free to change.

When experimenting do not use your real server always break a copy. In the same vain treat delete and copy commands with respect i.e. make sure they delete or overwrite the files you intended.

Folder and file structure
uscd2 uscd Comments
cd_mode.bat   Double click switches to CD mode (runs cd_mode.pl)
us_mode.bat   Double click switches to US mode (runs us_mode.pl)
  cd_mode.pl Main script to set-up CD mode
  us_mode.pl Main script to set-up US mode
  cd_data.txt Tracks mode selected and temporary folder to use.
  new_Server_Start.bat Creates temporary folder on hard drive and copies MySQL databases to temporary folder.
  old_Server_Start.bat Original as default installation
  new_Stop.bat Deletes temporary folders and all files in them
  old_Stop.bat Original as default installation
  read_me_cd.txt General description what plugin does.
  new_navigation.php Apanel: Reduced menu suitable for CD
  old_navigation.php Apanel: Original menu as default installation
  new_start.php Apanel: Home page that you tailor to fit your requirements.
  old_start.php Apanel: Original home page as default installation

Top

Scripts - Overview

Workhorses for this plugin are the two scripts cd_mode.pl and us_mode.pl they mirror each other with only minor differences. Main reference point is file cd_mode.pl I have numbered each section in this file and corresponding sections in us_mode.pl. I do not propose to give a line-by-line description but a general description for each section. The files themselves are verbose hence worth a read.

Scripts
Section cd_mode.pl view Perl Script cd_mode.pl us_mode.pl view Perl Script us_mode.pl

1

Read content of tracking file cd_data.txt

Data:
Current Drive
Current Temporary Folder
Tracks currently selected mode
Previous Drive
Previous Folder

Take no further action if currently selected mode is cd-mode.

Read content of tracking file cd_data.txt

Data:
Current Drive
Current Temporary Folder
Tracks currently selected mode
Previous Drive
Previous Folder

Take no further action if currently selected mode is us-mode.

2

Display request for temporary drive and folder name. Get user input either uses defaults or new values entered. (Have not implemented any input checking)

 

3

Change mode to cd and update temporary folder information. Save data to the tracking file cd_data.txt.

Change mode to us Save this to the tracking file cd_data.txt.

4

Update new_Server_Start and new_Stop bat files to reflect the new temporary folder path.

 

5

Copy bat files to Uniform Server folder rename while copying
new_Server_Start.bat rename to Server_Start.bat
new_Stop.bat rename to Stop.bat

Copy bat files to Uniform Server folder rename while copying this restores the original files.
old_Server_Start.bat rename to Server_Start.bat
old_Stop.bat rename to Stop.bat

6

.............. DELETE THIS SECTION IF NOT REQUIRED ............
Also delete corresponding section in file us_mpde.pl
Replace: Admin menu with CD version limited functions
Replace: Admin home page.
Copy: Read_me to docs folder.

.............. DELETE THIS SECTION IF NOT REQUIRED ............
Also delete corresponding section in file cd_mode.pl
Restore: Original Admin Menu.
Restore: Original Admin Home Page
Delete: Read_me doc.

7

Build path to temporary folder

Build path to temporary folder

8

Update Uniserver configuration files with new path information.

Apache
MySQL
php
phpMyAdmin

To accomplish this uses the function (sub) in section 10

Update Uniserver configuration files with new path information.

Apache
MySQL
php
phpMyAdmin

To accomplish this uses the function (sub) in section 10

9

Wait for user to press enter key, effectively indicates script has finished.

Wait for user to press enter key, effectively indicates script has finished.

10

Function sub update_files: Search and replace all string matches in a file.
Main use of this function is to update server configuration files defined in section 8.

Section 8 is identical to both scripts; array data passed to this function are identical in both cases. After reversing the array data received CD-mode does not change the popped data order. However US-mode restores the configuration data hence after reversing the array data popped search and replace strings are interchanged.

Function sub update_files: Search and replace all string matches in a file.
Main use of this function is to update server configuration files defined in section 8.

Section 8 is identical to both scripts; array data passed to this function are identical in both cases. After reversing the array data received CD-mode does not change the popped data order. However US-mode restores the configuration data hence after reversing the array data popped search and replace strings are interchanged.

11

Function copy: Copy any file to a new location.

Function copy: Copy any file to a new location.

Top

Summary

Essentially that’s the final solution for the CD plugin; it has a few shortcomings and rough edges these are related to personal preferences. The above provides a sound foundation, you can hack the code to meet your own requirements.

One problem with the above it does not offer a complete CD solution in fact it is just one of many components required. The final part of this series covers some of the options available and proposes one solution.

Top


Ric