Oily Rag 1: CD Part 2

Revision as of 21:42, 8 July 2008 by Ric (talk | contribs) (New page: {{Uc nav oily rag 1 CD}} '''USCD1 Plugin''' On the previous page I have shown how easy it is to modify Uniform Server 3.5-Apollo and have it running from a CD. You currently have a collec...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

MPG UniCenter

MPG UniCenter

Oily Rag: Be prepared to get your hands dirty.

USCD1 Plugin

On the previous page I have shown how easy it is to modify Uniform Server 3.5-Apollo and have it running from a CD. You currently have a collection of old and new files neatly saved in folder uscd, we now put these to good use by creating a test plugin for UniServer.

Plugin

This plugin is not overly complex it allows you to switch Uniform Server to CD mode where you can burn your design and then switch back to standard mode. To achieve switching two batches files are required one for each mode. Our design needs a reference point allowing relative paths to be used. Uniform Server already provides a plugins folder which meets our requirements.

Files and location

Currently we have a collection of files in folder uscd these I have listed below. During switching these files are copied to the location shown. While copying each file its name is changed back to the original. To perform this copying we use two batch files cd_mode_switch.bat copies only the new files and us_mode_switch.bat copies original (old) files, thus switching between CD and normal Uniform Server mode respectively.

File Location  
new_httpd.conf

old_httpd.conf

*\Uniform Server\udrive\usr\local\apache2\conf Apache
new_my-small.cnf

old_my-small.cnf

*\Uniform Server\udrive\usr\local\mysql\bin MySQL
new_php.ini

old_php.ini

*\Uniform Serve\udrive\usr\local\php PHP
new_config.inc.php

old_config.inc.php

*\Uniform Serve\udrive\home\admin\www\phpMyAdmin phpMyAdmin
new_Server_Start.bat

old_Server_Start.bat

*\Uniform Server UniServer Control
new_Stop.bat

old_Stop.bat

*\Uniform Server UniServer Cont

Top

Preperation

Create a new folder uscd1 in folder *\Uniform Server\udrive\plugins now copy the folder uscd to uscd1.

  • Folder uscd1: Will contain two new batch files cd_mode.bat and us_mode.bat these call batch files us_mode_switch.bat and cd_mode_switch.bat respectively. They can be moved to the top level folder (Uniform Server) each file contains a single line of code hence are easily modified to run the main switching batch files.
  • Folder uscd: Will contain two new batch files cd_mode_switch.bat and us_mode_switch.bat these perform file copying and renaming. Strictly speaking these are the only two files required for switching.

Note: Using four files provides a flexible architecture I prefer to have all my control files located in the top level folder you can choose whatever suits your need better.

Top

Batch file commands

Before looking at the batch files an understanding of the commands used will make the whole process easier to understand.

Batch Command Explanation
pushd %~dp0
....
batch file code
....
popd
  • pushd Pushes the Current Directory onto a memory stack (Where you came from).
  • %~dp0 This forces the current working directory to the current location of the batch file you are running. It includes the full path not just the drive letter (if its remote that’s included).
  • popd Restores the previously pushed directory (effectively returns control back to whatever call the batch file).
COPY switches source destination

COPY switches source destination Copies one or more files to another location.

Source: Complete path and name of the file to copy.

Destination: Complete path and file name to where we wish to copy the above file. The file name can be different to that of the source file. (We use this to change names back to their originals)

Switches: /Y Suppresses prompting to confirm you want to overwrite an existing destination file.

..\folder\file_name

..\..\folder\file_name

..\ not a DOS command Its a relative path name ..\ means move up one folder level ..\..\ move up two folder levels.

..\folder_name\folder_name\file_name Move up one folder level and then start moving down following the folder names to the file name.

Note: Relative to the current working directory (folder) as established above using pushd.

Top

us_mode_switch.bat

Double click on this file and you are back to a default installation of Uniform Server (Well the files we have been using). The above comments also apply to this file.

us_mode_switch.bat
rem File Name: us_mode_switch.bat
rem Location: Uniform Server\udrive\plugins\uscd1\uscd
rem Created By: UniCenter
rem Comment: Run either directly or from folder Uniform Server using us_mode.bat
rem Example plugin USCD1 3.5-Apollo
rem Edited Last By: Mike Gleaves (Ric)
rem 30-6-08 V1.0
rem Tutorial Oily Rag 1: CD Part 2
:======================================
echo off
cls
rem === Set current working directory
pushd %~dp0

rem === Copy original files back to server
rem == Uniserver control
copy /Y old_Server_Start.bat ..\..\..\..\Server_Start.bat
copy /Y old_Stop.bat ..\..\..\..\Stop.bat
rem == Apache
copy /Y old_httpd.conf ..\..\..\usr\local\apache2\conf\httpd.conf" 
rem == MySQL
copy /Y old_my-small.cnf ..\..\..\usr\local\mysql\bin\my-small.cnf"
rem == php
copy /Y old_php.ini ..\..\..\usr\local\php\php.ini"
rem == phpMyAdmin
copy /Y old_config.inc.php ..\..\..\home\admin\www\phpMyAdmin\config.inc.php"
echo.
echo Switched to US Mode
echo.
pause
popd

Top

cd_mode_switch.bat

Double click on this file and you are ready to make a few beer coasters. It really does not require an explanation; you are copying new files and overwriting the old ones.

cd_mode_switch.bat
rem File Name: cd_mode_switch.bat
rem Location: Uniform Server\udrive\plugins\uscd1\uscd
rem Created By: UniCenter
rem Comment: Run either directly or from folder Uniform Server using cd_mode.bat
rem Example plugin USCD1 3.5-Apollo
rem Edited Last By: Mike Gleaves (Ric)
rem 30-6-08 V1.0
rem Tutorial Oily Rag 1: CD Part 2
:======================================
echo off
cls
rem === Set current working directory
pushd %~dp0

rem === Copy original files back to server
rem == Uniserver control
copy /Y new_Server_Start.bat ..\..\..\..\Server_Start.bat
copy /Y new_Stop.bat ..\..\..\..\Stop.bat
rem == Apache
copy /Y new_httpd.conf ..\..\..\usr\local\apache2\conf\httpd.conf" 
rem == MySQL
copy /Y new_my-small.cnf ..\..\..\usr\local\mysql\bin\my-small.cnf"
rem == php
copy /Y new_php.ini ..\..\..\usr\local\php\php.ini"
rem == phpMyAdmin
copy /Y new_config.inc.php ..\..\..\home\admin\www\phpMyAdmin\config.inc.php"
echo.
echo Switched to CD Mode
echo.
pause
popd

Top

us_mode.bat

An alternative method of running the above two files.

us_mode.bat
rem Location: *\Uniform Server\udrive\plugins\uscd1

uscd\us_mode_switch.bat


us_mode.bat
rem Location: Uniform Server

udrive\plugins\uscd1\uscd\us_mode_switch.bat

Top

cd_mode.bat

Another alternative method of running the above two main files.

cd_mode.bat
rem Location: *\Uniform Server\udrive\plugins\uscd1

uscd\cd_mode_switch.bat


cd_mode.bat
rem Location: Uniform Server

udrive\plugins\uscd1\uscd\cd_mode_switch.bat

File Overview

This shows where to place all the files.

File Overview
Uniform Server

us_mode.bat Server_Start.bat
cd_mode.bat Stop.bat uscd2.exe          

Uniform Server\udrive\plugins\uscd1

cd_mode.bat   us_mode.bat   

Uniform Server\udrive\plugins\uscd1\uscd

new_php.ini         old_php.ini         new_Server_Start.bat old_Server_Start.bat
cd_mode_switch.bat  new_Stop.bat        old_Stop.bat         new_config.inc.php
old_config.inc.php  us_mode_switch.bat  new_httpd.conf       old_httpd.conf         
new_my-small.cnf    old_my-small.cnf       

Top

How to use the plugin

Before running the servers it is good practice to run either us_mode.bat or cd_mode.bat.

  • us_mode.bat If you are developing a web site this selects the normal Uniform Server mode.
  • cd_mode.bat When you are ready to transfer the servers and site/s to a CD run this batch file to setup CD mode. There is no need to start the servers just copy folder Uniform Server and all its content to a CD.

Top

Download

Download this overlay (plugin USCD1) file CD Part 2 copy the file to folder Uniform Server double click to extract the files. See above file overview for details of file locations.

What's next

The above is a solid foundation for producing a plugin, it can be used as is but lacks features that a real plugin should have. Part 3 revisits what we currently have and resolves these shortcomings.

Top


  Ric