This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bookchin/master
v2.0.0
- Loading branch information
Showing
31 changed files
with
1,678 additions
and
1,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
coverage/ | ||
*.swp |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,227 @@ | ||
[![Storj](https://nodei.co/npm/storjshare-daemon.png?downloads=true)](http://storj.github.io/storjshare-daemon) | ||
========================================================================================== | ||
Storj Share Daemon | ||
================== | ||
|
||
[![Build Status](https://img.shields.io/travis/Storj/storjshare-daemon.svg?style=flat-square)](https://travis-ci.org/Storj/storjshare-daemon) | ||
[![Coverage Status](https://img.shields.io/coveralls/Storj/storjshare-daemon.svg?style=flat-square)](https://coveralls.io/r/Storj/storjshare-daemon) | ||
[![NPM](https://img.shields.io/npm/v/storjshare-daemon.svg?style=flat-square)](https://www.npmjs.com/package/storjshare-daemon) | ||
[![License](https://img.shields.io/badge/license-AGPL3.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/Storj/storjshare-daemon/master/LICENSE) | ||
|
||
This package exposes a module that provides all of the tools needed to | ||
integrate with the Storj network. You must have Node.js v4.x.x, Python v2.x.x, | ||
and Git installed. [Complete documentation can be found here](http://storj.github.io/core). | ||
Daemon + CLI for farming data on the Storj network, suitable for standalone | ||
use or inclusion in other packages. | ||
|
||
## Installation | ||
|
||
Make sure you have the following prerequisites installed: | ||
|
||
* Git | ||
* Node.js LTS | ||
* NPM | ||
* Python 2.7 | ||
* GCC/G++/Make | ||
|
||
Install the package globally using Node Package Manager: | ||
|
||
``` | ||
npm install storjshare-daemon --save | ||
npm install -g storjshare-daemon | ||
``` | ||
|
||
Including in your project | ||
## Usage (CLI) | ||
|
||
Once installed, you will have access to the `storjshare` program, so start by | ||
asking it for some help. | ||
|
||
``` | ||
var ConfigManager = require('storjshare-daemon').ConfigManager; | ||
var Farmer = require('storjshare-daemon').Farmer; | ||
storjshare --help | ||
Usage: storjshare [options] [command] | ||
Commands: | ||
start start a farming node | ||
stop stop a farming node | ||
restart restart a farming node | ||
status check status of node(s) | ||
logs tail the logs for a node | ||
create create a new configuration | ||
destroy kills the farming node | ||
killall kills all shares and stops the daemon | ||
daemon starts the daemon | ||
help [cmd] display help for [cmd] | ||
Options: | ||
-h, --help output usage information | ||
-V, --version output the version number | ||
``` | ||
|
||
You can also get more detailed help for a specific command. | ||
|
||
``` | ||
storjshare help create | ||
Generating the Config Manager | ||
Usage: storjshare-create [options] | ||
Options: | ||
-h, --help output usage information | ||
-a, --sjcx <addr> specify the sjcx address (required) | ||
-s, --storage <path> specify the storage path | ||
-l, --logfile <path> specify the logfile path | ||
-k, --privkey <privkey> specify the private key | ||
-o, --outfile <writepath> write config to path | ||
``` | ||
var configName = 'test'; | ||
var config = { | ||
farmerConf: { | ||
paymentAddress: '123123334123 | ||
}, | ||
storage: { | ||
path: '/path/to/datadir', | ||
dataDir: path.join('/path/to/datadir', 'storjshare-' + configName), | ||
size: size, | ||
unit: unit | ||
} | ||
}; | ||
|
||
var configManager = new ConfigManager(configName, config); | ||
## Usage (Programmatic) | ||
|
||
The Storj Share daemon uses a local [dnode](https://github.com/substack/dnode) | ||
server to handle RPC message from the CLI and other applications. Assuming the | ||
daemon is running, your program can communicate with it using this interface. | ||
The example that follows is using Node.js, but dnode is implemented in many | ||
[other languages](https://github.com/substack/dnode#dnode-in-other-languages). | ||
|
||
```js | ||
const dnode = require('dnode'); | ||
const daemon = dnode.connect(45015); | ||
|
||
configManager.saveConfig(function(err) { | ||
if (err) { | ||
console.log(err) | ||
} | ||
daemon.on('remote', (rpc) => { | ||
// rpc.start(configPath, callback); | ||
// rpc.stop(nodeId, callback); | ||
// rpc.restart(nodeId, callback); | ||
// rpc.status(callback); | ||
// rpc.destroy(nodeId, callback); | ||
// rpc.killall(); | ||
}); | ||
``` | ||
|
||
Generating the Farmer | ||
You can also easily start the daemon from your program by creating a dnode | ||
server and passing it an instance of the `RPC` class exposed from this package. | ||
|
||
```js | ||
const storjshare = require('storjshare-daemon'); | ||
const dnode = require('dnode'); | ||
const api = new storjshare.RPC(); | ||
|
||
dnode(api.methods).listen(45015, '127.0.0.1'); | ||
``` | ||
var configName = 'test'; | ||
var configManager = new ConfigManager(configName); | ||
|
||
// Initialize Farmer with configManager | ||
var farmer = new Farmer(configManager); | ||
## Configuring the Daemon | ||
|
||
// Pipe the output to wherever | ||
configManager.config.farmerConf.logger.pipe(process.stdout); | ||
The Storj Share daemon loads configuration from anywhere the | ||
[rc](https://www.npmjs.com/package/rc) package can read it. The first time you | ||
run the daemon, it will create a directory in `$HOME/.config/storjshare`, so | ||
the simplest way to change the daemon's behavior is to create a file at | ||
`$HOME/.config/storjshare/config` containing the following: | ||
|
||
```json | ||
{ | ||
"daemonRpcPort": 45015, | ||
"daemonRpcAddress": "127.0.0.1", | ||
"daemonLogFilePath": "", | ||
"daemonLogVerbosity": 3 | ||
} | ||
``` | ||
|
||
Modify these parameters to your liking, see `example/daemon.config.json` for | ||
detailed explanation of these properties. | ||
|
||
## Debugging the Daemon | ||
|
||
The daemon logs activity to the configured log file, which by default is | ||
`$HOME/.config/storjshare/logs/daemon.log`. However if you find yourself | ||
needing to frequently restart the daemon and check the logs during | ||
development, you can run the daemon as a foreground process for a tighter | ||
feedback loop. | ||
|
||
``` | ||
storjshare killall | ||
storjshare daemon --foreground | ||
``` | ||
|
||
## Migrating from [`storjshare-cli`](https://github.com/storj/storjshare-cli) | ||
|
||
Storj Share provides a simple method for creating new shares, but if you were | ||
previously using the `storjshare-cli` package superceded by this one, you'll | ||
want to migrate your configuration to the new format. To do this, first you'll | ||
need to dump your private key **before** installing this package. | ||
|
||
> If you accidentally overwrote your old `storjshare-cli` installation with | ||
> this package, don't worry - just reinstall the old package to dump the key, | ||
> then reinstall this package. | ||
### Step 0: Dump Your Private Key | ||
|
||
You can print your cleartext private key from storjshare-cli, using the | ||
`dump-key` command: | ||
|
||
``` | ||
storjshare dump-key | ||
[...] > Unlock your private key to start storj > ******** | ||
[info] Cleartext Private Key: | ||
[info] ====================== | ||
[info] 4154e85e87b323611cba45ab1cd51203f2508b1da8455cdff8b641cce827f3d6 | ||
[info] | ||
[info] (This key is suitable for importing into Storj Share GUI) | ||
``` | ||
|
||
If you are using a custom data directory, be sure to add the `--datadir <path>` | ||
option to be sure you get the correct key. Also be sure to note your defined | ||
payout address and data directory. | ||
|
||
### Step 1: Install Storj Share and Create Config | ||
|
||
Now that you have your private key, you can generate a new configuration file. | ||
To do this, first install the `storjshare-daemon` package globally and use the | ||
`create` command. You'll need to remove the `storjshare-cli` package first, so | ||
make sure you perform the previous step for all shared drives before | ||
proceeding forward. | ||
|
||
``` | ||
npm remove -g storjshare-cli | ||
npm install -g storjshare-daemon | ||
``` | ||
|
||
Now that you have Storj Share installed, use the `create` command to generate | ||
your configuration. | ||
|
||
// Begin Farming | ||
farmer.start(function(err) { | ||
if(err) { | ||
console.log('Failed to start: ' + err.message); | ||
} | ||
}); | ||
``` | ||
storjshare create -k 4154e8... -a 1K1rPg... -s <datadir> -o <writepath> | ||
``` | ||
|
||
This will generate your configuration file given the parameters you passed in, | ||
write the file to the path following the `-o` option, and open it in your text | ||
editor. Here, you can make other changes to the configuration following the | ||
detailed comments in the generated file. | ||
|
||
### Step 2: Use The New Configuration | ||
|
||
Now that you have successfully migrated your configuration file, you can use | ||
it to start the share. | ||
|
||
``` | ||
storjshare start --config path/to/config.json | ||
* daemon is not running, starting... | ||
* starting share with config at path/to/config.json | ||
``` | ||
|
||
## License | ||
|
||
Storj Share - Daemon + CLI for farming data on the Storj network. | ||
Copyright (C) 2017 Storj Labs, Inc | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see http://www.gnu.org/licenses/. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const editor = require('editor'); | ||
const {tmpdir, homedir} = require('os'); | ||
const fs = require('fs'); | ||
const storj = require('storj-lib'); | ||
const path = require('path'); | ||
const mkdirp = require('mkdirp'); | ||
const config = require('../lib/config/daemon'); | ||
const storjshare_create = require('commander'); | ||
|
||
storjshare_create | ||
.option('-a, --sjcx <addr>', 'specify the sjcx address (required)') | ||
.option('-s, --storage <path>', 'specify the storage path') | ||
.option('-l, --logfile <path>', 'specify the logfile path') | ||
.option('-k, --privkey <privkey>', 'specify the private key') | ||
.option('-o, --outfile <writepath>', 'write config to path') | ||
.parse(process.argv); | ||
|
||
if (!storjshare_create.sjcx) { | ||
console.error('\n no payment address was given, try --help'); | ||
process.exit(1); | ||
} | ||
|
||
if (!storjshare_create.privkey) { | ||
storjshare_create.privkey = storj.KeyPair().getPrivateKey(); | ||
} | ||
|
||
if (!storjshare_create.storage) { | ||
storjshare_create.storage = path.join( | ||
homedir(), | ||
'.config/storjshare/shares', | ||
storj.KeyPair(storjshare_create.privkey).getNodeID() | ||
); | ||
mkdirp.sync(storjshare_create.storage); | ||
} | ||
|
||
if (!storjshare_create.logfile) { | ||
storjshare_create.logfile = path.join( | ||
homedir(), | ||
'.config/storjshare/logs', | ||
storj.KeyPair(storjshare_create.privkey).getNodeID() + '.log' | ||
); | ||
} | ||
|
||
let isWritingToTemp = false; | ||
|
||
if (!storjshare_create.outfile) { | ||
isWritingToTemp = true; | ||
storjshare_create.outfile = path.join( | ||
tmpdir(), | ||
storj.KeyPair(storjshare_create.privkey).getNodeID() + '.json' | ||
); | ||
} | ||
|
||
let exampleConfigPath = path.join(__dirname, '../example/farmer.config.json'); | ||
let exampleConfigString = fs.readFileSync(exampleConfigPath).toString(); | ||
|
||
function replaceEmptyConfig(prop, value) { | ||
exampleConfigString = exampleConfigString.replace( | ||
`"${prop}": ""`, | ||
`"${prop}": "${value}"` | ||
); | ||
} | ||
|
||
replaceEmptyConfig('paymentAddress', storjshare_create.sjcx); | ||
replaceEmptyConfig('networkPrivateKey', storjshare_create.privkey); | ||
replaceEmptyConfig('loggerOutputFile', storjshare_create.logfile); | ||
replaceEmptyConfig('storagePath', storjshare_create.storage); | ||
|
||
let outfile = isWritingToTemp ? | ||
storjshare_create.outfile : | ||
path.join(process.cwd(), storjshare_create.outfile); | ||
|
||
try { | ||
fs.writeFileSync(outfile, exampleConfigString); | ||
} catch (err) { | ||
console.log (`\n failed to write config, reason: ${err.message}`); | ||
process.exit(1); | ||
} | ||
|
||
console.log(`\n * configuration written to ${outfile}`); | ||
console.log(' * opening in your favorite editor to tweak before running'); | ||
editor(outfile, () => { | ||
console.log(' ...'); | ||
console.log(` * use new config: storjshare start --config ${outfile}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const daemonize = require('daemon'); | ||
const dnode = require('dnode'); | ||
const config = require('../lib/config/daemon'); | ||
const RPC = require('../lib/api'); | ||
const api = new RPC({ logVerbosity: config.daemonLogVerbosity }); | ||
const {createWriteStream} = require('fs'); | ||
const logFile = createWriteStream(config.daemonLogFilePath, { flags: 'a' }); | ||
const storjshare_daemon = require('commander'); | ||
|
||
storjshare_daemon | ||
.option('-F, --foreground', 'keeps the process in the foreground') | ||
.parse(process.argv); | ||
|
||
if (!storjshare_daemon.foreground) { | ||
daemonize(); | ||
api.logger.pipe(logFile); | ||
} else { | ||
api.logger.pipe(process.stdout); | ||
} | ||
|
||
dnode(api.methods).listen(config.daemonRpcPort, config.daemonRpcAddress); |
Oops, something went wrong.