Oily Rag 1: CD Part 4
Oily Rag 1: Introduction | CD Part 1 | CD Part 2 | CD Part 3 | CD Part 4 | CD Part 4 Scripts | CD Part 5 | CD Part 6 | Downloads |
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
- Unpack a new copy of Uniform Server 3.5-Apollo.
- Apply Combined bug fix details and download
- Download uscd4.exe from Oily Rag Download page. Save to folder Uniform Server double click to extract files.
- 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.
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.
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.
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.
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.
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 |
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: Take no further action if currently selected mode is cd-mode. |
Read content of tracking file cd_data.txt Data: 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 |
Copy bat files to Uniform Server folder rename while copying this restores the original files. |
6 |
.............. DELETE THIS SECTION IF NOT REQUIRED ............ |
.............. DELETE THIS SECTION IF NOT REQUIRED ............ |
7 |
Build path to temporary folder |
Build path to temporary folder |
8 |
Update Uniserver configuration files with new path information. Apache To accomplish this uses the function (sub) in section 10 |
Update Uniserver configuration files with new path information. Apache 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. 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. 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. |
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.
Ric |