Handle startup problems.
This commit is contained in:
parent
d208917ab7
commit
e3dbe372bd
1 changed files with 30 additions and 24 deletions
|
|
@ -22,9 +22,9 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.CommandLineParser;
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
import org.apache.commons.cli.DefaultParser;
|
import org.apache.commons.cli.DefaultParser;
|
||||||
|
|
@ -107,31 +107,37 @@ public class Operator extends Component {
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) {
|
||||||
Logger.getLogger(Operator.class.getName())
|
try {
|
||||||
.fine(() -> "Version: "
|
Logger.getLogger(Operator.class.getName())
|
||||||
+ Operator.class.getPackage().getImplementationVersion());
|
.fine(() -> "Version: "
|
||||||
CommandLineParser parser = new DefaultParser();
|
+ Operator.class.getPackage().getImplementationVersion());
|
||||||
// parse the command line arguments
|
CommandLineParser parser = new DefaultParser();
|
||||||
final Options options = new Options();
|
// parse the command line arguments
|
||||||
options.addOption(new Option("c", "config", true, "The configu"
|
final Options options = new Options();
|
||||||
+ "ration file (defaults to /etc/opt/vmoperator/config.yaml)."));
|
options.addOption(new Option("c", "config", true, "The configura"
|
||||||
CommandLine cmd = parser.parse(options, args);
|
+ "tion file (defaults to /etc/opt/vmoperator/config.yaml)."));
|
||||||
// The Operator is the root component
|
CommandLine cmd = parser.parse(options, args);
|
||||||
app = new Operator(cmd);
|
// The Operator is the root component
|
||||||
|
app = new Operator(cmd);
|
||||||
|
|
||||||
// Prepare Stop
|
// Prepare Stop
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
app.fire(new Stop(), Channel.BROADCAST);
|
app.fire(new Stop(), Channel.BROADCAST);
|
||||||
Components.awaitExhaustion();
|
Components.awaitExhaustion();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// Cannot do anything about this.
|
// Cannot do anything about this.
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Start application
|
// Start application
|
||||||
Components.start(app);
|
Components.start(app);
|
||||||
|
} catch (IOException | InterruptedException
|
||||||
|
| org.apache.commons.cli.ParseException e) {
|
||||||
|
Logger.getLogger(Operator.class.getName()).log(Level.SEVERE, e,
|
||||||
|
() -> "Failed to start runner: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue