Skip to content

Commit

Permalink
fix log -n, doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Pfeiffer committed Dec 14, 2012
1 parent 5a19b3d commit e19ddbf
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 106 deletions.
170 changes: 93 additions & 77 deletions README.md
Expand Up @@ -32,93 +32,109 @@
* install [node]
* `npm install nexus -g`

## example

install a program locally in `~/.nexus/apps`

nexus install https://github.com/visionmedia/express

we need to do `npm install` since `nexus` does *not* do anything but cloning
the repo. you can put a `nexus.json` into the root of your repo to tell `nexus`
what you want it to do upon installation (see `nexus help install`):

nexus exec express -- npm install

install another version of the program, the name is now express_2 to avoid
name-collision with the other program. now it will clone from a locally
mirrored cache of the repo:

nexus install https://github.com/visionmedia/express#2.5.11
nexus exec express_1 -- npm install

start the resource-example with version 3.0.0rc3:

nexus start express -- node examples/resource/app

start another process with version 2.5.11:

nexus start express_1 -- node -e "require('./examples/resource/app').listen(3001)"

show all locally running processes:

nexus ps

uninstall programs:

nexus rm express express_1

start a nexus server:

nexus server start -p 3840

remotly install a program and start a process, stopall and uninstall:

nexus -h 127.0.0.1 -p 3840 install https://github.com/visionmedia/express foo
nexus -h 127.0.0.1 -p 3840 start foo -- node examples/blog/app
nexus -h 127.0.0.1 -p 3840 ps
nexus -h 127.0.0.1 -p 3840 stopall
nexus -h 127.0.0.1 -p 3840 rm foo

## cli

```
nexus [-r <remote>] [-c <path to configFile>] [<command> [<options>]]
nexus [-r <remote>] [-c <path to configFile>] [<command> [<options>]]

commands:

version .. print version-number
config .. print config
ls .. list installed packages
install .. install packages
uninstall .. uninstall packages
ps .. list of current running (and crashed) programs
start .. start a program
restart .. restart a running (or max crashed) program
restartall .. restart all running programs
reboot .. reboot ghost-programs
stop .. stop a running program
stopall .. stop all running programs
exec .. execute a command
log .. access log-files
server .. control nexus-servers
help .. try `nexus help <command>` for more info
```
* [version] - print version-number
* [config] - print config
* [ls] - list installed packages
* [install] - install packages
* [uninstall] - uninstall packages
* [ps] - list of current running (and crashed) programs
* [start] - start a program
* [restart] - restart a running (or max crashed) program
* [restartall] - restart all running programs
* [reboot] - reboot ghost-programs
* [stop] - stop a running program
* [stopall] - stop all running programs
* [exec] - execute a command
* [log] - access log-files
* [server] - control nexus-servers
* [help] - try `nexus help <command>` for more info

## api

## config

you can pass a string or an object to the nexus-constructor or use the (`-c`)
option with the cli. if you pass a string it will will be `require(string)`'ed.

* `var nexus = require('nexus')('/some/path/to/a/file.json/or/file.js')`
* `var nexus = require('nexus')({prefix:__dirname})`
* `nexus -c /some/path/to/../file.json/or/file.js`

if you dont pass any config-option the nexus-cli will create a
`~/.nexus`-directory if it doesnt exist and put all the configs and logs there.
it will try to `require('~/.nexus/config.js')` per default.

the default config is (which gets overwritten by the config you pass to nexus):

``` javascript
{ prefix : process.env.HOME+'/.nexus' // is be used to prefix defaults
, apps : prefix+'/apps' // nexus will install apps into that directory
, tmp : prefix+'/tmp' // apps will be installed here temporarily
, logs : prefix+'/logs' // this is where log-files will be put
, key : null // path to key-file - if set, the nexus-server uses tls
, cert : null // path to cert-file - if set, the nexus-server uses tls
, ca : null // every file in that directory will be read into the ca
, db : prefix+'/nexus.db' // nexus stores information about running processes there
, port : 0xf00 // the nexus-server will listen on that port
// remote nexus-cli can connect (see -r option)
, host : '0.0.0.0' // if a port is set the net/tls-server will be bound to it
, socket : null // path to unix-socket, if set the server will also listen on it
, remotes : {} // can be used with the cli: `nexus -r`
// a remote is either a socket or a port
// (optional in combination with key, cert, host)
, error : null // if set (a string) it will be executed when a program exits
// CWD will be set to prefix, and ENV.NEXUS_MONITOR contains
// JSON.stringify'ed information about the chrashed program
}
```
var n = require('nexus')()
your config may look like this:

``` javascript
{ apps : '/path/to/directory'
, socket : '/path/to/socket'
, port : 12345
, host : '0.0.0.0'
, key : '/path/to/key.pem'
, cert : '/path/to/cert.pem'
, ca : '/path/to/ca'
, error : 'echo "it crashed" > email'
, remotes :
{ foo : { port:12346, key:<key>, cert:<cert>, host:'foo.com' }
, bar : { port:12347, key:<key>, cert:<cert>, host:'bar.com' }
}
}
```
n.version(cb)
now you can access the remote nexus-server `foo` with `nexus -r foo <command>`
n.config(cb)
or more simple - this will install all the things into `/var/nexus`:
n.install(opts, cb)
```
{ prefix : '/var/nexus', port : 12345 }
```
n.uninstall(opts, cb)
n.ps(opts, cb)
n.start(opts, cb)
n.restart(opts, cb)
the nexus-server will then listen on port `0.0.0.0:12345`.
n.restartall(cb)
n.reboot(cb)
n.stop(id, cb)
n.stopall(cb)
n.exec(opts, cb)
n.log(opts, cb)
n.server(opts, cb)
n.connect(opts, cb)
```

38 changes: 17 additions & 21 deletions bin/cli.js
Expand Up @@ -39,22 +39,6 @@ var opti = require('optimist')
, ' server .. control nexus-servers'
, ' help .. try `nexus help <command>` for more info'
].join('\n')

var help = {}
help.config = ['nexus config'].join('\n')
help.ls = ['nexus ls [<filter>]'].join('\n')
help.install = ['nexus install <git-url>'].join('\n')
help.uninstall = ['nexus uninstall <app-name>'].join('\n')
help.ps = ['nexus ps [<filter>]'].join('\n')
help.start = ['nexus start <app-name> [-- <command>]'].join('\n')
help.restart = ['nexus restart <app-id>'].join('\n')
help.restartall = ['nexus restartall'].join('\n')
help.reboot = ['nexus reboot'].join('\n')
help.stop = ['nexus stop <app-id> [<app-id> ..]'].join('\n')
help.stopall = ['nexus stopall'].join('\n')
help.exec = ['nexus exec [<app-name>] -- <command>'].join('\n')
help.log = ['nexus log <app-id> [<options>]'].join('\n')
help.server = ['nexus server [start]'].join('\n')

// node@0.6.x compat
fs.exists = fs.exists || path.exists
Expand All @@ -63,9 +47,8 @@ process.stdin.setRawMode = process.stdin.setRawMode || require('tty').setRawMode

if (!argv._[0]) return exit(null, usage)
else if (argv._[0] == 'help') {
if (!argv._[1] || !help[argv._[1]])
return exit(null, usage)
exit(null, help[argv._[1]])
if (!argv._[1]) return exit(null, usage)
help(argv._[1],exit)
}
else {
var opts = {}
Expand All @@ -76,8 +59,12 @@ else {
if (argv.cert) opts.cert = argv.cert
if (argv.ca) opts.ca = argv.ca
if (argv.r) opts.remote = argv.r
var N = nexus()
if (!opts.remote) return parseArgs('local')
if (argv.c)
var N = nexus(opts)
else
var N = nexus()
if (!opts.remote && !argv.p)
return parseArgs('local')
var client = N.connect(opts,function(remote,conn){
N = remote
parseArgs('remote')
Expand Down Expand Up @@ -217,6 +204,15 @@ function parseArgs(type) {
}
}

function help(cmd,cb) {
var docDir = path.join(__dirname,'..','doc','cli')
var cmdFile = path.join(docDir,cmd+'.md')
fs.exists(cmdFile,function(e){
if (!e) return exit('invalid command "'+cmd+'"')
fs.readFile(cmdFile,'utf-8',cb)
})
}

function parseFilter(args) {
var result = false
var args = args.map(function(x){return x.replace(/\./,':')})
Expand Down
3 changes: 3 additions & 0 deletions deps/mon/.gitignore
@@ -0,0 +1,3 @@
*.o
mon.log
mon
72 changes: 72 additions & 0 deletions doc/cli/config.md
@@ -0,0 +1,72 @@
# nexus-config(1) -- Manage nexus configuration

## SYNOPSIS

nexus config

## DESCRIPTION

you can pass a string or an object to the nexus-constructor or use the (`-c`)
option with the cli. if you pass a string it will will be `require(string)`'ed.

* `var nexus = require('nexus')('/some/path/to/a/file.json/or/file.js')`
* `var nexus = require('nexus')({prefix:__dirname})`
* `nexus -c /some/path/to/../file.json/or/file.js`

if you dont pass any config-option the nexus-cli will create a
`~/.nexus`-directory if it doesnt exist and put all the configs and logs there.
it will try to `require('~/.nexus/config.js')` per default.

the default config is (which gets overwritten by the config you pass to nexus):

``` javascript
{ prefix : process.env.HOME+'/.nexus' // is be used to prefix defaults
, apps : prefix+'/apps' // nexus will install apps into that directory
, tmp : prefix+'/tmp' // apps will be installed here temporarily
, logs : prefix+'/logs' // this is where log-files will be put
, key : null // path to key-file - if set, the nexus-server uses tls
, cert : null // path to cert-file - if set, the nexus-server uses tls
, ca : null // every file in that directory will be read into the ca
, db : prefix+'/nexus.db' // nexus stores information about running processes there
, port : 0xf00 // the nexus-server will listen on that port
// remote nexus-cli can connect (see -r option)
, host : '0.0.0.0' // if a port is set the net/tls-server will be bound to it
, socket : null // path to unix-socket, if set the server will also listen on it
, remotes : {} // can be used with the cli: `nexus -r`
// a remote is either a socket or a port
// (optional in combination with key, cert, host)
, error : null // if set (a string) it will be executed when a program exits
// CWD will be set to prefix, and ENV.NEXUS_MONITOR contains
// JSON.stringify'ed information about the chrashed program
}
```

## EXAMPLES

your config may look like this:

``` javascript
{ apps : '/path/to/directory'
, socket : '/path/to/socket'
, port : 12345
, host : '0.0.0.0'
, key : '/path/to/key.pem'
, cert : '/path/to/cert.pem'
, ca : '/path/to/ca'
, error : 'echo "it crashed" > email'
, remotes :
{ foo : { port:12346, key:<key>, cert:<cert>, host:'foo.com' }
, bar : { port:12347, key:<key>, cert:<cert>, host:'bar.com' }
}
}
```

now you can access the remote nexus-server `foo` with `nexus -r foo <command>`

or more simple - this will install all the things into `/var/nexus`:

```
{ prefix : '/var/nexus', port : 12345 }
```

the nexus-server will then listen on port `0.0.0.0:12345`.
36 changes: 36 additions & 0 deletions doc/cli/log.md
@@ -0,0 +1,36 @@
# nexus-log(1) -- Access and manage nexus-logs

## SYNOPSIS

nexus logs <command> [<options>]

## DESCRIPTION

Access and manage nexus-logs

## COMMANDS

### list

### cleanup

### tail

nexus tail <appId> [<options>]

#### OPTIONS

* `-f` - follow
* `-n <n>` - last `<n>` lines

## EXAMPLES

Print the last `50` lines of the log-file corresponding to the application
with the id `idY`

nexus tail idY -n 50

Print the last `50` lines of the log-file corresponding to the application
with the id `idY` running on a remote nexus `remoteX` and follow the output:

nexus -r remoteX tail idY -n 50 -f
1 change: 1 addition & 0 deletions nexus.js
Expand Up @@ -584,6 +584,7 @@ N.log = function log(opts, cb) {
if (!mon) return cb(new Error('invalid options, invalid id'))
var logPath = path.join(_config.logs,mon.name+'_'+opts.id+'.log')
opts.command = 'tail '+logPath
if (opts.lines) opts.command += ' -n '+opts.lines
if (opts.follow) opts.command += ' -f'
self.exec(opts, cb)
}
Expand Down

0 comments on commit e19ddbf

Please sign in to comment.