chore(daemon): use zcashd.pid approach to check external daemon
This commit is contained in:
parent
b77bffe621
commit
158383b65c
|
@ -4,7 +4,6 @@ import cp from 'child_process';
|
|||
import path from 'path';
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
import processExists from 'process-exists';
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import isDev from 'electron-is-dev';
|
||||
import type { ChildProcess } from 'child_process';
|
||||
|
@ -24,6 +23,7 @@ import { log } from './logger';
|
|||
import store from '../electron-store';
|
||||
import { parseZcashConf, parseCmdArgs, generateArgsFromConf } from './parse-zcash-conf';
|
||||
import { isTestnet } from '../is-testnet';
|
||||
import { getDaemonProcessId } from './get-daemon-process-id';
|
||||
import {
|
||||
EMBEDDED_DAEMON,
|
||||
ZCASH_NETWORK,
|
||||
|
@ -129,8 +129,6 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
|
|||
await waitForDaemonClose(ZCASHD_PROCESS_NAME);
|
||||
}
|
||||
|
||||
const [, isRunning] = await eres(processExists(ZCASHD_PROCESS_NAME));
|
||||
|
||||
// This will parse and save rpcuser and rpcpassword in the store
|
||||
let [, optionsFromZcashConf] = await eres(parseZcashConf());
|
||||
|
||||
|
@ -155,11 +153,19 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
|
|||
if (optionsFromZcashConf.rpcuser) store.set('rpcuser', optionsFromZcashConf.rpcuser);
|
||||
if (optionsFromZcashConf.rpcpassword) store.set('rpcpassword', optionsFromZcashConf.rpcpassword);
|
||||
|
||||
if (isRunning) {
|
||||
log('Searching for zcashd.pid');
|
||||
const daemonProcessId = getDaemonProcessId(optionsFromZcashConf.datadir);
|
||||
|
||||
if (daemonProcessId) {
|
||||
store.set(EMBEDDED_DAEMON, false);
|
||||
log(
|
||||
// eslint-disable-next-line
|
||||
`A daemon was found running in PID: ${daemonProcessId}. Starting Zepio in external daemon mode.`,
|
||||
);
|
||||
|
||||
// Command line args override zcash.conf
|
||||
const [{ cmd, pid }] = await findProcess('name', ZCASHD_PROCESS_NAME);
|
||||
const [{ cmd, pid }] = await findProcess('pid', daemonProcessId);
|
||||
|
||||
store.set(DAEMON_PROCESS_PID, pid);
|
||||
|
||||
// We need grab the rpcuser and rpcpassword from either process args or zcash.conf
|
||||
|
@ -179,11 +185,13 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
|
|||
if (rpcport) store.set('rpcport', rpcport);
|
||||
if (rpcconnect) store.set('rpcconnect', rpcconnect);
|
||||
|
||||
log(`A daemon was found running in PID: ${pid}. Starting Zepio in external daemon mode.`);
|
||||
|
||||
return resolve();
|
||||
}
|
||||
|
||||
log(
|
||||
"Zepio couldn't find a `zcashd.pid`, that means there is no instance of zcash running on the machine, trying start built-in daemon",
|
||||
);
|
||||
|
||||
store.set(EMBEDDED_DAEMON, true);
|
||||
|
||||
if (!isRelaunch) {
|
||||
|
|
Loading…
Reference in New Issue