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