exit if daemon is not running

Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
dzdidi
2024-01-25 07:57:33 +00:00
parent c414940c54
commit d3c16cc4be

View File

@@ -28,20 +28,9 @@ const repoName = matches[2]
const store = new Corestore(RAM)
const swarm = new Hyperswarm({ keypair: home.getKeyPair() })
let daemonPid
if (!home.isDaemonRunning()) {
const opts = {
detached: true,
stdio: [ 'ignore', home.getOutStream(), home.getErrStream() ]
}
const daemon = spawn('git-peard', opts)
daemonPid = daemon.pid
home.storeDaemonPid(daemonPid)
// TODO: remove in case of error or exit but allow unref
// daemon.on('error', home.removeDaemonPid)
// daemon.on('exit', home.removeDaemonPid)
console.error('started daemon', daemonPid)
daemon.unref()
console.error('Please start git pear daemon')
process.exit(1)
}
swarm.join(crypto.discoveryKey(Buffer.from(targetKey, 'hex')), { server: false })
@@ -120,11 +109,6 @@ async function talkToGit (refs, drive, repoName, rpc) {
const publicKey = home.readPk()
const res = await rpc.request(command, Buffer.from(`${publicKey}/${repoName}:${dst}`))
if (daemonPid) {
process.kill(daemonPid)
home.removeDaemonPid()
}
process.stdout.write('\n\n')
process.exit(0)
} else if (chunk && chunk.search(/^list/) !== -1) { // list && list for-push