Future<int>
startWithMonitor(String generatedStartScript)
Source
Future<int> startWithMonitor(String generatedStartScript) async {
var startupTime = new DateTime.now();
var startScriptFile = createStartScript(generatedStartScript);
var serverProcess = await executeStartScript(startScriptFile);
if (shouldRunObservatory && await supportsLaunchObservatory()) {
await launchObservatory("http://localhost:8181");
}
var startFailureReason = await checkForStartError(serverProcess);
if (startFailureReason != "ok") {
failWithError(serverProcess.pid, startFailureReason);
return 1;
}
if (!shouldRunDetached) {
stderr.addStream(serverProcess.stderr);
serverProcess.exitCode.then((code) {
displayError("Server terminated (Exit Code: $code)");
exit(0);
});
}
var now = new DateTime.now();
var diff = now.difference(startupTime);
displayInfo("Success!", color: CLIColor.boldGreen);
displayProgress(
"Startup Time: ${diff.inSeconds}.${"${diff.inMilliseconds}".padLeft(4, "0")}s");
displayProgress(
"Application '$packageName/$libraryName' now running on port $port. (PID: ${serverProcess.pid})");
if (!shouldRunDetached) {
displayProgress("Use Ctrl-C (SIGINT) to stop running the application.");
displayInfo("Starting Application Log --");
stdout.addStream(serverProcess.stdout);
ProcessSignal.SIGINT.watch().listen((ProcessSignal s) {
var f = new File(pidPathForPid(serverProcess.pid));
if (f.existsSync()) {
f.deleteSync();
}
Isolate.current.kill();
});
} else {
displayProgress(
"Use 'aqueduct serve stop' in '${projectDirectory.path}' to stop running the application.");
}
return 0;
}