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

Last change on this file since 26001 was 26001, checked in by ak19, 12 years ago

Solved a hard to track bug that prevented a change to the GS3 port number from being effective, when the port was adjusted from the Settings dialog during a running GS3-server. This was owing to the changes that introduced the ant target force-stop-tomcat in build.xml, which is what we want to run when we know the server is already running.

File size: 3.9 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.RunAnt;
14
15public class Server3 extends BaseServer
16{
17
18 public Server3(String gsdl3_src_home, String lang)
19 {
20 super(gsdl3_src_home, lang, gsdl3_src_home + File.separatorChar + "build.properties", "web"+File.separator+"logs");
21
22 Property = new Server3Property();
23
24 String frame_title = dictionary.get("ServerControl.Frame_Title");
25 server_control_ = new Server3Control(this, frame_title);
26
27 /** Ant command tagets for managing Web server */
28 START_CMD = "start";
29 RESTART_CMD = "restart";
30 CONFIGURE_CMD = "configure";
31 STOP_CMD = "force-stop-tomcat";
32
33 autoStart();
34 }
35
36 protected int runTarget(String cmd)
37 {
38 RunAnt runAnt = new RunAnt();
39 runAnt.setTargetCmd(cmd);
40 runAnt.run();
41 return runAnt.getTargetState();
42 }
43
44 public String getBrowserURL()
45 {
46 return GlobalProperties.getFullGSDL3WebAddress() + config_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET);
47 }
48
49 public String fallbackGSDL3Home()
50 {
51 return gsdl_home + File.separator + "web"; //System.getenv("GSDL3SRCHOME") + File.separator + "web";
52 }
53
54 public void reload()
55 {
56 GlobalProperties.loadGlobalProperties(fallbackGSDL3Home()); // properties file may have changed, so reload it
57 }
58
59 public static void main(String[] args)
60 {
61 if ((args.length < 1) || (args.length > 2))
62 {
63 System.err.println("Usage: java org.greenstone.server.Server3 <gsdl3-src-home> [lang]");
64 System.exit(1);
65 }
66
67 String gsdl3_src_home = args[0];
68 File gsdl3_src_dir = new File(gsdl3_src_home);
69 if (!gsdl3_src_dir.isDirectory())
70 {
71 System.err.println("src directory does not exist!");
72 System.exit(1);
73 }
74
75 String lang = (args.length == 2) ? args[1] : "en";
76 new Server3(gsdl3_src_home, lang);
77 }
78
79 // Prepare the log4j.properties for GS3
80 protected void initLogger() {
81
82 String gsdl3_home = GlobalProperties.getGSDL3Home(); // may not be initialised at this stage
83 if(gsdl3_home == null) { // use gsdl_home/web
84 gsdl3_home = fallbackGSDL3Home();
85 }
86 String propsFolder = gsdl3_home + File.separator + "WEB-INF" + File.separator + "classes" + File.separator;
87 File propsFile = new File(propsFolder+"log4j.properties");
88
89 // create it from the template file GS3/resources/java/log4j.properties.in
90 if(!propsFile.exists()) {
91 try {
92 // need to set gsdl3.home property's value to be gsdl_home/web,
93 // so that the location of the log files gets resolved correctly
94
95 // load the template log4j.properties.in file into logProps
96 FileInputStream infile = new FileInputStream(new File(gsdl_home+File.separator+"resources"+File.separator+"java"+File.separator+"log4j.properties.in"));
97 if(infile != null) {
98 Properties logProps = new Properties();
99 logProps.load(infile);
100 infile.close();
101
102 // set gsdl3.home to web home
103 logProps.setProperty("gsdl3.home", gsdl3_home);
104
105 // write the customised properties out to a custom log4j.properties file
106 FileOutputStream outfile = new FileOutputStream(propsFile);
107 if(outfile != null) {
108 logProps.store(outfile, "Customised log4j.properties file");
109 outfile.close();
110 } else {
111 System.err.println("Could not store properties file " + propsFile + " for Server3.");
112 }
113 }
114 } catch(Exception e) {
115 System.err.println("Exception occurred when custom-configuring the logger for Server3.\n" + e);
116 e.printStackTrace();
117 }
118 }
119
120 // now configure the logger with the custom log4j.properties file
121 if(propsFile.exists()) {
122 PropertyConfigurator.configure(propsFile.getAbsolutePath());
123 } else {
124 System.err.println("Could not create properties file " + propsFile + " for Server3.");
125 }
126 }
127}
Note: See TracBrowser for help on using the repository browser.