node app control and monitoring daemon based on config files (somewhat similar to procfiles)
npm install nacnac is a simple app control and monitoring daemon written in node
Unlike other process monitors, nac doesn't allow for random spawning and
adding of processes. Instead, nac expects you to add "apps" defined by their
name and nacfile (procfile-like configuration files)
The nacfile allows you to specify many other things about the process,
such as arguments, environment variable configuration, working directory,
custom scripts etc.
nac remembers your apps and will restart them the next time its started.
nac is multi-server-aware which allows you to use it with parallel control
tools such as pssh,
cssh,
fabric, or, in the future, rnac
nac can optionally be multi-user aware: a single daemon can run as root and
all clients will talk to it. Apps however are run under the uid of the user
that added the application, and each user can only control his own apps.
npm install nac -g
Run the nac daemon.
nacd --daemon
Create a simple YAML nacfile for your app
in the same directory where your app.js resides:
``yaml`
command: node
args: [app.js]
env:
NODE_ENV: production
PORT: 5000
Add the nacfile to git, clone the app on your server and run the commands:
$ nac myapp create ~/projects/myapp/nacfile.yaml
myapp created (/home/spion/projects/myapp/nacfile.yaml)
$ nac myapp start
You can alternatively run the daemon as root. There is no need for concern - it
will run apps under the priviledges of the user that added them (by setting
the uid and gid). Users can only administer the apps they've added themselves.
su root
nacd --daemon
Warning! The root daemon will not read the apps that were added to existing
user daemons. Users will need to re-add their apps.
There are two types of configuration files in nac:
* app configuration (nacfile)
* server daemon configuration (nacd.yaml)
Here is a complete example nacfile:
`yamlcommand to execute. It has to be executable: if using a JS file directly,
use chmod +x file.js first and add a shebang line at the top containing:
#!/usr/bin/env node
command: ./myapp-cluster.jsworking dir relative to the nacfile
cwd: .
$3
User-level nacd daemons can be configured by creating
~/.config/nac/nacd.yamlA root-level nacd daemon is configured via
/etc/nacd.yamlExample
nacd.yaml for the first server:`yaml
tags:
- one.myapp.com
- one
- myapp-servers
`Since this server has the tag "one.myapp.com", it will apply the specified
config overrides for that tag
available commands
#### create
nac myapp create nacfile.yaml
Adds the specified app with its nacfile to the daemon.
The name specified must be unique for that server and user. If the user already
has an app running under that name, on that server, nac will complain.
#### start, stop, restart
nac myapp [start|stop|restart]
Start/stop/restart the app
myapp using the command, arguments and
environment variables specified in the config file. #### kill
nac myapp kill
Send the specified named signal to the app's process. Useful for user-defined
signals such as cluster reloading
#### destroy
nac myapp destroy
Will remove the project and its nacfile from the daemon and stop the app
process
#### update
nac myapp update [configpath]
Will update the configuration file. If you omit the path,
nacd will attempt
to reload the configuration file from the same location as previously
specified. If you specify the config path, nacd will update the apps's
configuration and update the location of the config file for that app#### logs
nac myapp logs
Show stdout/stderr logs for the project. Logs will be displayed in the format
[date] [time] [stdout|stderr]: content
Arguments:
* --tag - show just stdout
* --last - show last N lines in log (default 100)
* --past
$3
nac myapp run script [args]
Run one of the scripts for the project with the specified arguments. Will
display the output of the script.
$3
nac help [command]
Display detailed help for the command. If the command is omitted, nac will
print a list of commands.
environment variables
When running the app or its custom script,
nac` sets the following extra * NACFILE - full path to the nacfile
* NACDIR - absolute working directory of the app
* NACNAME - the name of the app (e.g. myapp)
For more info on replacing forever and using nac for deployment, read the
forever migration guide
MIT