3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import java.sql.Driver;
22 import java.sql.DriverManager;
23 import java.util.Enumeration;
24 import java.util.Date;
25 import org.sonews.config.Config;
26 import org.sonews.daemon.ChannelLineBuffers;
27 import org.sonews.daemon.Connections;
28 import org.sonews.daemon.NNTPDaemon;
29 import org.sonews.feed.FeedManager;
30 import org.sonews.mlgw.MailPoller;
31 import org.sonews.storage.StorageBackendException;
32 import org.sonews.storage.StorageManager;
33 import org.sonews.storage.StorageProvider;
34 import org.sonews.util.Log;
35 import org.sonews.util.Purger;
36 import org.sonews.util.io.Resource;
39 * Startup class of the daemon.
40 * @author Christian Lins
43 public final class Main
50 /** Version information of the sonews daemon */
51 public static final String VERSION = "sonews/1.0.0";
52 public static final Date STARTDATE = new Date();
55 * The main entrypoint.
59 public static void main(String[] args) throws Exception
61 System.out.println(VERSION);
62 Thread.currentThread().setName("Mainthread");
64 // Command line arguments
65 boolean feed = false; // Enable feeding?
66 boolean mlgw = false; // Enable Mailinglist gateway?
69 for(int n = 0; n < args.length; n++)
71 if(args[n].equals("-c") || args[n].equals("-config"))
73 Config.inst().set(Config.LEVEL_CLI, Config.CONFIGFILE, args[++n]);
74 System.out.println("Using config file " + args[n]);
76 else if(args[n].equals("-dumpjdbcdriver"))
78 System.out.println("Available JDBC drivers:");
79 Enumeration<Driver> drvs = DriverManager.getDrivers();
80 while(drvs.hasMoreElements())
82 System.out.println(drvs.nextElement());
86 else if(args[n].equals("-feed"))
90 else if(args[n].equals("-h") || args[n].equals("-help"))
95 else if(args[n].equals("-mlgw"))
99 else if(args[n].equals("-p"))
101 port = Integer.parseInt(args[++n]);
103 else if(args[n].equals("-v") || args[n].equals("-version"))
105 // Simply return as the version info is already printed above
110 // Try to load the JDBCDatabase;
111 // Do NOT USE BackendConfig or Log classes before this point because they require
112 // a working JDBCDatabase connection.
115 StorageProvider sprov =
116 StorageManager.loadProvider("org.sonews.storage.impl.JDBCDatabaseProvider");
117 StorageManager.enableProvider(sprov);
119 // Make sure some elementary groups are existing
120 if(!StorageManager.current().isGroupExisting("control"))
122 StorageManager.current().addGroup("control", 0);
123 Log.msg("Group 'control' created.", true);
126 catch(StorageBackendException ex)
128 ex.printStackTrace();
129 System.err.println("Database initialization failed with " + ex.toString());
130 System.err.println("Make sure you have specified the correct database" +
131 " settings in sonews.conf!");
135 ChannelLineBuffers.allocateDirect();
138 Runtime.getRuntime().addShutdownHook(new ShutdownHook());
140 // Start the listening daemon
143 port = Config.inst().get(Config.PORT, 119);
145 final NNTPDaemon daemon = NNTPDaemon.createInstance(port);
148 // Start Connections purger thread...
149 Connections.getInstance().start();
151 // Start mailinglist gateway...
154 new MailPoller().start();
160 FeedManager.startFeeding();
163 Purger purger = new Purger();
166 // Wait for main thread to exit (setDaemon(false))
170 private static void printArguments()
172 String usage = Resource.getAsString("helpers/usage", true);
173 System.out.println(usage);