This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
daemon.js
86 lines (75 loc) · 2.28 KB
/
daemon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict'
const os = require('os')
const { getRepoPath, print, ipfsPathHelp } = require('../utils')
module.exports = {
command: 'daemon',
describe: 'Start a long-running daemon process',
builder (yargs) {
return yargs
.epilog(ipfsPathHelp)
.option('enable-sharding-experiment', {
type: 'boolean',
default: false
})
.option('enable-pubsub-experiment', {
type: 'boolean',
default: false
})
.option('offline', {
desc: 'Run offline. Do not connect to the rest of the network but provide local API.',
default: false
})
.option('enable-namesys-pubsub', {
type: 'boolean',
default: false
})
.option('enable-preload', {
type: 'boolean',
default: true
})
},
handler (argv) {
argv.resolve((async () => {
print('Initializing IPFS daemon...')
print(`js-ipfs version: ${require('../../../package.json').version}`)
print(`System version: ${os.arch()}/${os.platform()}`)
print(`Node.js version: ${process.versions.node}`)
const repoPath = getRepoPath()
// Required inline to reduce startup time
const HttpApi = require('../../http')
const api = new HttpApi({
silent: argv.silent,
repo: process.env.IPFS_PATH,
offline: argv.offline,
pass: argv.pass,
preload: { enabled: argv.enablePreload },
EXPERIMENTAL: {
pubsub: argv.enablePubsubExperiment,
ipnsPubsub: argv.enableNamesysPubsub,
dht: argv.enableDhtExperiment,
sharding: argv.enableShardingExperiment
}
})
try {
await api.start()
} catch (err) {
if (err.code === 'ENOENT' && err.message.match(/uninitialized/i)) {
print('Error: no initialized ipfs repo found in ' + repoPath)
print('please run: jsipfs init')
process.exit(1)
}
throw err
}
print('Daemon is ready')
const cleanup = async () => {
print(`Received interrupt signal, shutting down...`)
await api.stop()
process.exit(0)
}
// listen for graceful termination
process.on('SIGTERM', cleanup)
process.on('SIGINT', cleanup)
process.on('SIGHUP', cleanup)
})())
}
}