source: greenstone3/trunk/src/java/org/greenstone/server/Server2.java@ 18770

Last change on this file since 18770 was 18770, checked in by ak19, 15 years ago

On error, the correct location of the logs folder needs to be displayed which is different between GS2 and GS3, so this is set by the subclass constructors.

File size: 4.6 KB
Line 
1
2package org.greenstone.server;
3
4import java.io.File;
5import java.io.FileInputStream;
6import java.io.FileOutputStream;
7import java.util.Properties;
8
9import org.apache.log4j.*;
10
11import org.greenstone.server.BaseServer;
12import org.greenstone.server.BaseProperty;
13
14public class Server2 extends BaseServer
15{
16 protected String libraryURL;
17
18 public Server2(String gsdl2_home, String lang)
19 {
20 super(gsdl2_home, lang,
21 gsdl2_home+File.separator+"lib"+File.separator+"java"+File.separator+"build.properties",
22 "etc"+File.separator+"logs-gsi");
23
24 Property = new Server2Property();
25
26 String frame_title = dictionary.get("ServerControl.Frame_Title");
27 server_control_ = new Server2Control(this,frame_title);
28
29 /** Make command tagets for managing Web server */
30 START_CMD = "web-start";
31 RESTART_CMD = "web-restart";
32 CONFIGURE_CMD = "configure-web";
33 STOP_CMD = "web-stop";
34
35 autoStart();
36 }
37
38 // Prepare the log4j.properties for GS2
39 protected void initLogger() {
40
41 String libjavaFolder = gsdl_home+File.separator+"lib"+File.separator+"java"+File.separator;
42 File propsFile = new File(libjavaFolder+"log4j.properties");
43
44 // create it from the template file log4j.properties.in
45 if(!propsFile.exists()) {
46 try {
47 // need to set gsdl2.home property's value to be gsdl_home,
48 // so that the location of the log files gets resolved correctly
49
50 // load the template log4j.properties.in file into logProps
51 FileInputStream infile = new FileInputStream(new File(libjavaFolder+"log4j.properties.in"));
52 if(infile != null) {
53 Properties logProps = new Properties();
54 logProps.load(infile);
55 infile.close();
56
57 // set gsdl3.home to gsdl_home
58 logProps.setProperty("gsdl2.home", gsdl_home);
59
60 // write the customised properties out to a custom log4j.properties file
61 FileOutputStream outfile = new FileOutputStream(propsFile);
62 if(outfile != null) {
63 logProps.store(outfile, "Customised log4j.properties file");
64 outfile.close();
65 } else {
66 System.err.println("Could not store properties file " + propsFile + " for Server2.");
67 }
68 }
69 } catch(Exception e) {
70 System.err.println("Exception occurred when custom-configuring the logger for Server2.\n" + e);
71 }
72 }
73
74 // now configure the logger with the custom log4j.properties file
75 if(propsFile.exists()) {
76 PropertyConfigurator.configure(propsFile.getAbsolutePath());
77 } else {
78 System.err.println("Could not create properties file " + propsFile + " for Server2.");
79 }
80 }
81
82
83 protected int runTarget(String cmd)
84 {
85 RunMake runMake = new RunMake();
86 runMake.setTargetCmd(cmd);
87 runMake.run();
88 return runMake.getTargetState();
89 }
90
91 public String getBrowserURL() {
92 return libraryURL;
93 }
94
95 // works out the library URL again
96 public void reload() {
97 // default values, to be replaced with what's in gsdlsite.cfg
98 String host = "localhost";
99 String port = "8080";
100 String gwcgi;
101 String httpprefix = "greenstone";
102 String suffix = "/cgi-bin/library.cgi";
103
104 // get the prefix from the gsdlsite.cfg and build.properties files
105 // (port number and servername)
106 try{
107 File gsdlsite_cfg = new File(gsdl_home + File.separator + "cgi-bin" + File.separator + "gsdlsite.cfg");
108 FileInputStream fin = new FileInputStream(gsdlsite_cfg);
109 Properties gsdlProperties = new Properties();
110 if(fin != null) {
111 gsdlProperties.load(fin);
112
113 gwcgi = gsdlProperties.getProperty("gwcgi");
114 if(gwcgi != null) {
115 suffix = gwcgi;
116 } else {
117 httpprefix = gsdlProperties.getProperty("httpprefix", httpprefix);
118 suffix = httpprefix + suffix;
119 }
120 fin.close();
121 } else {
122 recordError("Could not open gsdlsite_cfg for reading, using default library prefix.");
123 }
124 reloadBuildProperties();
125 host = build_properties.getProperty("apache.server", host);
126 port = build_properties.getProperty("apache.port", port);
127
128 } catch(Exception e) {
129 recordError("Exception trying to load properties from gsdlsite_cfg. Using default library prefix.", e);
130 suffix = httpprefix + suffix;
131 }
132
133 libraryURL = "http://" + host + ":" + port + suffix;
134 //recordSuccess("**** browser URL is: " + libraryURL);
135
136 }
137
138
139 public static void main (String[] args)
140 {
141 if ((args.length < 1) || (args.length>2)) {
142 System.err.println("Usage: java org.greenstone.server.Server2 <gsdl2-home-dir> [lang]");
143 System.exit(1);
144 }
145
146 String gsdl2_home = args[0];
147 File gsdl2_dir = new File(gsdl2_home);
148 if (!gsdl2_dir.isDirectory()) {
149 System.err.println("gsdl-home-dir directory does not exist!");
150 System.exit(1);
151 }
152
153 String lang = (args.length==2) ? args[1] : "en";
154 new Server2(gsdl2_home,lang);
155 }
156}
Note: See TracBrowser for help on using the repository browser.