public class WindowsMachine extends Machine
Modifier and Type | Class and Description |
---|---|
protected static class |
WindowsMachine.windowsStartVbsScriptTpl |
applications, arcDatabaseFile, databaseFile, hostname, inheritedSecurityPolicyFile, inheritedSlf4jConfigFile, jarFolder, log, machineDirectory, machineParameters, machineRoot, netarchiveSuiteFileName, operatingSystem, resetTempDir, scriptExtension, settings, targetEncoding
Constructor and Description |
---|
WindowsMachine(org.dom4j.Element root,
XmlStructure parentSettings,
Parameters param,
String netarchiveSuiteSource,
File slf4JConfig,
File securityPolicy,
File dbFile,
File arcdbFile,
boolean resetDir,
File externalJarFolder)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
protected String |
changeFileDirPathForSecurity(String path)
Changes the file directory path to the format used in the security policy.
|
protected void |
createApplicationKillScripts(File directory)
Creates the kill scripts for all the applications.
|
protected void |
createApplicationStartScripts(File directory)
Creates the start scripts for all the applications.
|
protected void |
createArchiveDatabaseKillScript(File dir)
Creates a script for killing the archive database on a given machine.
|
protected void |
createArchiveDatabaseStartScript(File dir)
Creates a script for starting the archive database on a given machine.
|
protected void |
createHarvestDatabaseKillScript(File dir)
Creates a script for killing the harvest database on a given machine.
|
protected void |
createHarvestDatabaseStartScript(File dir)
Creates a script for starting the harvest database on a given machine.
|
protected void |
createHarvestDatabaseUpdateScript(File machineDirectory,
boolean forceCreate)
create a harvestDatabaseUpdatescript in the given machineDirectory.
|
protected void |
createInstallDirScript(File directory)
Function to create the script which installs the new directories.
|
protected void |
createOSLocalKillAllScript(File directory)
This function creates the script to kill all applications on this machine.
|
protected void |
createOSLocalStartAllScript(File directory)
This function creates the script to start all applications on this machine.
|
protected String |
createPathToDir(String dir)
Function for creating the directories along the path until the end directory.
|
protected void |
createRestartScript(File dir)
Creates scripts for restarting all the applications on a machine.
|
protected void |
createWaitScript(File dir)
Creates the script for waiting during restart.
|
protected String |
getAppDirectories()
Creates the script for creating the application specified directories.
|
protected String |
getConfDirPath()
The operation system specific path to the conf directory.
|
protected String |
getInstallDirPath()
The operation system specific path to the installation directory.
|
protected String |
getJMXremoteFilesCommand()
This method does the following:
|
protected String |
getLibDirPath()
The operation system specific path to the lib directory.
|
protected String |
getLocalConfDirPath()
Creates the local path to the conf dir.
|
protected String |
getLocalInstallDirPath()
Creates the local path to the installation directory.
|
protected String |
getLocalLibDirPath()
Creates the local path to the lib dir.
|
protected String |
getMakeDirectoryName()
Creates the name for the make dir script.
|
protected 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 String |
osInstallArchiveDatabase()
THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX!
|
protected String |
osInstallDatabase()
THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX!
|
protected String |
osInstallExternalJarFiles()
This function makes the part of the install script for installing the external jar files from within the
jarFolder.
|
protected String |
osInstallScript()
Creates the operation system specific installation script for this machine.
|
protected String |
osInstallScriptCreateDir()
Creates the specified directories in the deploy config file.
|
protected String |
osKillScript()
Creates the operation system specific killing script for this machine.
|
protected String |
osStartScript()
Creates the operation system specific starting script for this machine.
|
protected String |
scriptCreateDir(String dir,
boolean clean)
This functions makes the script for creating the new directories.
|
protected void |
windowsStartBatScript(Application app,
File directory)
Creates the batch script for starting the application.
|
protected void |
windowsStartVbsScript(Application app,
File directory)
This function creates the VBscript to start the application.
|
createJmxRemoteAccessFile, createJmxRemotePasswordFile, createSecurityPolicyFile, createSlf4jConfigFiles, getEnvironmentName, getHeritrixLogin, getHeritrixUsername, getMonitorLogin, getMonitorUsername, getTargetEncoding, machineUserLogin, modifyLogProperties, write, writeToGlobalInstallScript, writeToGlobalKillScript, writeToGlobalStartScript
public WindowsMachine(org.dom4j.Element root, XmlStructure parentSettings, Parameters param, String netarchiveSuiteSource, File slf4JConfig, File securityPolicy, File dbFile, File arcdbFile, boolean resetDir, File externalJarFolder)
root
- 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 be '.zip'.securityPolicy
- The security policy file, to be copied into machine directory.dbFile
- The harvest definition database file.arcdbFile
- The archive database.resetDir
- Whether the temporary directory should be reset.externalJarFolder
- The folder containing the external jar library files.protected String osInstallScript()
Pseudo code: - echo copying 'NetarchiveSuite.zip' to: 'machine' - scp 'NetarchiveSuite.zip' 'login'@'machine': - echo unzipping 'NetarchiveSuite.zip' at: 'machine' - ssh 'login'@'machine' 'unzip' 'environmentName' -o 'NetarchiveSuite.zip - $'create directories'. - echo preparing for copying of settings and scripts - if [ $( ssh 'login'@'machine' cmd /c if exist 'environmentName'\\conf\\jmxremote.password echo 1 ) ]; then echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\conf\\jmxremote.password /P BITARKIV\\'login':F; fi - if [ $( ssh 'login'@'machine' cmd /c if exist 'environmentName'\\conf\\jmxremote.access echo 1 ) ]; then echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\conf\\jmxremote.access /P BITARKIV\\'login':F; fi - echo copying settings and scripts - scp -r 'machine'/* 'login'@'machine':'environmentName'\\conf\\ - $'apply database script' - echo make password files readonly * if 'jmxremote-password-path' != 'jmxremote-password-defaultpath' - ssh 'login'@'machine' move /Y 'jmxremote-password-defaultpath' 'jmxremote-password-path' * if 'jmxremote-access-path' != 'jmxremote-access-defaultpath' - ssh 'login'@'machine' move /Y 'jmxremote-access-defaultpath' 'jmxremote-access-path' - echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\'jmxremote-password-path' /P BITARKIV\\'login':R - echo Y | ssh 'login'@'machine' cmd /c cacls 'environmentName'\\'jmxremote-access-path' /P BITARKIV\\'login':R
variables: 'NetarchiveSuite.zip' = The NetarchiveSuitePackage with '.zip' extension. 'machine' = The machine name. 'login' = The username for the machine. 'unzip' = The command for unzipping. 'environmentName' = the environmentName from the configuration file.
$'...' = call other function.
osInstallScript
in class Machine
protected String osKillScript()
pseudocode: - ssh 'login'@'machine' cmd /c 'environmentName'\\conf\\killall.bat
variables: 'login' = machine user name 'machine' = name of the machine 'environmentName' = the environmentName from configuration.
osKillScript
in class Machine
protected String osStartScript()
pseudocode: - ssh 'login'@'machine' cmd /c 'environmentName'\\conf\\startall.bat - sleep 5 - ssh 'login'@'machine' "more 'environmentName'\\start_APP.log
variables: 'login' = machine user name 'machine' = name of the machine 'environmentName' = the environmentName from configuration.
osStartScript
in class Machine
protected String getInstallDirPath()
Machine
getInstallDirPath
in class Machine
protected String getConfDirPath()
Machine
getConfDirPath
in class Machine
protected String getLibDirPath()
Machine
getLibDirPath
in class Machine
protected String getLocalConfDirPath()
protected String getLocalLibDirPath()
protected String getLocalInstallDirPath()
protected void createOSLocalKillAllScript(File directory) throws IOFailure
createOSLocalKillAllScript
in class Machine
directory
- The directory for this machine (use global variable?).IOFailure
- If an error occurred during the creation of the local killall script.protected void createOSLocalStartAllScript(File directory) throws IOFailure
createOSLocalStartAllScript
in class Machine
directory
- The directory for this machine (use global variable?).IOFailure
- If an error occurred during the creation of the local startall script.protected void createApplicationKillScripts(File directory) throws IOFailure
kill_ps_app.bat kills the process of the application. kill_app.bat runs kill_ps_app.bat if the application is running. run_app tells if the application is running. It is deleted during kill.
The kill_app.bat should have the following structure:
- ECHO Killing application : app - CD "path" - IF EXIST run_app GOTO KILL - GOTO NOKILL - - :KILL - cmdrun kill_ps_app.bat - DEL run_app - GOTO DONE - - :NOKILL - ECHO Cannot kill application. Already running. - - :DONE
where: app = application name. path = the path to the ./conf directory. cmdrun = the windows command to run other batch programs.
The kill_ps_app.bat is empty upon creation. When the application is started, the command to kill the process of he application is written to this file as the only content. It will look something like this:
- taskkill /F /PID id
where: id = the process identification number of the running application.
TODO kill the potential heritrix process, created by a harvester. Just like on Linux/Unix. If we in the future add the possibility of running heritrix on Windows.
createApplicationKillScripts
in class Machine
directory
- The directory for this machine (use global variable?).IOFailure
- If an error occurred during the creation of the application kill script file.protected void createApplicationStartScripts(File directory)
It creates the batch and the VBscript for starting the application, which are called start_app.bat and start_app.vbs respectively. These files are created in each of their own function.
createApplicationStartScripts
in class Machine
directory
- The directory for this machine (use global variable?).windowsStartBatScript(Application, File)
,
windowsStartVbsScript(Application, File)
protected String osGetClassPath(Application app)
Machine
osGetClassPath
in class Machine
app
- The application which has the class paths.protected void windowsStartBatScript(Application app, File directory) throws IOFailure
The script should be the following:
- echo Starting windows application : app - cd "path" - if exist ".\conf\run_app.txt" goto NOSTART - goto START - - :START - cscript .\conf\start_app.vbs - goto DONE - - :NOSTART - echo Application already running. - - :DONE
where: app = the name of the application. path = the path to the installation directory.
app
- The application to start.directory
- The directory where the script should be placed.IOFailure
- If an error occurred during the creation of the windows start bat script.protected void windowsStartVbsScript(Application app, File directory) throws IOFailure
It should have the following content: - set WshShell = CreateObject("WScript.Shell") - set oExec = WshShell.exec( JAVA ) - set fso = CreateObject("Scripting.FileSystemObject") - set f = fso.OpenTextFile(".\conf\kill_ps_app.bat", 2, True) - f.WriteLine "taskkill /F /PID " & oExec.ProcessID - f.close - 'Create a new start-log for the application - CreateObject("Scripting.FileSystemObject").OpenTextFile(" start_APP.log", 2, True).close - Do While oExec.Status = 0 - WScript.Sleep 1000 - Do While oExec.StdOut.AtEndOfStream <> True - Set outFile = CreateObject("Scripting.FileSystemObject") .OpenTextFile("start_APP.log", 8, True) - outFile.WriteLine oExec.StdOut.ReadLine - outFile.close - Loop - Do While oExec.StdErr.AtEndOfStream <> True - Set outFile = CreateObject("Scripting.FileSystemObject") .OpenTextFile("start_APP.log", 8, True) - outFile.WriteLine oExec.StdErr.ReadLine - outFile.close - Loop - Loop
where: JAVA = the command for starting the java application (very long). app = the name of the application.
app
- The application to start.directory
- The directory where the script should be placed.IOFailure
- If an error occurred during the creation of the windows vb script.protected 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.
osInstallDatabase
in class Machine
protected String osInstallArchiveDatabase()
Checks if a specific directory for the archive database is given in the settings, and thus if the archive database should be installed on this machine.
If not specific database is given (archiveDatabaseFileName = null) then use the default in the NetarchiveSuite.zip package. Else send the new archive database to the standard database location, and extract it to the given location.
osInstallArchiveDatabase
in class Machine
protected String osInstallExternalJarFiles()
Machine
osInstallExternalJarFiles
in class Machine
protected String osInstallScriptCreateDir()
osInstallScriptCreateDir
in class Machine
protected String scriptCreateDir(String dir, boolean clean)
Machine
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.
scriptCreateDir
in class Machine
dir
- The name of the directory to create.clean
- Whether the directory should be cleaned\reset.Machine.createInstallDirScript(File)
protected String createPathToDir(String dir)
dir
- The path to the directory.protected String getAppDirectories()
Machine
getAppDirectories
in class Machine
protected String getMakeDirectoryName()
protected void createInstallDirScript(File directory) throws IOFailure
createInstallDirScript
in class Machine
directory
- The directory to put the file.IOFailure
- If an error occurred during the creation of the install-dir script.protected String changeFileDirPathForSecurity(String path)
Machine
changeFileDirPathForSecurity
in class Machine
path
- The current path.protected String getJMXremoteFilesCommand()
Retrieves the path to the jmxremote.access and jmxremote.password files.
Moves these files, if they are different from standard. This has to be a force move (command 'move /Y').
Makes the jmxremote.access and jmxremote.password files readonly.
getJMXremoteFilesCommand
in class Machine
protected void createRestartScript(File dir) throws IOFailure
First the killall scripts is called, then wait for 5 seconds for the applications to be fully terminated, and finally call the startall script.
The createWaitScript is called through this script to create the wait script which is used by the restart script.
createRestartScript
in class Machine
dir
- The directory where the script file will be placed.IOFailure
- If the restart script cannot be created, or if the wait script cannot be created.protected void createWaitScript(File dir) throws IOFailure
dir
- The directory where the script should be placed.IOFailure
- If the method fails in creating the wait script.protected void createArchiveDatabaseStartScript(File dir)
Machine
createArchiveDatabaseStartScript
in class Machine
dir
- The directory where the script will be placed.protected void createArchiveDatabaseKillScript(File dir)
Machine
createArchiveDatabaseKillScript
in class Machine
dir
- The directory where the script will be placed.protected void createHarvestDatabaseStartScript(File dir)
Machine
createHarvestDatabaseStartScript
in class Machine
dir
- The directory where the script will be placed.protected void createHarvestDatabaseKillScript(File dir)
Machine
createHarvestDatabaseKillScript
in class Machine
dir
- The directory where the script will be placed.protected void createHarvestDatabaseUpdateScript(File machineDirectory, boolean forceCreate)
Machine
createHarvestDatabaseUpdateScript
in class Machine
machineDirectory
- a given MachineDirectory.Copyright © 2005–2016 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.