Fix Windows local node daemon arguments
This commit is contained in:
@@ -39,20 +39,9 @@ class WindowsLocalNodeService implements LocalNodeService {
|
||||
@override
|
||||
Future<bool> stop() async {
|
||||
final effective = _resolveConfig(null);
|
||||
final pidFile = File(await _pidFilePath());
|
||||
if (!await pidFile.exists()) {
|
||||
_logger.w('Local node pidfile not found at ${pidFile.path}');
|
||||
return false;
|
||||
}
|
||||
final rawPid = await pidFile.readAsString();
|
||||
final pid = int.tryParse(rawPid.trim());
|
||||
if (pid == null) {
|
||||
_logger.w('Local node pidfile invalid: $rawPid');
|
||||
return false;
|
||||
}
|
||||
final killed = Process.killPid(pid);
|
||||
if (!killed) {
|
||||
_logger.w('Failed to terminate local node process ($pid)');
|
||||
final stopped = await _stopViaRpc(effective);
|
||||
if (!stopped) {
|
||||
_logger.w('Failed to stop local node via RPC.');
|
||||
return false;
|
||||
}
|
||||
return _waitForStop(effective);
|
||||
@@ -86,7 +75,6 @@ class WindowsLocalNodeService implements LocalNodeService {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final pidFile = await _pidFilePath();
|
||||
final daemonLogFile = await AppPaths.localNodeLogFile();
|
||||
final launcherLogFile = await AppPaths.localNodeLauncherLogFile();
|
||||
await launcherLogFile.parent.create(recursive: true);
|
||||
@@ -97,8 +85,6 @@ class WindowsLocalNodeService implements LocalNodeService {
|
||||
config.rpcHost,
|
||||
'--rpc-bind-port',
|
||||
config.rpcPort.toString(),
|
||||
'--pidfile',
|
||||
pidFile,
|
||||
'--log-file',
|
||||
daemonLogFile.path,
|
||||
...config.extraArgs,
|
||||
@@ -200,6 +186,35 @@ class WindowsLocalNodeService implements LocalNodeService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _stopViaRpc(LocalNodeConfig config) async {
|
||||
HttpClient? client;
|
||||
try {
|
||||
client = HttpClient();
|
||||
final uri = Uri.parse('http://${config.rpcHost}:${config.rpcPort}/json_rpc');
|
||||
final request = await client.postUrl(uri);
|
||||
request.headers.contentType = ContentType.json;
|
||||
request.write(jsonEncode({
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0',
|
||||
'method': 'stop_daemon',
|
||||
}));
|
||||
final response = await request.close();
|
||||
final body = await utf8.decoder.bind(response).join();
|
||||
if (response.statusCode != HttpStatus.ok) {
|
||||
_logger.w(
|
||||
'Local node stop_daemon returned HTTP ${response.statusCode}: $body',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
_logger.w('Failed to call stop_daemon on local node: $error');
|
||||
return false;
|
||||
} finally {
|
||||
client?.close(force: true);
|
||||
}
|
||||
}
|
||||
|
||||
LocalNodeConfig _resolveConfig(LocalNodeConfig? config) {
|
||||
final base = config ?? _lastConfig ?? const LocalNodeConfig();
|
||||
return _applyOverrides(base);
|
||||
@@ -252,8 +267,4 @@ class WindowsLocalNodeService implements LocalNodeService {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> _pidFilePath() async {
|
||||
return (await AppPaths.localNodePidFile()).path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user