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