feat: 🎸 Do not stop client daemon if it was already started (#2021)

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11932
This commit is contained in:
Zhihe Li committed 2024-01-16 10:17:45 -05:00
1 parent 7bc2ccb5ae
commit 50e4a2adbc
1 file changed
+13 -8
@@ -10,6 +10,7 @@ const runtimeSettings = require('./runtime-settings');
class ClientDaemonManager {
#socketPath;
#isClientDaemonAlreadyRunning = true;
get socketPath() {
return this.#socketPath;
@@ -33,14 +34,14 @@ class ClientDaemonManager {
* @returns {Promise<void>}
*/
async start() {
// TODO: Finalize how often the daemon should be refreshing
const startDaemonCommand = [
'daemon',
'start',
'-refresh-interval-seconds',
'10',
];
await spawn(startDaemonCommand);
const startDaemonCommand = ['daemon', 'start'];
const { stderr } = await spawn(startDaemonCommand);
// If we get a null/undefined, err on safe side and don't stop daemon when
// we close the desktop client
if (stderr && !stderr.includes('The daemon is already running')) {
this.#isClientDaemonAlreadyRunning = false;
}
this.status();
}
@@ -48,6 +49,10 @@ class ClientDaemonManager {
* Stops the daemon.
*/
stop() {
if (this.#isClientDaemonAlreadyRunning) {
return;
}
const stopDaemonCommand = ['daemon', 'stop'];
spawnSync(stopDaemonCommand);
}