Changeset 18868

Show
Ignore:
Timestamp:
01.04.2009 19:31:09 (10 years ago)
Author:
ak19
Message:

Updated Server files for Linux GS2 Local Library Server to work the same way as the Windows GS2 LLS. Basically the major difference is that build.properties is no longer used but glisite.cfg or llssite.cfg depending on whether or not gs2-server.sh is launched from gli. There are a few additional changes required for this to keep it consistent with the way the Windows GS2 LLS works: storing the preview URL in glisite.cfg/llssite.cfg while the server is running and removing it when the server has stopped, Server2.java's main method taking the configfile as an additional parameter (and corresponding adjustments in the gsicontrol.sh script of GS2).

Location:
greenstone3/trunk/src/java/org/greenstone/server
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/server/BaseProperty.java

    r18693 r18868  
    55    public final String GSDL_HOME; 
    66    public final String GSDL_VERSION; 
    7     public final String AUTOSTART = "server.auto.start"; 
     7    public final String AUTOSTART; 
     8    public final String START_BROWSER; 
     9 
    810    public final String DEFAULT_SERVLET = "server.default.servlet"; 
    911 
     
    1921    public final String SERVER_SETTINGS; 
    2022     
    21     protected BaseProperty(String version, String web_port)  
     23    protected BaseProperty(String version, String web_port, String autostart, String startbrowser)  
    2224    { 
    2325    // property names 
     
    2729    SERVER_CONTROL = "Server"+version+"Control"; 
    2830    SERVER_SETTINGS = "Server"+version+"Settings"; 
     31    AUTOSTART = autostart; 
     32    START_BROWSER = startbrowser; 
    2933    } 
    3034 
  • greenstone3/trunk/src/java/org/greenstone/server/BaseServer.java

    r18770 r18868  
    2424    static protected final int SERVER_START_FAILED = 1; 
    2525    static protected final int BROWSER_LAUNCHED = 2; 
    26     static protected final int BROWSER_LAUNCH_FAILED = 3;  
     26    static protected final int BROWSER_LAUNCH_FAILED = 3; 
     27    static protected final int START_SERVER = 4; 
    2728  
    28     static protected Properties build_properties; 
     29    static protected Properties config_properties; 
    2930    static protected Logger logger_; 
    3031 
    31     static public File build_properties_file; 
     32    static public File config_properties_file; 
    3233    static public Dictionary dictionary; 
    3334    static public BaseProperty Property; 
     
    3738    protected String gsdl_home; 
    3839    protected String logs_folder; 
     40    protected boolean start_browser; 
     41 
    3942    protected BaseServerControl server_control_;     
    4043     
    41     protected BaseServer(String gsdl_home, String lang, String build_properties_path, String logs) 
     44    protected BaseServer(String gsdl_home, String lang, String config_properties_path, String logs) 
    4245    { 
    4346    this.gsdl_home = gsdl_home; 
     
    4952    logger_ = Logger.getLogger(BaseServer.class.getName()); 
    5053 
    51     build_properties_file = new File(build_properties_path); 
    52  
    53     if (!build_properties_file.exists()) { 
    54         logger_.fatal("Can't find build.properties file "+build_properties_path); 
     54    config_properties_file = new File(config_properties_path); 
     55     
     56    if (!config_properties_file.exists()) { 
     57        logger_.fatal("Can't find configuration file "+config_properties_path); 
    5558        System.exit(1); 
    5659    } 
    5760     
    58     build_properties = new Properties(); 
    59     reloadBuildProperties(); 
    60      
     61    config_properties = new Properties(); 
     62    reloadConfigProperties(); 
     63 
    6164    dictionary = new Dictionary("server", lang, this.getClass().getClassLoader()); 
    6265 
     
    6568    public void autoStart() 
    6669    { 
    67     String auto_start = build_properties.getProperty(BaseServer.Property.AUTOSTART); 
    68     if (auto_start != null && auto_start.equals("true")) { 
    69         restart(); 
    70     } 
    71     else{ 
    72         start(); 
    73     }   
    74      
     70    String auto_start = config_properties.getProperty(BaseServer.Property.AUTOSTART, "true"); 
     71 
     72    if (auto_start.equals("true") || auto_start.equals("1")) { 
     73        String start_browser = config_properties.getProperty(BaseServer.Property.START_BROWSER, "true"); 
     74 
     75        if (start_browser.equals("true") || start_browser.equals("1")) { 
     76        restart(); 
     77        } 
     78        else{ 
     79        start(); 
     80        }   
     81    } else { 
     82        reload(); // browser URL or other important properties may not yet be initialised 
     83        server_state_ = START_SERVER; 
     84        server_control_.updateControl(); 
     85    } 
    7586    } 
    7687 
     
    91102    public abstract String getBrowserURL(); 
    92103    public abstract void reload(); // reload properties, since they may have changed 
     104    protected void preStop() {} 
    93105 
    94106    public void reconfigRequired() 
     
    118130    } 
    119131    else{ 
    120         recordSuccess(CONFIGURE_CMD);  
     132        recordSuccess(CONFIGURE_CMD); 
    121133    } 
    122134     
     
    162174    String url = getBrowserURL(); 
    163175    //recordError("**** browserURL: " + url); 
    164     BrowserLauncher launcher = new BrowserLauncher(build_properties.getProperty(BaseServer.Property.BROWSER_PATH),url); 
     176    BrowserLauncher launcher = new BrowserLauncher(config_properties.getProperty(BaseServer.Property.BROWSER_PATH, ""),url); 
    165177        logger_.info(message); 
    166178 
     
    203215 
    204216    public void stop(boolean silent) { 
     217    preStop(); 
    205218    if(!silent) { 
    206219        server_control_.displayMessage(dictionary.get("ServerControl.Stopping")); 
     
    217230    } 
    218231     
    219     public  void reloadBuildProperties() { 
     232    public  void reloadConfigProperties() { 
    220233    try { 
    221         FileInputStream in = new FileInputStream(build_properties_file); 
     234        FileInputStream in = new FileInputStream(config_properties_file); 
    222235 
    223236        if (in != null) { 
    224         logger_.info("loading build properties"); 
    225         build_properties.load(in); 
     237        logger_.info("loading configuration properties: " + config_properties_file); 
     238        config_properties.load(in); 
    226239        in.close(); 
    227240        } else { 
    228         logger_.error("Couldn't load build properties!"); 
     241        logger_.error("Couldn't load configuration properties from " + config_properties_file + "!"); 
    229242        } 
    230243    } catch (Exception e) { 
    231         logger_.error("Exception trying to reload build.properties: "+e); 
     244        logger_.error("Exception trying to reload configuration properties " +config_properties_file + ": " +e); 
    232245    } 
    233246     
  • greenstone3/trunk/src/java/org/greenstone/server/BaseServerControl.java

    r18693 r18868  
    132132    public void updateControl(){ 
    133133        switch (server.getServerState()){ 
     134    case BaseServer.START_SERVER: 
    134135    case BaseServer.SERVER_STARTED: 
    135136        { 
     
    157158    case BaseServer.BROWSER_LAUNCH_FAILED: 
    158159        { 
    159         enter_button.setText(stringToHTML(BaseServer.dictionary.get("ServerControl.EnterLibrary"))); 
     160        enter_button.setText(stringToHTML(BaseServer.dictionary.get("ServerControl.EnterLibrary") 
     161                          + "(URL: " + server.getBrowserURL() + ")")); 
    160162        enter_button.setEnabled(true); 
    161163        fMenu.setEnabled(true); 
     
    201203    public void actionPerformed(ActionEvent ev) { 
    202204        switch (server.getServerState()){ 
     205        case BaseServer.START_SERVER: 
     206        { 
     207         Thread runInThread = new Thread(new Runnable(){ 
     208                public void run(){ 
     209                server.start(); 
     210                server.launchBrowser(); 
     211                } 
     212            },"start server and launch browser"); 
     213             
     214            runInThread.start();  
     215                   break;      
     216        } 
    203217        case BaseServer.SERVER_STARTED: case BaseServer.BROWSER_LAUNCH_FAILED: 
    204218        { 
  • greenstone3/trunk/src/java/org/greenstone/server/BaseServerSettings.java

    r18710 r18868  
    4444 
    4545        try { 
    46         this.portNum = Integer.parseInt(server.build_properties.getProperty(BaseServer.Property.WEB_PORT)); 
     46        this.portNum = Integer.parseInt(server.config_properties.getProperty(BaseServer.Property.WEB_PORT)); 
    4747    } 
    4848        catch(Exception e){ 
     
    5050    }  
    5151 
    52         this.browserPath = server.build_properties.getProperty(BaseServer.Property.BROWSER_PATH); 
     52        this.browserPath = server.config_properties.getProperty(BaseServer.Property.BROWSER_PATH); 
    5353         
    5454        if (this.browserPath == null || this.browserPath.equals("")){ 
     
    6060    } 
    6161 
    62     String auto_start_str = server.build_properties.getProperty(BaseServer.Property.AUTOSTART); 
     62    String auto_start_str = server.config_properties.getProperty(BaseServer.Property.AUTOSTART); 
    6363    if ((auto_start_str.trim()).equals("true")) { 
    6464        this.autoStart = true; 
     
    222222     
    223223    public void actionPerformed(ActionEvent ev) { 
    224         // save everything to build_properties if things have changed 
     224        // save everything to config_properties if things have changed 
    225225         boolean has_changed = false; 
    226226             boolean require_restart = false; 
     
    268268         
    269269        ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 
    270         oldFileLines = scriptReadWrite.readInFile(BaseServer.build_properties_file); 
     270        oldFileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 
    271271         
    272272        newFileLines = scriptReadWrite.queryReplace(oldFileLines, BaseServer.Property.WEB_PORT, portNum+""); 
     
    284284        newFileLines = scriptReadWrite.queryReplace(newFileLines,BaseServer.Property.BROWSER_PATH, browserPath); 
    285285 
    286         scriptReadWrite.writeOutFile(BaseServer.build_properties_file, 
     286        scriptReadWrite.writeOutFile(BaseServer.config_properties_file, 
    287287                         newFileLines); 
    288         server.reloadBuildProperties(); 
     288        server.reloadConfigProperties(); 
    289289        if (require_restart){ 
    290290            JOptionPane.showMessageDialog(null,server.dictionary.get("ServerSetting.SettingChanged"),"Info", JOptionPane.INFORMATION_MESSAGE); 
  • greenstone3/trunk/src/java/org/greenstone/server/ScriptReadWrite.java

    r13229 r18868  
    4646    public ArrayList queryReplace(ArrayList fileLines_ex, String param, 
    4747                  String newValue) { 
    48  
     48    // only replace existing, don't append if param does not exist 
     49    return replaceOrAddLine(fileLines_ex, param, newValue, false);  
     50    } 
     51     
     52    // if the parameter exists, then a replace is performed, else the parameter-value 
     53    // is appended 
     54    public ArrayList replaceOrAddLine(ArrayList fileLines_ex, String param, String newValue,  
     55                      boolean replaceElseAdd)  
     56    {    
    4957    String oneLine = null; 
    5058    String newLine = null; 
     
    6371            newLine = param + "=" + newValue; 
    6472            fileLines_ex.set(i, newLine); 
     73            replaceElseAdd = false; // replaced, no longer need to add in any case 
    6574            break; 
    6675        } 
    6776        } 
     77    } 
     78    // If we've made no replacement and need to append the new item 
     79    if(replaceElseAdd) { 
     80        fileLines_ex.add(param+"="+newValue); 
    6881    } 
    6982    return fileLines_ex; 
  • greenstone3/trunk/src/java/org/greenstone/server/Server2.java

    r18770 r18868  
    66import java.io.FileOutputStream; 
    77import java.util.Properties; 
     8import java.util.ArrayList; 
    89 
    910import org.apache.log4j.*; 
     
    1617    protected String libraryURL; 
    1718 
    18     public Server2(String gsdl2_home, String lang) 
     19    public Server2(String gsdl2_home, String lang, String configfile) 
    1920    { 
    20     super(gsdl2_home, lang, 
    21           gsdl2_home+File.separator+"lib"+File.separator+"java"+File.separator+"build.properties", 
    22           "etc"+File.separator+"logs-gsi");  
     21    super(gsdl2_home, lang, configfile, "etc"+File.separator+"logs-gsi");    
     22                   // configfile can be either glisite.cfg or llssite.cfg 
     23 
    2324 
    2425    Property = new Server2Property(); 
     
    3031    START_CMD     = "web-start"; 
    3132    RESTART_CMD   = "web-restart"; 
    32     CONFIGURE_CMD = "configure-web"; 
     33    CONFIGURE_CMD = "configure-web " + configfile; 
    3334    STOP_CMD      = "web-stop"; 
    3435 
     
    122123        recordError("Could not open gsdlsite_cfg for reading, using default library prefix."); 
    123124        } 
    124         reloadBuildProperties(); 
    125         host = build_properties.getProperty("apache.server", host); 
    126         port = build_properties.getProperty("apache.port", port); 
     125        reloadConfigProperties(); 
     126        port = config_properties.getProperty("portnumber", port); 
    127127 
    128128    } catch(Exception e) { 
     
    132132 
    133133    libraryURL = "http://" + host + ":" + port + suffix; 
    134     //recordSuccess("**** browser URL is: " + libraryURL); 
    135134     
     135    // the URL has been changed 
     136    // write the URL to the file since this should work like GS2's Local Lib Server for Windows 
     137    ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 
     138    ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 
     139    scriptReadWrite.replaceOrAddLine(fileLines, "url", libraryURL, true); 
     140    scriptReadWrite.writeOutFile(config_properties_file, fileLines); 
    136141    } 
    137142     
     143    // About to stop the webserver 
     144    // Custom GS2 action: remove the url property from the config file 
     145    protected void preStop() { 
     146    ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 
     147    ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 
     148    if (fileLines.contains("url="+getBrowserURL())) { 
     149        // would be last element, remove it: 
     150        fileLines.remove(fileLines.size()-1); 
     151    } 
     152    scriptReadWrite.writeOutFile(config_properties_file, fileLines); 
     153    } 
    138154 
    139155    public static void main (String[] args) 
    140156    { 
    141         if ((args.length < 1) || (args.length>2)) { 
    142         System.err.println("Usage: java org.greenstone.server.Server2 <gsdl2-home-dir> [lang]"); 
     157        if ((args.length < 1) || (args.length > 3)) { 
     158        System.err.println("Usage: java org.greenstone.server.Server2 <gsdl2-home-dir> [lang] [--config=configfile]"); 
    143159        System.exit(1); 
    144160    } 
     
    151167    } 
    152168     
    153     String lang = (args.length==2) ? args[1] : "en"; 
    154     new Server2(gsdl2_home,lang); 
     169    String lang = (args.length>=2) ? args[1] : "en"; 
     170     
     171    // if no config file is given, then the following defaults to llssite.cfg 
     172    String configfile = (args.length==3 && args[2].startsWith("--config=")) ? args[2] : gsdl2_home+File.separator+"llssite.cfg"; 
     173    int equalSign = configfile.indexOf('='); 
     174    if(equalSign != -1) { 
     175        configfile = configfile.substring(equalSign+1); 
     176    } 
     177 
     178    new Server2(gsdl2_home,lang,configfile); 
    155179    } 
    156180} 
  • greenstone3/trunk/src/java/org/greenstone/server/Server2Property.java

    r18693 r18868  
    99    // Initialising customised final variables  
    1010    // Version number, WEB_PORT 
    11     super("2", "apache.port"); 
     11    super("2", "portnumber", "autoenter", "start_browser"); 
    1212    } 
    1313 
  • greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java

    r18719 r18868  
    33import java.awt.BorderLayout; 
    44import java.awt.event.*; 
     5import java.util.ArrayList; 
    56import javax.swing.*; 
    67import javax.swing.event.*; 
     
    4041    } 
    4142 
     43    public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines)  
     44    { 
     45    String newAutoEnter = autoEnter.isSelected() ? "1" : "0"; 
     46    newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 
     47    } 
     48 
    4249    public void stateChanged(ChangeEvent e) { 
    4350    int portNumber = ((Integer)portNumber_spinner.getValue()).intValue(); 
    4451    String url = (String)prefix_combobox.getSelectedItem(); 
    45  
     52    url.replace('\\', '/'); 
    4653    String pre = ""; 
    4754    if(url.indexOf("http://") != -1) { 
     
    6774 
    6875    public void actionPerformed(ActionEvent e) { 
    69         System.err.println("*** Port number changed in url box!"); 
    7076    String url = (String)prefix_combobox.getSelectedItem(); 
    7177    int portNumber = 80; 
  • greenstone3/trunk/src/java/org/greenstone/server/Server3.java

    r18770 r18868  
    3838     
    3939    public String getBrowserURL() { 
    40     return GlobalProperties.getGSDL3WebAddress()+ build_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET); 
     40    return GlobalProperties.getGSDL3WebAddress()+ config_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET); 
    4141    } 
    4242 
  • greenstone3/trunk/src/java/org/greenstone/server/Server3Property.java

    r18693 r18868  
    88    { 
    99    // Initialising customised final variables  
    10     // Version number, WEB_PORT 
    11     super("3", "tomcat.port"); 
     10    // Version number, WEB_PORT, autoenter, startbrowser 
     11    // For GS3, the last two are controlled by the same property 
     12    super("3", "tomcat.port", "server.auto.start", "server.auto.start"); 
    1213    } 
    1314 
  • greenstone3/trunk/src/java/org/greenstone/server/Server3Settings.java

    r18708 r18868  
    3131    JLabel servlet_label = new JLabel(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".URL")); 
    3232 
    33     this.servletDefault = server.build_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET).replaceAll("/",""); 
     33    this.servletDefault = server.config_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET).replaceAll("/",""); 
    3434     
    3535    servlet_combobox = new JComboBox(); 
     
    8686    public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines)  
    8787    { 
     88    String newAutoEnter = (new Boolean(autoEnter.isSelected())).toString(); 
     89    newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 
     90 
    8891    String newServletDef = (String) servlet_combobox.getSelectedItem(); 
    8992    newFileLines = scriptReadWrite.queryReplace(newFileLines,BaseServer.Property.DEFAULT_SERVLET, (String) url_mappings.get(newServletDef));