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

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

Fixed bug introduced in previous commit: default suffix of the GS2 library URL should not include the httpprefix of greenstone.

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