/
WindowsMachine.java
1318 lines (1218 loc) · 62.8 KB
/
WindowsMachine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* #%L
* Netarchivesuite - deploy
* %%
* Copyright (C) 2005 - 2018 The Royal Danish Library,
* the National Library of France and the Austrian National Library.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package dk.netarkivet.deploy;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import org.dom4j.Element;
import dk.netarkivet.common.exceptions.IOFailure;
/**
* A WindowsMachine is the instance of the abstract machine class, which runs the operating system Windows. This class
* only contains the operating system specific functions.
*/
public class WindowsMachine extends Machine {
/**
* The constructor. Starts by initializing the parent abstract class, then sets the operating system dependent
* variables.
*
* @param root The XML root element.
* @param parentSettings The Settings to be inherited from the PhysicalLocation, where this machine is placed.
* @param param The machine parameters to be inherited from the PhysicalLocation.
* @param netarchiveSuiteSource The name of the NetarchiveSuite package file. Must be '.zip'.
* @param securityPolicy The security policy file, to be copied into machine directory.
* @param dbFile The harvest definition database file.
* @param arcdbFile The archive database.
* @param resetDir Whether the temporary directory should be reset.
* @param externalJarFolder The folder containing the external jar library files.
*/
public WindowsMachine(Element root, XmlStructure parentSettings, Parameters param, String netarchiveSuiteSource,
File slf4JConfig, File securityPolicy, File dbFile, File arcdbFile, boolean resetDir,
File externalJarFolder, File logoFile, File menulogoFile) {
super(root, parentSettings, param, netarchiveSuiteSource, slf4JConfig, securityPolicy, dbFile,
arcdbFile, resetDir, externalJarFolder, logoFile, menulogoFile);
// set operating system
operatingSystem = Constants.OPERATING_SYSTEM_WINDOWS_ATTRIBUTE;
scriptExtension = Constants.SCRIPT_EXTENSION_WINDOWS;
}
/**
* On windows machines console output can cause problems so any uses of ConsoleHandler are
* removed.
*
* @param logProperties the original contents of the logging properties file.
* @return logging properties with the ConsoleHandler removed
*/
/* Is this necessaray with the logback?
@Override
protected String modifyLogProperties(String logProperties) {
String output;
// First delete any instances followed by a comma - ie
// not as last handler
output = logProperties.replaceAll("java.util.logging.ConsoleHandler\\s*,", "");
// Now delete any instances where ConsoleHandler is declared
// last
output = output.replaceAll(",\\s*java.util.logging.ConsoleHandler", "");
return output;
} */
/**
* Creates the operation system specific installation script for this machine.
* <p>
* 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
* <p>
* 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.
* <p>
* $'...' = call other function.
*
* @return Operation system specific part of the installscript
*/
@Override
protected String osInstallScript() {
StringBuilder res = new StringBuilder();
// - echo copying 'NetarchiveSuite.zip' to: 'machine'
res.append(ScriptConstants.ECHO_COPYING + Constants.SPACE);
res.append(netarchiveSuiteFileName);
res.append(Constants.SPACE + ScriptConstants.TO + Constants.COLON + Constants.SPACE);
res.append(hostname);
res.append(Constants.NEWLINE);
// - scp 'NetarchiveSuite.zip' 'login'@'machine':
res.append(ScriptConstants.SCP + Constants.SPACE);
res.append(netarchiveSuiteFileName);
res.append(Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.COLON);
res.append(Constants.NEWLINE);
// echo removing old libraries if they exist.
res.append(ScriptConstants.ECHO_DELETING_OLD_LIBRARIES);
res.append(Constants.NEWLINE);
// ssh 'login'@'machine' cmd /c if exist
// 'environmentName'\\'lib' del /Q 'environmentName'\\'lib'
res.append(ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE + ScriptConstants.IF
+ Constants.SPACE + ScriptConstants.EXIST + Constants.SPACE);
res.append(ScriptConstants.doubleBackslashes(getLocalLibDirPath()) + Constants.SPACE + "DEL /Q"
+ Constants.SPACE);
res.append(ScriptConstants.doubleBackslashes(getLocalLibDirPath()));
res.append(Constants.SPACE + Constants.NEWLINE);
// - echo unzipping 'NetarchiveSuite.zip' at: 'machine'
res.append(ScriptConstants.ECHO_UNZIPPING + Constants.SPACE);
res.append(netarchiveSuiteFileName);
res.append(Constants.SPACE + ScriptConstants.AT + Constants.COLON + Constants.SPACE);
res.append(hostname);
res.append(Constants.NEWLINE);
// - ssh 'login'@'machine' 'unzip' 'environmentName' -o
// 'NetarchiveSuite.zip
res.append(ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_UNZIP_COMMAND + Constants.SPACE);
res.append(getEnvironmentName());
res.append(Constants.SPACE + ScriptConstants.SCRIPT_OUTPUT + Constants.SPACE);
res.append(netarchiveSuiteFileName);
res.append(Constants.NEWLINE);
// - $'create directories'.
res.append(osInstallScriptCreateDir());
// - echo preparing for copying of settings and scripts
res.append(ScriptConstants.ECHO_PREPARING_FOR_COPY);
res.append(Constants.NEWLINE);
// - if [ $( ssh 'login'@'machine' cmd /c if exist
// 'environmentName'\\'jmxremote.password' echo 1 ) ]; then echo Y
// | ssh 'login'@'machine' cmd /c cacls
// 'environmentName'\\'jmxremote.password' /P BITARKIV\\'login':F; fi
res.append(ScriptConstants.IF + Constants.SPACE + Constants.SQUARE_BRACKET_BEGIN + Constants.SPACE
+ Constants.DOLLAR_SIGN + Constants.BRACKET_BEGIN + Constants.SPACE + ScriptConstants.SSH
+ Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE + ScriptConstants.IF
+ Constants.SPACE + ScriptConstants.EXIST + Constants.SPACE);
res.append(ScriptConstants.doubleBackslashes(getLocalConfDirPath()));
res.append(Constants.JMX_PASSWORD_FILE_NAME);
res.append(Constants.SPACE + ScriptConstants.ECHO_ONE);
res.append(Constants.SPACE + Constants.BRACKET_END + Constants.SPACE + Constants.SQUARE_BRACKET_END
+ Constants.SEMICOLON + Constants.SPACE + ScriptConstants.THEN + Constants.SPACE);
res.append(ScriptConstants.ECHO_Y + Constants.SPACE + Constants.SEPARATOR + Constants.SPACE
+ ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE + ScriptConstants.CACLS
+ Constants.SPACE);
res.append(ScriptConstants.doubleBackslashes(getLocalConfDirPath()));
res.append(Constants.JMX_PASSWORD_FILE_NAME + Constants.SPACE + ScriptConstants.SLASH_P + Constants.SPACE
+ ScriptConstants.BITARKIV_BACKSLASH_BACKSLASH);
res.append(machineParameters.getMachineUserName().getText().trim());
res.append(ScriptConstants.COLON_F + Constants.SEMICOLON + Constants.SPACE + ScriptConstants.FI
+ Constants.SEMICOLON);
res.append(Constants.NEWLINE);
// - if [ $( ssh 'login'@'machine' cmd /c if exist
// 'environmentName'\\'jmxremote.access' echo 1 ) ]; then echo Y
// | ssh 'login'@'machine' cmd /c cacls
// 'environmentName'\\'jmxremote.access' /P BITARKIV\\'login':F; fi
res.append(ScriptConstants.IF + Constants.SPACE + Constants.SQUARE_BRACKET_BEGIN + Constants.SPACE
+ Constants.DOLLAR_SIGN + Constants.BRACKET_BEGIN + Constants.SPACE + ScriptConstants.SSH
+ Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE + ScriptConstants.IF
+ Constants.SPACE + ScriptConstants.EXIST + Constants.SPACE);
res.append(ScriptConstants.doubleBackslashes(getLocalConfDirPath()));
res.append(Constants.JMX_ACCESS_FILE_NAME);
res.append(Constants.SPACE + ScriptConstants.ECHO_ONE);
res.append(Constants.SPACE + Constants.BRACKET_END + Constants.SPACE + Constants.SQUARE_BRACKET_END
+ Constants.SEMICOLON + Constants.SPACE + ScriptConstants.THEN + Constants.SPACE
+ ScriptConstants.ECHO_Y + Constants.SPACE);
res.append(Constants.SEPARATOR + Constants.SPACE + ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE + ScriptConstants.CACLS
+ Constants.SPACE);
res.append(ScriptConstants.doubleBackslashes(getLocalConfDirPath()));
res.append(Constants.JMX_ACCESS_FILE_NAME + Constants.SPACE + ScriptConstants.SLASH_P + Constants.SPACE
+ ScriptConstants.BITARKIV_BACKSLASH_BACKSLASH);
res.append(machineParameters.getMachineUserName().getText().trim());
res.append(ScriptConstants.COLON_F + Constants.SEMICOLON + Constants.SPACE + ScriptConstants.FI
+ Constants.SEMICOLON);
res.append(Constants.NEWLINE);
// - echo copying settings and scripts
res.append(ScriptConstants.ECHO_COPY_SETTINGS_AND_SCRIPTS);
res.append(Constants.NEWLINE);
// - scp -r 'machine'/* 'login'@'machine':'environmentName'\\conf\\
res.append(ScriptConstants.SCP + Constants.SPACE + ScriptConstants.DASH_R + Constants.SPACE);
res.append(hostname);
res.append(Constants.SLASH + Constants.STAR + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.COLON);
res.append(ScriptConstants.doubleBackslashes(getLocalConfDirPath()));
res.append(Constants.NEWLINE);
// INSTALL EXTERNAL JAR FILES.
res.append(osInstallExternalJarFiles());
// APPLY DATABASE!
res.append(osInstallDatabase());
// APPLY ARCHIVE DATABASE!
res.append(osInstallArchiveDatabase());
// HANDLE JMXREMOTE PASSWORD AND ACCESS FILE.
res.append(getJMXremoteFilesCommand());
// END OF SCRIPT
return res.toString();
}
/**
* Creates the operation system specific killing script for this machine.
* <p>
* pseudocode: - ssh 'login'@'machine' cmd /c 'environmentName'\\conf\\killall.bat
* <p>
* variables: 'login' = machine user name 'machine' = name of the machine 'environmentName' = the environmentName
* from configuration.
*
* @return Operation system specific part of the killscript.
*/
@Override
protected String osKillScript() {
StringBuilder res = new StringBuilder();
res.append(ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + Constants.QUOTE_MARK + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE
+ Constants.SPACE);
res.append(getLocalConfDirPath());
res.append(Constants.SCRIPT_NAME_KILL_ALL);
res.append(scriptExtension);
res.append(Constants.SPACE + Constants.QUOTE_MARK + Constants.SPACE);
res.append(Constants.NEWLINE);
return res.toString();
}
/**
* Creates the operation system specific starting script for this machine.
* <p>
* pseudocode: - ssh 'login'@'machine' cmd /c 'environmentName'\\conf\\startall.bat - sleep 5 - ssh
* 'login'@'machine' "more 'environmentName'\\start_APP.log
* <p>
* variables: 'login' = machine user name 'machine' = name of the machine 'environmentName' = the environmentName
* from configuration.
*
* @return Operation system specific part of the startscript.
*/
@Override
protected String osStartScript() {
StringBuilder res = new StringBuilder();
// - ssh 'login'@'machine' cmd /c 'environmentName'\\conf\\startall.bat
res.append(ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + Constants.QUOTE_MARK + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE
+ Constants.SPACE);
res.append(getLocalConfDirPath());
res.append(Constants.SCRIPT_NAME_START_ALL);
res.append(scriptExtension);
res.append(Constants.SPACE + Constants.QUOTE_MARK + Constants.SPACE);
res.append(Constants.NEWLINE);
// - sleep 5
res.append(ScriptConstants.SLEEP_5);
res.append(Constants.NEWLINE);
// - ssh 'login'@'machine' "more 'environmentName'\\start_APP.log"
for (Application app : applications) {
res.append(ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + Constants.QUOTE_MARK + ScriptConstants.WINDOWS_COMMAND_TYPE + Constants.SPACE);
res.append(getEnvironmentName() + Constants.BACKSLASH + Constants.SCRIPT_NAME_LOCAL_START
+ app.getIdentification() + Constants.EXTENSION_LOG_FILES);
res.append(Constants.QUOTE_MARK + Constants.SPACE);
res.append(Constants.NEWLINE);
}
return res.toString();
}
@Override
protected String getInstallDirPath() {
return machineParameters.getInstallDirValue() + Constants.BACKSLASH + getEnvironmentName();
}
@Override
protected String getConfDirPath() {
return getInstallDirPath() + Constants.CONF_DIR_WINDOWS;
}
@Override
protected String getLibDirPath() {
return getInstallDirPath() + Constants.LIB_DIR_WINDOWS;
}
/**
* Creates the local path to the conf dir.
*
* @return The path to the conf dir for ssh.
*/
protected String getLocalConfDirPath() {
return getEnvironmentName() + Constants.CONF_DIR_WINDOWS;
}
/**
* Creates the local path to the lib dir.
*
* @return The path to the lib dir for ssh.
*/
protected String getLocalLibDirPath() {
return getEnvironmentName() + Constants.LIB_DIR_WINDOWS;
}
/**
* Creates the local path to the installation directory.
*
* @return The path to the installation directory for ssh.
*/
protected String getLocalInstallDirPath() {
return getEnvironmentName() + Constants.BACKSLASH;
}
/**
* This function creates the script to kill all applications on this machine. The scripts calls all the kill script
* for each application.
*
* @param directory The directory for this machine (use global variable?).
* @throws IOFailure If an error occurred during the creation of the local killall script.
*/
@Override
protected void createOSLocalKillAllScript(File directory) throws IOFailure {
// create the kill all script file
File killAllScript = new File(directory, Constants.SCRIPT_NAME_KILL_ALL + scriptExtension);
try {
// Initialise script
PrintWriter killPrinter = new PrintWriter(killAllScript, getTargetEncoding());
try {
killPrinter.println(ScriptConstants.ECHO_KILL_ALL_APPS + Constants.COLON + Constants.SPACE
+ Constants.APOSTROPHE + hostname + Constants.APOSTROPHE);
killPrinter.println(ScriptConstants.CD + Constants.SPACE + Constants.QUOTE_MARK + getConfDirPath()
+ Constants.QUOTE_MARK);
// insert path to kill script for all applications
for (Application app : applications) {
// make name of file
String appScript = Constants.SCRIPT_NAME_LOCAL_KILL + app.getIdentification() + scriptExtension;
killPrinter.print(ScriptConstants.OPERATING_SYSTEM_WINDOWS_RUN_BATCH_FILE);
killPrinter.print(Constants.QUOTE_MARK);
killPrinter.print(appScript);
killPrinter.print(Constants.QUOTE_MARK);
killPrinter.println();
}
// Add 10 seconds timeout to allow the shutdown to complete before exiting the ssh connection
killPrinter.print(ScriptConstants.OPERATING_SYSTEM_WINDOWS_10_SECONDS_WAIT);
killPrinter.println();
} finally {
// close script
killPrinter.close();
}
} catch (IOException e) {
String msg = "Problems creating local kill all script. ";
log.trace(msg, e);
throw new IOFailure(msg, e);
}
}
/**
* This function creates the script to start all applications on this machine. The scripts calls all the start
* script for each application.
*
* @param directory The directory for this machine (use global variable?).
* @throws IOFailure If an error occurred during the creation of the local startall script.
*/
@Override
protected void createOSLocalStartAllScript(File directory) throws IOFailure {
// create the start all script file
File startAllScript = new File(directory, Constants.SCRIPT_NAME_START_ALL + scriptExtension);
try {
// Initialise script
PrintWriter startPrinter = new PrintWriter(startAllScript, getTargetEncoding());
try {
startPrinter.println(ScriptConstants.ECHO_START_ALL_APPS + Constants.COLON + Constants.SPACE
+ Constants.APOSTROPHE + hostname + Constants.APOSTROPHE);
startPrinter.println(ScriptConstants.CD + Constants.SPACE + Constants.QUOTE_MARK + getConfDirPath()
+ Constants.QUOTE_MARK);
// insert path to kill script for all applications
for (Application app : applications) {
// make name of file
String appScript = Constants.SCRIPT_NAME_LOCAL_START + app.getIdentification() + scriptExtension;
startPrinter.print(ScriptConstants.OPERATING_SYSTEM_WINDOWS_RUN_BATCH_FILE);
startPrinter.print(Constants.QUOTE_MARK);
startPrinter.print(appScript);
startPrinter.print(Constants.QUOTE_MARK);
startPrinter.println();
}
// Add 10 seconds timeout to allow the Starting to complete before exiting the ssh connection
startPrinter.print(ScriptConstants.OPERATING_SYSTEM_WINDOWS_10_SECONDS_WAIT);
startPrinter.println();
} finally {
// close script
startPrinter.close();
}
} catch (IOException e) {
String msg = "Problems during creation of the local start " + "all script.";
log.trace(msg, e);
throw new IOFailure(msg, e);
}
}
/**
* Creates the kill scripts for all the applications. Two script files are created: kill_app.bat and
* kill_ps_app.bat.
* <p>
* 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.
* <p>
* The kill_app.bat should have the following structure:
* <p>
* - 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
* <p>
* where: app = application name. path = the path to the ./conf directory. cmdrun = the windows command to run other
* batch programs.
* <p>
* 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:
* <p>
* - taskkill /F /PID id
* <p>
* where: id = the process identification number of the running application.
* <p>
* 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.
*
* @param directory The directory for this machine (use global variable?).
* @throws IOFailure If an error occurred during the creation of the application kill script file.
*/
@Override
protected void createApplicationKillScripts(File directory) throws IOFailure {
// go through all applications and create their kill script
for (Application app : applications) {
String id = app.getIdentification();
String killPsName = Constants.SCRIPT_KILL_PS + id + scriptExtension;
File appKillScript = new File(directory, Constants.SCRIPT_NAME_LOCAL_KILL + id + scriptExtension);
File appKillPsScript = new File(directory, killPsName);
try {
// make print writer for writing to file
PrintWriter appPrint = new PrintWriter(appKillScript, getTargetEncoding());
try {
// initiate variables
String tmpRunApp = Constants.FILE_TEMPORARY_RUN_WINDOWS_NAME + id;
// get the content for the kill script of
// this application
// #echo kill windows application
appPrint.println(ScriptConstants.ECHO_KILL_WINDOWS_APPLICATION + Constants.COLON + Constants.SPACE
+ id);
// cd "path"
appPrint.println(ScriptConstants.CD + Constants.SPACE + Constants.QUOTE_MARK
+ app.installPathWindows() + Constants.CONF_DIR_WINDOWS + Constants.QUOTE_MARK);
// if exist run_app.txt GOTO KILL
appPrint.println(ScriptConstants.IF + Constants.SPACE + ScriptConstants.EXIST + Constants.SPACE
+ tmpRunApp + Constants.SPACE + ScriptConstants.GOTO + Constants.SPACE
+ ScriptConstants.LABEL_KILL);
// GOTO NOKILL
appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_NOKILL);
//
appPrint.println();
// :KILL
appPrint.println(Constants.COLON + ScriptConstants.LABEL_KILL);
// cmdrun kill_ps_app.bat
appPrint.println(ScriptConstants.OPERATING_SYSTEM_WINDOWS_RUN_BATCH_FILE + Constants.QUOTE_MARK
+ killPsName + Constants.QUOTE_MARK);
// del run_app.txt
appPrint.println(ScriptConstants.DEL + Constants.SPACE + tmpRunApp);
// GOTO DONE
appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_DONE);
//
appPrint.println();
// :NOKILL
appPrint.println(Constants.COLON + ScriptConstants.LABEL_NOKILL);
// echo Cannot kill application. Already running.
appPrint.println(ScriptConstants.ECHO_CANNOT_KILL_APP);
//
appPrint.println();
// :DONE
appPrint.println(Constants.COLON + ScriptConstants.LABEL_DONE);
} finally {
// close file
appPrint.close();
}
// Printer for making the kill process file.
PrintWriter appPsPrint = new PrintWriter(appKillPsScript, getTargetEncoding());
try {
// write dummy line in kill script.
appPsPrint.println("ECHO Not started!");
} finally {
// close file
appPsPrint.close();
}
} catch (IOException e) {
String msg = "Cannot create the kill script for " + "application: " + app.getIdentification()
+ ", at machine: '" + hostname + "'";
log.trace(msg, e);
throw new IOFailure(msg, e);
}
}
}
/**
* Creates the start scripts for all the applications.
* <p>
* 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.
*
* @param directory The directory for this machine (use global variable?).
* @see #windowsStartBatScript(Application, File)
* @see #windowsStartVbsScript(Application, File)
*/
@Override
protected void createApplicationStartScripts(File directory) {
// go through all applications and create their start script
for (Application app : applications) {
windowsStartBatScript(app, directory);
windowsStartVbsScript(app, directory);
}
}
@Override
protected String osGetClassPath(Application app) {
StringBuilder res = new StringBuilder();
// get all the classpaths (change from '\' to '\\')
for (Element cp : app.getMachineParameters().getClassPaths()) {
// insert the path to the install directory
res.append(ScriptConstants.doubleBackslashes(getInstallDirPath()));
res.append(Constants.BACKSLASH + Constants.BACKSLASH);
// Then insert the class path.
res.append(ScriptConstants.replaceWindowsDirSeparators(cp.getText()));
res.append(Constants.SEMICOLON);
}
return res.toString();
}
/**
* Creates the batch script for starting the application. It checks if the application is running and starts the
* application if it is not the case. The application is started by calling the start_app.vbs.
* <p>
* The script should be the following:
* <p>
* - 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
* <p>
* where: app = the name of the application. path = the path to the installation directory.
*
* @param app The application to start.
* @param directory The directory where the script should be placed.
* @throws IOFailure If an error occurred during the creation of the windows start bat script.
*/
protected void windowsStartBatScript(Application app, File directory) throws IOFailure {
File appStartScript = new File(directory, Constants.SCRIPT_NAME_LOCAL_START + app.getIdentification()
+ scriptExtension);
try {
// make print writer for writing to file
PrintWriter appPrint = new PrintWriter(appStartScript, getTargetEncoding());
try {
// initiate variables
String id = app.getIdentification();
String tmpRunApp = Constants.FILE_TEMPORARY_RUN_WINDOWS_NAME + id;
// cd "path"
appPrint.println(ScriptConstants.CD + Constants.SPACE + Constants.QUOTE_MARK + app.installPathWindows()
+ Constants.QUOTE_MARK);
// if exist .\conf\run_app.txt GOTO NOSTART
appPrint.println(ScriptConstants.IF + Constants.SPACE + ScriptConstants.EXIST + Constants.SPACE
+ Constants.DOT + Constants.CONF_DIR_WINDOWS + tmpRunApp + Constants.SPACE
+ ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_NOSTART);
// GOTO START
appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_START);
//
appPrint.println();
// :START
appPrint.println(Constants.COLON + ScriptConstants.LABEL_START);
// cscript .\conf\start_app.vbs
appPrint.println(ScriptConstants.CSCRIPT + Constants.SPACE + Constants.DOT + Constants.CONF_DIR_WINDOWS
+ Constants.SCRIPT_NAME_LOCAL_START + id + Constants.EXTENSION_VBS_FILES);
// GOTO DONE
appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_DONE);
//
appPrint.println();
// :NOSTART
appPrint.println(Constants.COLON + ScriptConstants.LABEL_NOSTART);
// echo Cannot start. Application already running.
appPrint.println(ScriptConstants.ECHO_CANNOT_START_APP);
//
appPrint.println();
// :DONE
appPrint.println(Constants.COLON + ScriptConstants.LABEL_DONE);
} finally {
// close file
appPrint.close();
}
} catch (IOException e) {
String msg = "Cannot create the start script for application: " + app.getIdentification()
+ ", at machine: '" + hostname + "'";
log.trace(msg, e);
throw new IOFailure(msg, e);
}
}
protected static final class windowsStartVbsScriptTpl {
protected static final String[] mainScript = {
"Set WshShell= CreateObject(\"WScript.Shell\")",
"javahome = WshShell.ExpandEnvironmentStrings(\"%JAVA_HOME%\")",
"WScript.Echo \"JAVA_HOME=\" & javahome",
"If javahome = \"%JAVA_HOME%\" Then",
" java = \"java\"",
"Else",
" java = javahome & \"\\bin\\java\"",
"End If",
"Set oExec = WshShell.exec(\"\"\"java\"\"\" & \" ${machineparameters} -classpath \"\"${classpath}\"\""
+ " -Ddk.netarkivet.settings.file=\"\"${confdirpath}settings_${id}.xml\"\""
+ "${slf4jlogger}" + "${securityManagement}" + " ${appname}" + "\")",
"Set fso= CreateObject(\"Scripting.FileSystemObject\")",
"Set f=fso.OpenTextFile(\".\\conf\\${killpsname}\",2,True)",
"f.WriteLine \"taskkill /F /PID \" & oExec.ProcessID",
"f.close",
"Set tf=fso.OpenTextFile(\".\\conf\\${tmprunpsname}\",8,True)",
"tf.WriteLine \"running process: \" & oExec.ProcessID",
"tf.close",
"'Create a new start-log for the application",
"CreateObject(\"Scripting.FileSystemObject\").OpenTextFile(\"${startlogname}\", 2, True).close",
"Do While oExec.Status = 0 Or oExec.StdOut.AtEndOfStream <> True Or oExec.StdErr.AtEndOfStream <> True",
" WScript.Sleep 1000",
" Do While oExec.StdOut.AtEndOfStream <> True",
" Set outFile = CreateObject(\"Scripting.FileSystemObject\").OpenTextFile(\"${startlogname}\", 8, True)",
" outFile.WriteLine oExec.StdOut.ReadLine",
" outFile.close",
" Loop",
" Do While oExec.StdErr.AtEndOfStream <> True",
" Set outFile = CreateObject(\"Scripting.FileSystemObject\").OpenTextFile(\"${startlogname}\", 8, True)",
" outFile.WriteLine oExec.StdErr.ReadLine", " outFile.close", " Loop", "Loop"};
protected static final String slf4jLogger = " -Dlogback.configurationFile=\"\"${confdirpath}logback_${id}.xml\"\"";
protected static final String securityManagement = " -Djava.security.manager -Djava.security.policy=\"\"${confdirpath}security.policy\"\"";
}
/**
* This function creates the VBscript to start the application. It calls a command for executing the java
* application, then it writes the way to kill the process in the kill_ps_app.bat and finally it creates the
* run-file.
* <p>
* 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
* <p>
* where: JAVA = the command for starting the java application (very long). app = the name of the application.
*
* @param app The application to start.
* @param directory The directory where the script should be placed.
* @throws IOFailure If an error occurred during the creation of the windows vb script.
*/
protected void windowsStartVbsScript(Application app, File directory) throws IOFailure {
File appStartSupportScript = new File(directory, Constants.SCRIPT_NAME_LOCAL_START + app.getIdentification()
+ Constants.EXTENSION_VBS_FILES);
try {
// make print writer for writing to file
PrintWriter vbsPrint = new PrintWriter(appStartSupportScript, getTargetEncoding());
try {
// initiate variables
String id = app.getIdentification();
String killPsName = Constants.SCRIPT_KILL_PS + id + scriptExtension;
String tmpRunPsName = Constants.FILE_TEMPORARY_RUN_WINDOWS_NAME + id;
String startLogName = Constants.SCRIPT_NAME_LOCAL_START + id + Constants.EXTENSION_LOG_FILES;
Map<String, String> env = new HashMap<String, String>();
env.put("machineparameters", app.getMachineParameters().writeJavaOptions());
env.put("classpath", osGetClassPath(app));
env.put("confdirpath", ScriptConstants.doubleBackslashes(getConfDirPath()));
env.put("id", id);
env.put("appname", app.getTotalName());
env.put("killpsname", killPsName);
env.put("tmprunpsname", tmpRunPsName);
env.put("startlogname", startLogName);
if (inheritedSlf4jConfigFile != null) {
env.put("slf4jlogger", Template.untemplate(windowsStartVbsScriptTpl.slf4jLogger, env, true));
} else {
env.put("slf4jlogger", "");
}
if (app.getTotalName().contains(ScriptConstants.BITARCHIVE_APPLICATION_NAME)) {
env.put("securityManagement",
Template.untemplate(windowsStartVbsScriptTpl.securityManagement, env, true));
} else {
env.put("securityManagement", "");
}
String str = Template.untemplate(windowsStartVbsScriptTpl.mainScript, env, true, "\r\n");
vbsPrint.print(str);
} finally {
// close file
vbsPrint.close();
}
} catch (IOException e) {
String msg = "Cannot create the start script for application: " + app.getIdentification()
+ ", at machine: '" + hostname + "'";
log.trace(msg, e);
throw new IOFailure(msg, e);
}
}
/**
* THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX!
* <p>
* Checks if a specific directory for the database is given in the settings, and thus if the database should be
* installed on this machine.
* <p>
* 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.
* <p>
* Extract the database in the standard database location to the specified database directory.
*
* @return The script for installing the database (if needed).
*/
@Override
protected String osInstallDatabase() {
String databaseDir = machineParameters.getHarvestDatabaseDirValue();
// Do not install if no proper database directory.
if (databaseDir == null || databaseDir.isEmpty()) {
return Constants.EMPTY;
}
StringBuilder res = new StringBuilder(ScriptConstants.ECHO_WINDOWS_DATABASE);
res.append(Constants.NEWLINE);
return res.toString();
}
/**
* THIS HAS NOT BEEN IMPLEMENTED FOR WINDOWS YET - ONLY LINUX!
* <p>
* 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.
* <p>
* 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.
*
* @return The script for installing the archive database (if needed).
*/
@Override
protected String osInstallArchiveDatabase() {
String bpDatabaseDir = machineParameters.getArchiveDatabaseDirValue();
// Do not install if no proper archive database directory.
if (bpDatabaseDir == null || bpDatabaseDir.isEmpty()) {
return Constants.EMPTY;
}
StringBuilder res = new StringBuilder(ScriptConstants.ECHO_WINDOWS_DATABASE);
res.append(Constants.NEWLINE);
return res.toString();
}
@Override
protected String osInstallExternalJarFiles() {
if (jarFolder == null) {
return Constants.EMPTY;
}
StringBuilder res = new StringBuilder();
// Comment about copying files.
res.append(ScriptConstants.ECHO_INSTALLING_EXTERNAL_JAR_FILES);
res.append(Constants.NEWLINE);
// if [ -d folder ]; then ssh machine "md installdir/external";
// scp folder/* machine:installdir/external; fi;
res.append(ScriptConstants.LINUX_IF_DIR_EXIST + Constants.SPACE);
res.append(jarFolder.getPath());
res.append(Constants.SPACE + ScriptConstants.LINUX_THEN + Constants.SPACE);
res.append(ScriptConstants.SSH + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.MD + Constants.SPACE + Constants.QUOTE_MARK);
res.append(ScriptConstants.doubleBackslashes(getInstallDirPath()));
res.append(Constants.BACKSLASH + Constants.BACKSLASH + Constants.EXTERNAL_JAR_DIRECTORY + Constants.QUOTE_MARK
+ Constants.SEMICOLON);
res.append(Constants.SPACE + ScriptConstants.SCP + Constants.SPACE + ScriptConstants.DASH_R + Constants.SPACE);
res.append(jarFolder.getPath());
res.append(Constants.SLASH + Constants.STAR);
res.append(Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.COLON + Constants.QUOTE_MARK);
res.append(ScriptConstants.doubleBackslashes(getInstallDirPath()));
res.append(Constants.BACKSLASH + Constants.BACKSLASH + Constants.EXTERNAL_JAR_DIRECTORY + Constants.QUOTE_MARK);
res.append(Constants.SEMICOLON + Constants.SPACE + ScriptConstants.FI + Constants.SEMICOLON);
res.append(Constants.NEWLINE);
return res.toString();
}
/**
* Creates the specified directories in the deploy config file.
*
* @return The script for creating the directories.
*/
@Override
protected String osInstallScriptCreateDir() {
StringBuilder res = new StringBuilder();
res.append(ScriptConstants.ECHO_CREATING_DIRECTORIES);
res.append(Constants.NEWLINE);
// send script to machine
res.append(ScriptConstants.SCP + Constants.SPACE);
res.append(getMakeDirectoryName());
res.append(Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.COLON);
res.append(Constants.NEWLINE);
// run script
res.append(ScriptConstants.SSH + Constants.SPACE + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE);
res.append(getMakeDirectoryName());
res.append(Constants.NEWLINE);
// delete script
res.append(ScriptConstants.SSH + Constants.SPACE + Constants.SPACE);
res.append(machineUserLogin());
res.append(Constants.SPACE + ScriptConstants.WINDOWS_COMMAND_RUN + Constants.SPACE + ScriptConstants.DEL
+ Constants.SPACE);
res.append(getMakeDirectoryName());
res.append(Constants.NEWLINE);
return res.toString();
}
@Override
protected String scriptCreateDir(String dir, boolean clean) {
StringBuilder res = new StringBuilder();
if (clean) {
res.append(ScriptConstants.IF + Constants.SPACE + ScriptConstants.EXIST + Constants.SPACE);
res.append(dir);
res.append(Constants.SPACE + ScriptConstants.RD + Constants.SPACE);
res.append(dir);
res.append(Constants.NEWLINE);
}
res.append(ScriptConstants.IF + Constants.SPACE + ScriptConstants.NOT + Constants.SPACE + ScriptConstants.EXIST
+ Constants.SPACE);
res.append(dir);
res.append(Constants.SPACE + ScriptConstants.MD + Constants.SPACE);
res.append(dir);
res.append(Constants.NEWLINE);
return res.toString();
}
/**
* Function for creating the directories along the path until the end directory. Does not create the end directory.
*
* @param dir The path to the directory.
* @return The script for creating the directory.
*/
protected String createPathToDir(String dir) {
StringBuilder res = new StringBuilder();
String[] pathDirs = dir.split(Constants.REGEX_BACKSLASH_CHARACTER);
StringBuilder path = new StringBuilder();
// only make directories along path to last directory,
// don't create end directory.
for (int i = 0; i < pathDirs.length - 1; i++) {
// don't make directory of empty path.
if (!pathDirs[i].isEmpty()) {
path.append(pathDirs[i]);
if (!path.substring(path.length() - 1).endsWith(Constants.COLON)) {
res.append(scriptCreateDir(path.toString(), false));
}
}
path.append(Constants.BACKSLASH);
}
return res.toString();
}
@Override
protected String getAppDirectories() {
StringBuilder res = new StringBuilder();
String[] dirs;
for (Application app : applications) {
// get archive.fileDir directories.
dirs = app.getSettingsValues(Constants.SETTINGS_BITARCHIVE_BASEFILEDIR_LEAF);
if (dirs != null && dirs.length > 0) {
for (String dir : dirs) {
res.append(createPathToDir(dir));
res.append(scriptCreateDir(dir, false));
for (String subdir : Constants.BASEFILEDIR_SUBDIRECTORIES) {
res.append(scriptCreateDir(dir + Constants.BACKSLASH + subdir, false));
}
}
}
// get harvester.harvesting.serverDir directories.
dirs = app.getSettingsValues(Constants.SETTINGS_HARVEST_SERVERDIR_LEAF);
if (dirs != null && dirs.length > 0) {
for (String dir : dirs) {
res.append(createPathToDir(dir));
res.append(scriptCreateDir(dir, false));
}
}
// get the viewerproxy.baseDir directories.
dirs = app.getSettingsValues(Constants.SETTINGS_VIEWERPROXY_BASEDIR_LEAF);
if (dirs != null && dirs.length > 0) {
for (String dir : dirs) {
res.append(createPathToDir(dir));
res.append(scriptCreateDir(dir, false));
}
}
// get the common.tempDir directories. But only those,
// which are not the same as the machine common.tempDir.
dirs = app.getSettingsValues(Constants.SETTINGS_TEMPDIR_LEAF);
if (dirs != null && dirs.length > 0) {
String machineDir = settings.getLeafValue(Constants.SETTINGS_TEMPDIR_LEAF);
for (String dir : dirs) {
// Don't make machine temp dir twice.
if (!dir.equals(machineDir)) {
res.append(createPathToDir(dir));
res.append(scriptCreateDir(dir, resetTempDir));
}
}
}
}
return res.toString();
}
/**
* Creates the name for the make dir script.
*
* @return The name of the script for creating the directories.
*/
protected String getMakeDirectoryName() {
return Constants.WINDOWS_DIR_CREATE_PREFIX + hostname + scriptExtension;
}
/**
* Function to create the script which installs the new directories. This is only used for windows machines!
*
* @param directory The directory to put the file.
* @throws IOFailure If an error occurred during the creation of the install-dir script.
*/
@Override
protected void createInstallDirScript(File directory) throws IOFailure {
File dirScript = new File(directory, getMakeDirectoryName());
try {
// make print writer for writing to file
PrintWriter dirPrint = new PrintWriter(dirScript, getTargetEncoding());
try {
// go to correct directory
dirPrint.print(ScriptConstants.CD + Constants.SPACE);
dirPrint.print(getInstallDirPath());
dirPrint.print(Constants.NEWLINE);
// go through all directories.
String dir;
// get archive.bitpresevation.baseDir directory.
dir = settings.getLeafValue(Constants.SETTINGS_ARCHIVE_BP_BASEDIR_LEAF);