source: main/trunk/greenstone3/src/java/org/greenstone/server/Server3.java

Last change on this file was 32429, checked in by ak19, 6 years ago

solr should only be accessible locally (from localhost, specifically 127.0.0.1) which means over http. This conflicted with the previous design of the properties file for working with http and/or https. Now we have tomcat.port.https and localhost.port.http, both always set. In place of server.protocol that used to contain the default protocol, we now have server.protocols which can be set to a comma separated list of one or both of http and https. Drastic restructuring followed. I think I've tested all but https certification stuff.

File size: 5.5 KB
Line 
1package org.greenstone.server;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.FileOutputStream;
6import java.util.Properties;
7
8import org.apache.log4j.PropertyConfigurator;
9
10import org.greenstone.server.BaseServer;
11import org.greenstone.server.BaseProperty;
12import org.greenstone.util.GlobalProperties;
13import org.greenstone.util.ProtocolPortProperties;
14import org.greenstone.util.RunAnt;
15
16public class Server3 extends BaseServer
17{
18 String opt_ant_properties = null;
19 ProtocolPortProperties protocolPortProps = null;
20
21 public Server3(String gsdl3_src_home, String lang)
22 {
23 super(gsdl3_src_home, lang, gsdl3_src_home + File.separatorChar + "build.properties", "web"+File.separator+"logs");
24
25 // config properties are loaded into the config_properties object
26 // now test the port and protocol values are sane or exit.
27 try {
28 protocolPortProps = new ProtocolPortProperties(config_properties);
29 } catch(Exception e) {
30 String errorMsg = "@@@ Error with ports/protocol in " + config_properties_file + ": " + e.getMessage();
31
32 // print it everywhere, because port/protocol misconfiguration is a fatal error and we're exiting
33 logger_.error(errorMsg, e);
34 System.err.println(errorMsg);
35 // If error, then quit this app as soon as possible
36 System.exit(-1);
37 }
38
39 Property = new Server3Property(protocolPortProps.getDefaultPortPropertyName());
40 // defaultPortPropertyName can be 'localhost.port.http' or 'tomcat.port.https'
41 // depending on which of http and https is the first value of 'server.protocols'
42
43 String frame_title = dictionary.get("ServerControl.Frame_Title");
44 server_control_ = new Server3Control(this, frame_title);
45
46 /** Ant command targets for managing Web server */
47 START_CMD = "start";
48 RESTART_CMD = "restart";
49 CONFIGURE_CMD = "configure";
50 STOP_CMD = "force-stop-tomcat force-stop-derby";
51
52 String is_read_only = System.getProperty("gsdl3home.isreadonly","false");
53 if (is_read_only.equals("true")) {
54 String default_gsdl3_home = gsdl3_src_home + File.separatorChar + "web";
55 String gsdl3_writablehome = System.getProperty("gsdl3.writablehome",default_gsdl3_home);
56 opt_ant_properties = "-Dgsdl3home.isreadonly=true -Dgsdl3.writablehome="+gsdl3_writablehome;
57 }
58
59 autoStart();
60 }
61
62 protected int runTarget(String cmd)
63 {
64 RunAnt runAnt = new RunAnt(opt_ant_properties);
65 runAnt.setTargetCmd(cmd);
66 runAnt.run();
67 return runAnt.getTargetState();
68 }
69
70 public String getBrowserURL()
71 {
72 return GlobalProperties.getFullGSDL3WebAddress() + config_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET);
73 }
74
75 public String fallbackGSDL3Home()
76 {
77 return gsdl_home + File.separator + "web"; //System.getenv("GSDL3SRCHOME") + File.separator + "web";
78 }
79
80 public void reload()
81 {
82 String gsdl3_writablehome = System.getProperty("gsdl3.writablehome",fallbackGSDL3Home());
83
84 GlobalProperties.loadGlobalProperties(gsdl3_writablehome); // properties file may have changed, so reload it
85 }
86
87 public static void main(String[] args)
88 {
89 if ((args.length < 1) || (args.length > 2))
90 {
91 System.err.println("Usage: java org.greenstone.server.Server3 <gsdl3-src-home> [lang]");
92 System.exit(1);
93 }
94
95 String gsdl3_src_home = args[0];
96 File gsdl3_src_dir = new File(gsdl3_src_home);
97 if (!gsdl3_src_dir.isDirectory())
98 {
99 System.err.println("src directory does not exist!");
100 System.exit(1);
101 }
102
103 String lang = (args.length == 2) ? args[1] : "en";
104 new Server3(gsdl3_src_home, lang);
105 }
106
107 // Prepare the log4j.properties for GS3
108 protected void initLogger() {
109
110 String gsdl3_home = GlobalProperties.getGSDL3Home(); // may not be initialised at this stage
111 if(gsdl3_home == null) { // use gsdl_home/web
112 gsdl3_home = fallbackGSDL3Home();
113 }
114
115 String gsdl3_writablehome = System.getProperty("gsdl3.writablehome",gsdl3_home);
116
117 String propsFolder = gsdl3_writablehome + File.separator + "WEB-INF" + File.separator + "classes" + File.separator;
118 File propsFile = new File(propsFolder+"log4j.properties");
119
120 // create it from the template file GS3/resources/web/log4j.properties
121 // Always do this => helps make Greenstone3 portable
122
123
124 try {
125 // need to set gsdl3.home property's value to be gsdl_home/web,
126 // so that the location of the log files gets resolved correctly
127
128 // load the template log4j.properties.svn file into logProps
129 FileInputStream infile = new FileInputStream(new File(gsdl_home+File.separator+"resources"+File.separator+"web"+File.separator+"log4j.properties.svn"));
130 if(infile != null) {
131 Properties logProps = new Properties();
132 logProps.load(infile);
133 infile.close();
134
135 // set gsdl3.home to web home
136 logProps.setProperty("gsdl3.home", gsdl3_home);
137 logProps.setProperty("gsdl3.writablehome", gsdl3_writablehome);
138
139 // write the customised properties out to a custom log4j.properties file
140 FileOutputStream outfile = new FileOutputStream(propsFile);
141 if(outfile != null) {
142 logProps.store(outfile, "Customised log4j.properties file");
143 outfile.close();
144 } else {
145 System.err.println("Could not store properties file " + propsFile + " for Server3.");
146 }
147 }
148 } catch(Exception e) {
149 System.err.println("Exception occurred when custom-configuring the logger for Server3.\n" + e);
150 e.printStackTrace();
151 }
152
153 // now configure the logger with the custom log4j.properties file
154 if(propsFile.exists()) {
155 PropertyConfigurator.configure(propsFile.getAbsolutePath());
156 } else {
157 System.err.println("Could not create properties file " + propsFile + " for Server3.");
158 }
159 }
160}
Note: See TracBrowser for help on using the repository browser.