nin

Nodejs INstaller

The missing nodejs app deploy tool.


An Introduction


Created by LI, Yu

Deploy nodejs app

a trivial but bother problem.

Trivial?

Usually only need to copy all files to deploy site.


cd deploy_site
cp /path/to/my/app/dev/* deploy_site/
  

Really done?

Bother?

Oh, sorry, forget to generate some conf files ...


cd deploy_site
cat ./myexamples/my.conf.example | sed -e 's/foo/bar/g' > ./etc/my.conf
  

Sorry, and some dirs ...


mkdir -p ./var
mkdir -p ./log
  

Sor..., and some npm pkgs, I forgot I have cleaned there ...


npm install
  

Wait, ..., and which's the main js file?


sudo wall -n "somebody know which is my app's main js file?"
  
And what if this is going to happen another 100 times?

We have npm, right?

Can it solve my problem?

Try this ?


npm install /path/to/my/app
  

Or this ?


npm install /path/to/my/app -g
  


Admit it, usually some or part of the problems are solved.

And the 2nd one could mess up my global node_modules.

So I need a new tool to ...

  • npm install my app
  • setup dirs of my app, and other stuff (such as conf files)
  • start my app with right scripts and parameters


That's what nin can do.

So, nin...


install it

npm install nin -g
   

Try it!


mkdir -p ~/nintest
cd ~/nintest
nin install https://github.com/liyu1981/nin-example/archive/bash.tar.gz
nin start nin-example
    
After start, go to http://localhost:12345
to see the nin-example app.

Current command summary


  Usage: nin [options] [command]

  Commands:

    deploy <pkg>           Install your app.
      > <pkg> can be any llegal npm pkg names.
      > Ref https://www.npmjs.org/doc/cli/npm-install.html

    install <pkg>          Install your app.
      > This equals deploy then setup.
      > <pkg> can be any llegal npm pkg names.
      > Ref https://www.npmjs.org/doc/cli/npm-install.html

    setup <pkgname>        Setup your app.
      > <pkgname> is the pkg installed dir name, i.e., some name in <cwd>/node_modules/

    start <pkgname>        Start your app.
      > <pkgname> is the pkg installed dir name, i.e., some name in <cwd>/node_modules/
      > pid file will write to var/<pkgname>

    stop <pkgname>         Stop your app.
      > <pkgname> is the pkg installed dir name, i.e., some name in <cwd>/node_modules/

    version                Show version info.

  Options:

    -h, --help   output usage information
    -q, --quiet  turn on quiet mode
  
For updated version, just nin↵

How to make my app ready for nin?

Just a nin.json file away.


{
  "setup": [
    {
      "type": "bash",
      "content": "op/setup.sh"
    }
  ],
  "start": [
    {
      "type": "bash",
      "content": "op/start.sh"
    }
  ],
  "stop": [
    {
      "type": "bash",
      "content": "op/stop.sh"
    }
  ]
}
  

... more elaboration

  • nin.json is basically json, same as package.json.
  • 3 kinds of targets: setup, start and stop.
  • The target will be read by corresponding nin command.
  • Each target have an array of actions.
  • Actions will executed one by one.
  • Each action is a { "type":..., "content": ... }.
  • Type could be bash/grunt/forever, and content is a file path to your script.

... more elaboration

Go back the nin-example, the setup has 1 action, which is a bash action, and its script is

#op/setup.sh
node_modules/rask/bin/rask gen log.json >etc/log.json
    
The start/stop also has 1 bash action, and the contents are

#op/start.sh
node index.js &
echo $! >var/server.pid
    

#op/stop.sh
kill `cat var/server.pid`
    

yes, nin will ensure your common dirs

In detail, they are


~/nintest $ tree -L 3
.
├── etc
│   └── nin-example -> /local/DevCamp/tmp/ne/node_modules/nin-example/etc
├── log
│   └── nin-example
├── node_modules
│   └── nin-example
│       ├── log -> /local/DevCamp/tmp/ne/log/nin-example
│       └── var -> /local/DevCamp/tmp/ne/var/nin-example
└── var
    └── nin-example
  

and nin also supports complex scripts

  • For setup target, nin supports grunt action, see the grunt branch of nin-example for example.
  • For start/stop target, nin supports forever action, see the forever branch of nin-example for example.



and I need not to install grunt/forever by myself, nin covers them. :)

So, test drive nin now!