Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status

RSS

nodestack (6) Versions 2.3.3

Installs/Configures nodestack

Policyfile
Berkshelf
Knife
cookbook 'nodestack', '= 2.3.3', :supermarket
cookbook 'nodestack', '= 2.3.3'
knife supermarket install nodestack
knife supermarket download nodestack
README
Dependencies
Changelog
Quality 0%

nodestack Cookbook

This cookbook deploys a NodeJS applitcation stack.

Requirements

cookbooks

  • apt
  • mysql
  • mysql-multi
  • database
  • chef-sugar
  • apt
  • mysql-multi
  • pg-multi
  • database
  • chef-sugar
  • elasticsearch
  • apache2, ~> 1.10
  • memcached
  • openssl
  • redisio
  • varnish
  • rackspace_gluster
  • platformstack
  • mongodb
  • build-essential
  • java
  • yum
  • git
  • nodejs
  • ssh_known_hosts
  • application
  • magic_shell
  • logrotate

Attributes

Note: the 'my_nodejs_app' defines the name of the app, please change this to something more relevant to the customer.

node['nodestack']['apps']['my_nodejs_app']['app_dir'] path where the application will be deployed

node['nodestack']['apps']['my_nodejs_app']['git_repo'] Git repository where the code lives.

node['nodestack']['apps']['my_nodejs_app']['git_rev'] Code revision or branch that should be used ('origin/' should not be specified for remote branches.) Example: HEAD

node['nodestack']['apps']['my_nodejs_app']['git_repo_domain'] The domain name for the git repo. Example: github.com

node['nodestack']['apps']['my_nodejs_app']['entry_point'] the .js file that will be ran as the server.

node['nodestack']['apps']['my_nodejs_app']['npm'] true/false - Wether we should run npm install during a deployment.

node['nodestack']['apps']['my_nodejs_app']['npm_options'] Array - NPM command line options to use for the application. '--production' should usually be included unless development is being done on the server.

node['nodestack']['apps']['my_nodejs_app']['config_file'] true/false - Wether the coobook will write a config.js from the following config hash.

node['nodestack']['apps']['my_nodejs_app']['env']= {} - This config hash contains environment variables that will be available to the application.

node['nodestack']['apps']['my_nodejs_app']['env']['PORT'] This is the only env attribute the cookbook expects to have by default, this is the port the app listens on.

node['nodestack']['apps']['my_nodejs_app']['monitoring']['body'] Text that will be matched from the GET request

node['nodestack']['apps']['my_nodejs_app']['deployment']['before_symlink'] Exposes the before_symlink attribute for the application resource. Set this to nil if you're not planning on using it.

node['nodestack']['apps']['my_nodejs_app']['deployment']['before_symlink_template'] Template file that will be dropped on the revision folder that will be ran by the before_symlink callback. Set this to nil if you're not planning on using it.

node['nodestack']['apps']['my_nodejs_app']['deployment']['template_options'] Hash of values that can be used in the before_symlink_template.

node['nodestack']['apps']['my_nodejs_app']['deployment']['strategy'] This is the strategy that will be used to run the Node.js application. Currently Nodestack only supports forever. Scroll further down to the deployment strategy section to read more about this.

node['nodestack']['apps']['my_nodejs_app']['open_files'] This sets the application user's file open limit (ulimit -n) - this is useful for upping the total number of concurrent websockets.

node['nodestack']['forever']['watch_ignore_patterns'] = ['*.log', '*.logs'] This is a list of patterns that will be ignored and not watched by forever-monitor. Forever-monitor watches the code directory (in the demo app /var/app/current) and will reload the application if it notices any changes in the files.

node['nodestack']['code_deployment'] This enables or disabled code deployment.

Deployment strategy

In the near future, nodestack may support more than one deployment strategy, for now it only supports forever.

Forever

With this deployment strategy, we use whatever init system is running on the OS to start/stop a service that starts a very simple Node.js app that starts forever-monitor.

This application will monitor and supervise the Node.js application the application being deployed. Forever-monitor will monitor any changes on the application files and reload itself if it finds any changes. It will also control the logging and the pids for the child process. There's also other options that can be implemented in the future, like the amount of child processes.

Code deployment is optional.

Nodestack can be deployed on a server without the deploying an application. Please note that the deployment strategy used will need to consider installing dependencies through NPM and starting/stopping the application. Some of these could be handled on a wrapper cookbook if so desired.

To make code deployment optional you need to set the following attribute node['nodestack']['code_deployment'] = false

Encrypted Data Bags

This cookbook uses encrypted databags to fill in the config.js file for the application. This config.js file is where you would usually include credentials for third party services, API keys, database passwords, etc. The data bag also stores the deployment private key.
The top level key in the databag represents the environment.

Example of the contents of a databag:

{
  "id": "config",
  "staging": {
    "ssh_deployment_key": "-----BEGIN RSA PRIVATE KEY-----\Ia+q5KO/FfGc2pD2bt2Vh9Tjg==\n-----END RSA PRIVATE KEY-----",
    "config": {
      "mysql": {
        "password": "randompass"
      },
      "mongo": {
        "host": "192.168.1.1",
        "port": 27027
      }
    }
  }
}

Attributes expected from an encrypted databag:

config = {} Configuration hash with all the information that the application needs

ssh_deployment_key ='' SSH private key for deployment.

It's important to name the databag with the app_name and then _databag

Usage

To deploy an app node these is how a nodejs_app role would look like:
text
$ knife role show nodejs_app
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: nodejs_app
override_attributes:
run_list:
recipe[platformstack::default]
recipe[rackops_rolebook::default]
recipe[nodestack::application_nodejs]

To deploy a standalone db for an app node these is how a nodejs_mysql role would look like:
text
$ knife role show nodejs_mysql
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: nodejs_mysql
override_attributes:
run_list:
recipe[platformstack::default]
recipe[rackops_rolebook::default]
recipe[nodestack::mysql_base]

To deploy a mongo node these is how a nodejs_mongo role would look like:
text
$ knife role show nodejs_mongo
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: nodejs_mongo
override_attributes:
run_list:
recipe[platformstack::default]
recipe[rackops_rolebook::default]
recipe[nodestack::mongodb_standalone]

These are the minimum environment variables that would be needed:
text
$ knife environment show nodejs
chef_type: environment
cookbook_versions:
default_attributes:
description:
json_class: Chef::Environment
name: nodejs
override_attributes:
mysql:
server_root_password: randompass
mysql-multi:
master: 10.x.x.x
nodestack:
app_name: beer_survey
git_repo: https://github.com/jrperritt/beer-survey.git
platformstack:
cloud_backup:
enabled: false
cloud_monitoring:
enabled: false
rackspace:
cloud_credentials:
api_key: xxx
username: xxx

  • Building MySQL cluster for nodestack.

Ensure the following attributes are set within environment or wrapper cookbook.

['mysql']['server_repl_password'] = 'rootlogin'
['mysql']['server_repl_password'] = 'replicantlogin'
['mysql-multi']['master'] = '1.2.3.4'
['mysql-multi']['slaves'] = ['5.6.7.8']

MySQL Master node:
text
$ knife role show nodejs_mysql_master
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: nodejs_mysql_master
override_attributes:
run_list:
recipe[platformstack::default]
recipe[rackops_rolebook::default]
recipe[nodestack::mysql_master]

MySQL Slave node:
text
$ knife role show nodejs_mysql_slave
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: nodejs_mysql_slave
override_attributes:
run_list:
recipe[platformstack::default]
recipe[rackops_rolebook::default]
recipe[nodestack::mysql_slave]

  • Building a PostgreSQL cluster for nodestack.

Ensure the following attributes are set within environment or wrapper cookbook.

['postgresql']['version'] = '9.3'
['postgresql']['password'] = 'postgresdefault'
['pg-multi']['replication']['password'] = 'useagudpasswd'
['pg-multi']['master_ip'] = '1.2.3.4'
['pg-multi']['slave_ip'] = ['5.6.7.8']

Depending on OS one of the following two must be set:
['postgresql']['enable_pdgd_yum'] = true  (Redhat Family)
['postgresql']['enable_pdgd_apt'] = true  (Debian Family)

PostgreSQL Master node:
text
$ knife role show nodejs_postgresql_master
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: nodejs_postgresql_master
override_attributes:
run_list:
recipe[platformstack::default]
recipe[rackops_rolebook::default]
recipe[nodestack::postgresql_master]

PostgreSQL Slave node:
text
$ knife role show nodejs_postgresql_slave
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: nodejs_postgresql_slave
override_attributes:
run_list:
recipe[platformstack::default]
recipe[rackops_rolebook::default]
recipe[nodestack::postgresql_slave]

Cloud Monitoring

To enable monitoring you need to set node['platformstack']['cloud_monitoring']['enabled'] = true. This will setup the OS monitors like filesystem, CPU, memory, networking, etc.

To enable HTTP checks for a Node.js app deployed with Nodestack, set the node['nodestack']['cloud_monitoring']['remote_http']['disabled'] = false.

default['nodestack']['cloud_monitoring']['remote_http']['disabled'] Enable/disable remote HTTP monitoring.
default['nodestack']['cloud_monitoring']['remote_http']['alarm'] Enable/disable alarm notifications.
default['nodestack']['cloud_monitoring']['remote_http']['period'] Seconds value on how often the check will be performed.
default['nodestack']['cloud_monitoring']['remote_http']['timeout'] Seconds value on the timeout before the check fails.

New Relic Monitoring

To configure New Relic, make sure the node['newrelic']['license']
attribute is set and include the platformstack cookbook in your run_list.

New Relic monitoring plugins can be configured by including the newrelic::meetme-plugin
recipe in your run_list and setting the following attribute hash in an application
cookbook:

node.override['newrelic']['meetme-plugin']['services'] = {
  "memcached": {
    "name": "localhost",
    "host":  "host",
    "port":  11211
  },
  "elasticsearch": {
    "name": "clustername",
    "host": "localhost",
    "port": 9200
  }
}

More examples can be found here
and here.

Logrotate

logrotate is now enabled, by default, for customer app(forever.[log|out|err]) log files.
The logrotate recipe iterates over every item(app_name) in the node['nodestack']['apps_to_deploy'] list
and creates a configuration file. i.e /etc/logrotate.d/my_nodejs_app

NOTE: The logrotate recipe does not rotate custom log files, so make sure the customer's app uses STDOUT and STDERR.

Configuration examples can be found here
and here

Contributing

  • See the guide here

License and Authors

Copyright 2014, Rackspace, US Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

nodestack CHANGELOG

This file is used to list changes made in each version of the nodestack cookbook.

2.3.3

  • Marco Morales - Unpinned apache2 cookbook

2.3.2

  • Marco Morales - Rewrote the init script for CentOS 6, which was causing problems when stopping/restarting an app. Issue 164

2.3.1

  • Seandon Mooy - Added "open_files" option per-app to allow setting the "ulimit -n" value per application.

2.3.0

  • Marco Morales - Removed recipe import from platformstack.

2.2.1

  • Marco Morales - Pin the version of forever, 0.12.0 was causing restarts in CentOS 6.5 to fail.

2.2.0

  • @martinb3 - Move away from logstash_commons, just set attributes in case elkstack is present.

2.1.0

  • Marco Morales - Adding template variables to be available for the before_symlink_template.

2.0.0

  • Marco Morales - Decoupled forever from application_nodejs recipe to make nodestack more modular and add more deployment strategies in the future. The attribute node['nodestack']['apps']['my_nodejs_app']['deployment']['strategy'] = 'forever' will need to be set when updating to 2.0.0.

1.0.2

  • Marco Morales - Removed npm-install-retry since it's no longer being used. Resource nodejs_npm is used now.

1.0.1

  • Marco Morales - Added attribute app_config['deployment']['before_symlink_template'] that should have a template name to be called by the the before_symlink callback.

1.0.0

  • Marco Morales - Moved the demo attributes to recipes/demo.rb default['nodestack']['apps_to_deploy'] is no longer needed. It will deploy all the apps in the apps hash.

0.11.1

  • Marco Morales - Exposes the before_symlink attribute from the application resource.

0.11.0

  • Martin Smith - Added ELK stack logging customization for node and forever logs, if ELK stack is available through platformstack.

0.10.0

  • Marco Morales - Code deployment is now optional

0.9.8

  • Jacob Dearing - Expose git_submodule attribute for application resource call.

0.9.7

  • Marco Morales - Removed platformstack from Berksfile and fixed the new serverspec syntax.

0.9.5

  • Sheppy Reno - Added basic Chefspec for application_nodejs.rb

0.9.4

  • Marco Morales - Allow options to be passed to apps via forevers 'options'

0.9.3

  • John Schwinghammer - Updated cloud_monitoring recipe name

0.9.2

  • Sheppy Reno - Make npm options an attribute

0.9.1

  • Sheppy Reno - Set NPM to only pull in production dependencies for the application.

0.9.0

  • Bob Garza - Added logrotate recipe and included in application_nodejs.rb. Configures logrotate, by default, for daily rotation of forever.(err|out|log)

0.8.15

  • Sheppy Reno - Cleanup application_nodejs.rb

0.8.14

0.8.13

  • Marco Morales - Added support for CentOS 7.

0.8.12

  • Bob Garza - Forever logs are now being appended instead of being overwritten.

0.8.11

  • Sheppy Reno - Check for attributes prior to setting iptables rules. - Corrected some Rubocop warnings

0.8.10

  • Sheppy Reno - Prettify the config.js JSON

0.8.9

  • Marco Morales - Added HTTP monitor check

Check the Markdown Syntax Guide for help with Markdown.

The Github Flavored Markdown page describes the differences between markdown on github and standard markdown.

Foodcritic Metric
            

2.3.3 failed this metric

FC024: Consider adding platform equivalents: /tmp/cook/6965e8e945d4a331f31ffb93/nodestack/recipes/forever.rb:88
FC031: Cookbook without metadata file: /tmp/cook/6965e8e945d4a331f31ffb93/nodestack/metadata.rb:1
FC045: Consider setting cookbook name in metadata: /tmp/cook/6965e8e945d4a331f31ffb93/nodestack/metadata.rb:1