aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/Main.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-09-15 11:29:01 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-09-15 11:29:01 +1200
commit2fb444df86d56246a8b5cee515eb91490c8dee05 (patch)
treeca1796dfe137184b6381fefeba0f7de4e26d7dd7 /src/org/traccar/Main.java
parent363ca19cb2ac1b56e3db8f38c89cf61c73806462 (diff)
downloadtrackermap-server-2fb444df86d56246a8b5cee515eb91490c8dee05.tar.gz
trackermap-server-2fb444df86d56246a8b5cee515eb91490c8dee05.tar.bz2
trackermap-server-2fb444df86d56246a8b5cee515eb91490c8dee05.zip
More work on service implementation
Diffstat (limited to 'src/org/traccar/Main.java')
-rw-r--r--src/org/traccar/Main.java76
1 files changed, 45 insertions, 31 deletions
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
index 986731240..992bfd8de 100644
--- a/src/org/traccar/Main.java
+++ b/src/org/traccar/Main.java
@@ -71,11 +71,16 @@ public final class Main {
throw new RuntimeException("Configuration file is not provided");
}
- String configFile = args[args.length - 1];
+ final String configFile = args[args.length - 1];
- if (args.length > 1) {
- WindowsService windowsService = new WindowsService("traccar");
- switch (args[1]) {
+ if (args[0].startsWith("--")) {
+ WindowsService windowsService = new WindowsService("traccar") {
+ @Override
+ public void run() {
+ Main.run(configFile);
+ }
+ };
+ switch (args[0]) {
case "--install":
windowsService.install("traccar", null, null, null, null, configFile);
return;
@@ -87,40 +92,49 @@ public final class Main {
windowsService.init();
break;
}
+ } else {
+ run(configFile);
}
+ }
- Context.init(configFile);
- logSystemInfo();
- LOGGER.info("Version: " + Context.getAppVersion());
- LOGGER.info("Starting server...");
-
- Context.getServerManager().start();
- if (Context.getWebServer() != null) {
- Context.getWebServer().start();
- }
+ public static void run(String configFile) {
+ try {
+ Context.init(configFile);
+ logSystemInfo();
+ LOGGER.info("Version: " + Context.getAppVersion());
+ LOGGER.info("Starting server...");
+
+ Context.getServerManager().start();
+ if (Context.getWebServer() != null) {
+ Context.getWebServer().start();
+ }
- new Timer().scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- try {
- Context.getDataManager().clearHistory();
- } catch (SQLException error) {
- LOGGER.warn(null, error);
+ new Timer().scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ Context.getDataManager().clearHistory();
+ } catch (SQLException error) {
+ LOGGER.warn(null, error);
+ }
}
- }
- }, 0, CLEAN_PERIOD);
+ }, 0, CLEAN_PERIOD);
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- LOGGER.info("Shutting down server...");
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ LOGGER.info("Shutting down server...");
- if (Context.getWebServer() != null) {
- Context.getWebServer().stop();
+ if (Context.getWebServer() != null) {
+ Context.getWebServer().stop();
+ }
+ Context.getServerManager().stop();
}
- Context.getServerManager().stop();
- }
- });
+ });
+ } catch (Exception e) {
+ LOGGER.error(null, e);
+ throw new RuntimeException(e);
+ }
}
}