mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 14:14:22 +01:00
30
src/cli.js
30
src/cli.js
@@ -105,23 +105,37 @@ program
|
|||||||
.description('start/stop gitpear daemon')
|
.description('start/stop gitpear daemon')
|
||||||
.option('-s, --start', 'start daemon')
|
.option('-s, --start', 'start daemon')
|
||||||
.option('-k, --stop', 'stop daemon')
|
.option('-k, --stop', 'stop daemon')
|
||||||
|
.option('-a, --attach', 'watch daemon logs')
|
||||||
.action((p, options) => {
|
.action((p, options) => {
|
||||||
|
if (options.opts().start && options.opts().stop) {
|
||||||
|
console.error('Cannot start and stop daemon at the same time')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
if (!options.opts().start && !options.opts().stop) {
|
||||||
|
console.error('Need either start or stop option')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
if (options.opts().start) {
|
if (options.opts().start) {
|
||||||
if (home.getDaemonPid()) {
|
if (home.getDaemonPid()) {
|
||||||
console.error('Daemon already running with PID:', home.getDaemonPid())
|
console.error('Daemon already running with PID:', home.getDaemonPid())
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const daemon = spawn('gitpeard', {
|
const opts = {}
|
||||||
detached: true,
|
if (options.opts().attach) {
|
||||||
stdio: [
|
opts.stdio = 'inherit'
|
||||||
'ignore',
|
} else {
|
||||||
home.getOutStream(),
|
opts.detached = true
|
||||||
home.getErrStream()
|
opts.stdio = [ 'ignore', home.getOutStream(), home.getErrStream() ]
|
||||||
]
|
}
|
||||||
})
|
|
||||||
|
const daemon = spawn('gitpeard', opts)
|
||||||
console.log('Daemon started. Process ID:', daemon.pid)
|
console.log('Daemon started. Process ID:', daemon.pid)
|
||||||
home.storeDaemonPid(daemon.pid)
|
home.storeDaemonPid(daemon.pid)
|
||||||
|
// TODO: remove in case of error or exit but allow unref
|
||||||
|
// daemon.on('error', home.removeDaemonPid)
|
||||||
|
// daemon.on('exit', home.removeDaemonPid)
|
||||||
daemon.unref()
|
daemon.unref()
|
||||||
} else if (options.opts().stop) {
|
} else if (options.opts().stop) {
|
||||||
if (!home.getDaemonPid()) {
|
if (!home.getDaemonPid()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user