• Stars
    star
    781
  • Rank 58,232 (Top 2 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 12 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Startup script for Linux-based systems for running node app when rebooting using an /etc/init.d script.

node-startup

Startup script for Linux-based systems for running a Node.js app when rebooting, using an /etc/init.d script.

Looking for a maintainer

If you use node-startup and would like to be a maintainer, send me a message.

Installation

Clone the repo:

git clone https://github.com/chovy/node-startup.git
cd node-startup/init.d

Edit the node-app script with your settings from the Configuration section, then follow instructions in the Running section.

Configuration

At the top of the node-app file, a few items are declared which are either passed to the Node.js app or used for general execution/management.

Node.js Config

The items declared and passed to the Node.js application are:

  • NODE_ENV - the type of environment - development, production, etc. - can be read by the application to do things conditionally (defaults to "production")
  • PORT - the port that the Node.js application should listen on - should be read by the application and used when starting its server (defaults to "3000")
  • CONFIG_DIR - used for node-config (defaults to "$APP_DIR"); is required, but should be kept as the default if not needed

Execution Config

The items declared and used by the overall management of executing the application are:

  • NODE_EXEC - location of the Node.js package executable - useful to set if the executable isn't on your PATH or isn't a service (defaults to $(which node))
  • APP_DIR - location of the Node.js application directory (defaults to "/var/www/example.com")
  • NODE_APP - filename of the Node.js application (defaults to "app.js")
  • PID_DIR - location of the PID directory (defaults to "$APP_DIR/pid")
  • PID_FILE - name of the PID file (defaults to "$PID_DIR/app.pid")
  • LOG_DIR - location of the log (Node.js application output) directory (defaults to "$APP_DIR/log")
  • LOG_FILE - name of the log file (defaults to "$LOG_DIR/app.log")
  • APP_NAME - name of the app for display and messaging purposes (defaults to "Node app")

Available Actions

The service exposes 4 actions:

  • start - starts the Node.js application
  • stop - stops the Node.js application
  • restart - stops the Node.js application, then starts the Node.js application
  • status - returns the current running status of the Node.js application (based on the PID file and running processes)

Testing

Test that it all works:

/etc/init.d/node-app start
/etc/init.d/node-app status
/etc/init.d/node-app restart
/etc/init.d/node-app stop

Add node-app to the default runlevels:

# Debian
update-rc.d node-app defaults
# RHEL, --del to remove
chkconfig --add node-app

Finally, reboot to be sure the Node.js application starts automatically:

Force Action## Why node-startup?

When my VPS was rebooted occassionally by the hosting provider, my Node.js app was not coming back online after boot. This script can be used in /etc/init.d, which will allow rc.d to restart your app when the machine reboots without your knowledge.

If you are using MongoDB, Redis, or Nginx, you want to add those to your default run-level as well.

Running

Copy the startup script node-app to your /etc/init.d directory:

sudo bash -l
cp ./init.d/node-app /etc/init.d/

In addition to the start, stop, and restart actions, a --force option can be added to the execution so that the following scenarios have the following outcomes:

  • start - PID file exists but application is stopped -> removes PID file and starts the application

  • stop - PID file exists but application is stopped -> removes PID file

  • restart - either of the above scenarios occur

    sudo reboot

Supported OS

Tested with Debian 6.0, but it should work on other Linux systems that use startup scripts in /etc/init.d (Red Hat, CentOS, Gentoo, Ubuntu, etc.).

LICENSE

(The MIT License)

Bitdeli Badge

More Repositories

1

humanparser

Parse a human name string into salutation, first name, middle name, last name, suffix.
JavaScript
87
star
2

app-notify

Send SMS and email notifications from within your node.js app
JavaScript
81
star
3

express-template-demo

Demo of using template engines with express.js and node.js
JavaScript
77
star
4

nodejs-stream

A nodejs backend for social network streams using a server sent event stream.
JavaScript
46
star
5

offline-app

Offline application that uses an appcache manifest file and localStorage for images and data.
JavaScript
29
star
6

bmr

Bmr - the Bitmessage reader, a bitmessage client with a better experience.
JavaScript
24
star
7

tabbed-navigation

jQuery.tabbed() navigation is a light-weight jQuery plugin for handling tabbed navigation with minimal markup.
CSS
24
star
8

git-deploy-node

Deploy a node app using git for continuous deployment.
Shell
23
star
9

hour-of-code

Hour of code examples with my kids
JavaScript
17
star
10

shapeshift

shapeshift.io api for node.js
JavaScript
12
star
11

techan-vue

Example of using techanjs with vue.js
JavaScript
8
star
12

express-force-domain

Force express 3.x to use a specific domain. Good for adding or removing www. and handling parked domains that redirect to your main domain.
JavaScript
7
star
13

reddit-eraser

Erase your reddit comment history (then delete them).
JavaScript
7
star
14

crypto-icons

Crypto currency icons, including font icon files.
CSS
7
star
15

angular-html5-storage

HTML5 web storage for Angular.js
JavaScript
5
star
16

getbypath

Get JSON data by path
JavaScript
5
star
17

reddit-rss-submit

Submit RSS links to Reddit.
JavaScript
3
star
18

page-updated

Send an email notification when a page on the Internet changes.
Shell
2
star
19

blockchain-in-javascript

Blockchain in JavaScript - code from Udemy course
JavaScript
2
star
20

kimsufi-alert

Kimsufi alert will send you an email or SMS when an OVH kimsufi server is available for purchase.
JavaScript
1
star
21

getrandomdate

Get a random date for a given time-frame in JSON, XML, or CSV format.
JavaScript
1
star
22

sheetjs-svelte

svelte demo for sheetjs
Svelte
1
star
23

torus-bufer

JavaScript
1
star
24

KODI-Popcorn-Time

With KODI Popcorn Time you can search for movies that you can see immediately in KODI.
Python
1
star