chris@1: /* chris@1: * SONEWS News Server chris@1: * see AUTHORS for the list of contributors chris@1: * chris@1: * This program is free software: you can redistribute it and/or modify chris@1: * it under the terms of the GNU General Public License as published by chris@1: * the Free Software Foundation, either version 3 of the License, or chris@1: * (at your option) any later version. chris@1: * chris@1: * This program is distributed in the hope that it will be useful, chris@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@1: * GNU General Public License for more details. chris@1: * chris@1: * You should have received a copy of the GNU General Public License chris@1: * along with this program. If not, see . chris@1: */ chris@1: chris@1: package org.sonews.daemon; chris@1: chris@1: import java.sql.Driver; chris@1: import java.sql.DriverManager; chris@1: import java.sql.SQLException; chris@1: import java.util.Enumeration; chris@1: import java.util.Date; chris@1: import org.sonews.feed.FeedManager; chris@1: import org.sonews.mlgw.MailPoller; chris@1: import org.sonews.daemon.storage.Database; chris@1: import org.sonews.util.Log; chris@1: import org.sonews.util.io.Resource; chris@1: chris@1: /** chris@1: * Startup class of the daemon. chris@1: * @author Christian Lins chris@1: * @since sonews/0.5.0 chris@1: */ chris@1: public final class Main chris@1: { chris@1: chris@1: private Main() chris@1: { chris@1: } chris@1: chris@1: /** Version information of the sonews daemon */ chris@1: public static final String VERSION = "sonews/0.5.0"; chris@1: public static final Date STARTDATE = new Date(); chris@1: chris@1: /** chris@1: * The main entrypoint. chris@1: * @param args chris@1: * @throws Exception chris@1: */ chris@1: public static void main(String[] args) throws Exception chris@1: { chris@1: System.out.println(VERSION); chris@1: Thread.currentThread().setName("Mainthread"); chris@1: chris@1: // Command line arguments chris@1: boolean feed = false; // Enable feeding? chris@1: boolean mlgw = false; // Enable Mailinglist gateway? chris@1: int port = -1; chris@1: chris@1: for(int n = 0; n < args.length; n++) chris@1: { chris@1: if(args[n].equals("-c") || args[n].equals("-config")) chris@1: { chris@1: BootstrapConfig.FILE = args[++n]; chris@1: System.out.println("Using config file " + args[n]); chris@1: } chris@1: else if(args[n].equals("-dumpjdbcdriver")) chris@1: { chris@1: System.out.println("Available JDBC drivers:"); chris@1: Enumeration drvs = DriverManager.getDrivers(); chris@1: while(drvs.hasMoreElements()) chris@1: { chris@1: System.out.println(drvs.nextElement()); chris@1: } chris@1: return; chris@1: } chris@1: else if(args[n].equals("-feed")) chris@1: { chris@1: feed = true; chris@1: } chris@1: else if(args[n].equals("-h") || args[n].equals("-help")) chris@1: { chris@1: printArguments(); chris@1: return; chris@1: } chris@1: else if(args[n].equals("-mlgw")) chris@1: { chris@1: mlgw = true; chris@1: } chris@1: else if(args[n].equals("-p")) chris@1: { chris@1: port = Integer.parseInt(args[++n]); chris@1: } chris@1: } chris@1: chris@1: // Try to load the Database; chris@1: // Do NOT USE Config or Log classes before this point because they require chris@1: // a working Database connection. chris@1: try chris@1: { chris@1: Database.getInstance(); chris@1: chris@1: // Make sure some elementary groups are existing chris@1: if(!Database.getInstance().isGroupExisting("control")) chris@1: { chris@1: Database.getInstance().addGroup("control", 0); chris@1: Log.msg("Group 'control' created.", true); chris@1: } chris@1: } chris@1: catch(SQLException ex) chris@1: { chris@1: ex.printStackTrace(); chris@1: System.err.println("Database initialization failed with " + ex.toString()); chris@1: System.err.println("Make sure you have specified the correct database" + chris@1: " settings in sonews.conf!"); chris@1: return; chris@1: } chris@1: chris@1: ChannelLineBuffers.allocateDirect(); chris@1: chris@1: // Add shutdown hook chris@1: Runtime.getRuntime().addShutdownHook(new ShutdownHook()); chris@1: chris@1: // Start the listening daemon chris@1: if(port <= 0) chris@1: { chris@1: port = Config.getInstance().get(Config.PORT, 119); chris@1: } chris@1: final NNTPDaemon daemon = NNTPDaemon.createInstance(port); chris@1: daemon.start(); chris@1: chris@1: // Start Connections purger thread... chris@1: Connections.getInstance().start(); chris@1: chris@1: // Start mailinglist gateway... chris@1: if(mlgw) chris@1: { chris@1: new MailPoller().start(); chris@1: } chris@1: chris@1: // Start feeds chris@1: if(feed) chris@1: { chris@1: FeedManager.startFeeding(); chris@1: } chris@1: chris@1: // Wait for main thread to exit (setDaemon(false)) chris@1: daemon.join(); chris@1: } chris@1: chris@1: private static void printArguments() chris@1: { chris@1: String usage = Resource.getAsString("helpers/usage", true); chris@1: System.out.println(usage); chris@1: } chris@1: chris@1: }