dk.netarkivet.deploy
Class LinuxMachine

java.lang.Object
  extended by dk.netarkivet.deploy.Machine
      extended by dk.netarkivet.deploy.LinuxMachine

public class LinuxMachine
extends Machine

A LinuxMachine is the instance of the abstract machine class, which runs the operating system Linux or another Unix dependent operation system. This class only contains the operating system specific functions.


Field Summary
 
Fields inherited from class dk.netarkivet.deploy.Machine
applications, databaseFile, inheritedLogPropFile, inheritedSecurityPolicyFile, log, machineDirectory, machineParameters, machineRoot, name, netarchiveSuiteFileName, OS, resetTempDir, scriptExtension, settings
 
Constructor Summary
LinuxMachine(org.dom4j.Element subTreeRoot, XmlStructure parentSettings, Parameters param, java.lang.String netarchiveSuiteSource, java.io.File logProp, java.io.File securityPolicy, java.io.File dbFile, boolean resetDir)
          The constructor.
 
Method Summary
protected  java.lang.String changeFileDirPathForSecurity(java.lang.String path)
          Changes the file directory path to the format used in the security policy.
protected  void createApplicationKillScripts(java.io.File directory)
          Creates the kill scripts for all the applications.
protected  void createApplicationStartScripts(java.io.File directory)
          Creates the start scripts for all the applications.
protected  void createInstallDirScript(java.io.File dir)
          Dummy function on linux machine.
protected  void createOSLocalKillAllScript(java.io.File directory)
          This function creates the script to kill all applications on this machine.
protected  void createOSLocalStartAllScript(java.io.File directory)
          This function creates the script to start all applications on this machine.
protected  java.lang.String createPathToDir(java.lang.String dir)
          Function for creating the directories along the path until the end directory.
protected  java.lang.String getAppDirectories()
          Creates the script for creating the application specified directories.
protected  java.lang.String getConfDirPath()
          The operation system specific path to the conf directory.
protected  java.lang.String getInstallDirPath()
          The operation system specific path to the installation directory.
protected  java.lang.String getJMXremoteFilesCommand()
          This method does the following: Retrieves the path to the jmxremote.access and jmxremote.password files.
protected  java.lang.String osGetClassPath(Application app)
          Makes all the class paths into the operation system specific syntax, and puts them into a string where they are separated by the operation system specific separator (':' for linux, ';' for windows).
protected  java.lang.String osInstallDatabase()
          Checks if a specific directory for the database is given in the settings, and thus if the database should be installed on this machine.
protected  java.lang.String osInstallScript()
          Creates the operation system specific installation script for this machine.
protected  java.lang.String osInstallScriptCreateDir()
          Creates the specified directories in the deploy-configuration file.
protected  java.lang.String osKillScript()
          Creates the operation system specific killing script for this machine.
protected  java.lang.String osStartScript()
          Creates the operation system specific starting script for this machine.
protected  java.lang.String scriptCreateDir(java.lang.String dir, boolean clean)
          This functions makes the script for creating the new directories.
 
Methods inherited from class dk.netarkivet.deploy.Machine
createJmxRemoteAccessFile, createJmxRemotePasswordFile, createLogPropertyFiles, createSecurityPolicyFile, getEnvironmentName, getHeritrixLogin, getHeritrixUsername, getMonitorLogin, getMonitorUsername, machineUserLogin, write, writeToGlobalInstallScript, writeToGlobalKillScript, writeToGlobalStartScript
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinuxMachine

public LinuxMachine(org.dom4j.Element subTreeRoot,
                    XmlStructure parentSettings,
                    Parameters param,
                    java.lang.String netarchiveSuiteSource,
                    java.io.File logProp,
                    java.io.File securityPolicy,
                    java.io.File dbFile,
                    boolean resetDir)
The constructor. Starts by initialising the parent abstract class, then sets the operating system dependent variables.

Parameters:
subTreeRoot - The XML root element.
parentSettings - The Settings to be inherited from the PhysicalLocation, where this machine is placed.
param - The machine parameters to be inherited from the PhysicalLocation.
netarchiveSuiteSource - The name of the NetarchiveSuite package file. Must end with '.zip'.
logProp - The logging property file, to be copied into machine directory.
securityPolicy - The security policy file, to be copied into machine directory.
dbFile - The name of the database file.
resetDir - Whether the temporary directory should be reset.
Method Detail

osInstallScript

protected java.lang.String osInstallScript()
Creates the operation system specific installation script for this machine.

Specified by:
osInstallScript in class Machine
Returns:
Operation system specific part of the installscript

osKillScript

protected java.lang.String osKillScript()
Creates the operation system specific killing script for this machine.

Specified by:
osKillScript in class Machine
Returns:
Operation system specific part of the killscript.

osStartScript

protected java.lang.String osStartScript()
Creates the operation system specific starting script for this machine. pseudo code: - ssh maclogin ". /etc/profile; conf/startall.sh; sleep 5; cat install/*.log" where: maclogin = login for machine (username@machine). conf = path to /conf directory. install = path to install directory.

Specified by:
osStartScript in class Machine
Returns:
Operation system specific part of the startscript.

getInstallDirPath

protected java.lang.String getInstallDirPath()
The operation system specific path to the installation directory.

Specified by:
getInstallDirPath in class Machine
Returns:
Install path.

getConfDirPath

protected java.lang.String getConfDirPath()
The operation system specific path to the conf directory.

Specified by:
getConfDirPath in class Machine
Returns:
Conf path.

createOSLocalKillAllScript

protected void createOSLocalKillAllScript(java.io.File directory)
This function creates the script to kill all applications on this machine. The scripts calls all the kill script for each application. pseudo code: - echo Killing all applications at machine: mac - if [ -e ./kill_app.sh ] - ./kill_app.sh - fi - ... where: mac = machine name. app = application name. ... = the same for other applications.

Specified by:
createOSLocalKillAllScript in class Machine
Parameters:
directory - The directory for this machine (use global variable?).

createOSLocalStartAllScript

protected void createOSLocalStartAllScript(java.io.File directory)
This function creates the script to start all applications on this machine. The scripts calls all the start script for each application. pseudo code: - echo Starting all applications at machine: mac - if [ -e ./start_app.sh ] - ./start_app.sh - fi - ... where: mac = machine name. app = application name. ... = the same for other applications.

Specified by:
createOSLocalStartAllScript in class Machine
Parameters:
directory - The directory for this machine (use global variable?).

createApplicationKillScripts

protected void createApplicationKillScripts(java.io.File directory)
Creates the kill scripts for all the applications. The script starts by finding all running processes of the application. If it finds any processes, it kills them. The kill_app.sh should have the following structure: - echo Killing linux application. - #!/bin/bash - PIDS = $(ps -wwfe | grep fullapp | grep -v grep | grep path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then - kill -9 $PIDS; - fi Also, if a heritrix process is started, the following is added: - PIDS = $(ps -wwfe | grep heritrix | grep -v grep | grep path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then - kill -9 $PIDS; - fi where: path = the path to the ./conf directory. fullapp = the full application name with class path. app = the id of the application (name + instanceId). heritrix = the heritrix class path.

Specified by:
createApplicationKillScripts in class Machine
Parameters:
directory - The directory for this machine (use global variable?).

createApplicationStartScripts

protected void createApplicationStartScripts(java.io.File directory)
Creates the start scripts for all the applications. The application should only be started, if it is not running already. The script starts by finding all running processes of the application. If any processes are found, a new application should not be started. Otherwise start the application. The start_app.sh should have the following structure: - echo Starting linux application: app - cd path - #!/bin/bash - PIDS = $(ps -wwfe | grep fullapp | grep -v grep | grep path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then - echo Application already running. - else - export CLASSPATH = cp:$CLASSPATH; - JAVA - fi where: path = the path to the install directory. fullapp = the full name application with java path. app = the name of the application. cp = the classpaths for the application. JAVA = the command to run the java application.

Specified by:
createApplicationStartScripts in class Machine
Parameters:
directory - The directory for this machine (use global variable?).

osGetClassPath

protected java.lang.String osGetClassPath(Application app)
Makes all the class paths into the operation system specific syntax, and puts them into a string where they are separated by the operation system specific separator (':' for linux, ';' for windows).

Specified by:
osGetClassPath in class Machine
Parameters:
app - The application which has the class paths.
Returns:
The class paths in operation system specific syntax.

osInstallDatabase

protected java.lang.String osInstallDatabase()
Checks if a specific directory for the database is given in the settings, and thus if the database should be installed on this machine. If no specific database is given (databaseFileName = null) then use the standard database extracted from NetarchiveSuite.zip. Else send the given new database to the standard database location. Extract the database in the standard database location to the specified database directory.

Specified by:
osInstallDatabase in class Machine
Returns:
The script for installing the database (if needed).

osInstallScriptCreateDir

protected java.lang.String osInstallScriptCreateDir()
Creates the specified directories in the deploy-configuration file. Structure - ssh login cd path; DIRS; CLEANDIR; exit; where: login = username@machine. path = path to install directory. DIRS = the way to create directories. CLEANDIR = the command to clean the tempDir (if chosen as optional) The install creation of DIR has the following structure for directory dir: if [ ! -d dir ]; then mkdir dir; fi;

Specified by:
osInstallScriptCreateDir in class Machine
Returns:
The script for creating the directories.

scriptCreateDir

protected java.lang.String scriptCreateDir(java.lang.String dir,
                                           boolean clean)
This functions makes the script for creating the new directories. Linux creates directories directly through ssh. Windows creates an install a script file for installing the directories, which has to be sent to the machine, then executed and finally deleted.

Specified by:
scriptCreateDir in class Machine
Parameters:
dir - The name of the directory to create.
clean - Whether the directory should be cleaned\reset.
Returns:
The lines of code for creating the directories.
See Also:
createInstallDirScript(File)

createPathToDir

protected java.lang.String createPathToDir(java.lang.String dir)
Function for creating the directories along the path until the end directory. Does not create the end directory.

Parameters:
dir - The path to the directory.
Returns:
The script for creating the directory.

getAppDirectories

protected java.lang.String getAppDirectories()
Creates the script for creating the application specified directories.

Specified by:
getAppDirectories in class Machine
Returns:
The script for creating the application specified directories.

createInstallDirScript

protected void createInstallDirScript(java.io.File dir)
Dummy function on linux machine. This is only used for windows machines!

Specified by:
createInstallDirScript in class Machine
Parameters:
dir - The directory to put the file.

changeFileDirPathForSecurity

protected java.lang.String changeFileDirPathForSecurity(java.lang.String path)
Changes the file directory path to the format used in the security policy.

Specified by:
changeFileDirPathForSecurity in class Machine
Parameters:
path - The current path.
Returns:
The formatted path.

getJMXremoteFilesCommand

protected java.lang.String getJMXremoteFilesCommand()
This method does the following: Retrieves the path to the jmxremote.access and jmxremote.password files. Moves these files, if they are different from standard. Makes the jmxremote.access and jmxremote.password files readonly.

Specified by:
getJMXremoteFilesCommand in class Machine
Returns:
The commands for handling the jmxremote files.