Debian Wheezy and other systems using the SysV style init with extend LSB Headers as defined in Chapter 20 of the LSB 3.1 specification
This unit will discuss how to approach a Node.js deployment using Wheezys SysV Init and associated tools
- Old-style Init, configured with Bash scripts
- Init script handles lifecycle commands
- Extend specification to include process dependencies
- Monitoring and auto-restart requires /etc/inittab or an external tool such as Monit
- Starts the Node process
- Directs stdout/stderr to a log file
- Uses LSB functions and start-stop-daemon to manage process lifecycle
file:nodejs:#1
### BEGIN INIT INFO
# Provides: {{SERVICE_NAME}}
# Required-Start: $all
# Required-Stop: $all
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: A Node Service
# Description:
# SysV style init script with LSB header. For use on Debian Wheezy.
### END INIT INFO
Wheezy ships with built-in functions that manage the lifecycle of a process and help ensure LSB 3.1 conformance.
# Import lsb functions
. /lib/lsb/init-functions
# Functions now available:
# start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...]
# killproc [-p pidfile] pathname [signal]
# pidofproc [-p pidfile] pathname
# log_success_msg message
# log_failure_msg message
# log_warning_msg message
** NOT MINE FROM HERE DOWN **
fd exhaustion is covered in the resource management unit. init scripts are a good place to set ulimit if necessary.file:nodejs-init.sh:#3
- Send each instance a
SIGTERM
- After 10 seconds, send
SIGKILL
if still running
file:nodejs-init.sh:#5
file:nodejs-init.sh:#6
- Used here to help ensure process stays alive
- Can also monitor system resources such as file checksums and permissions
- Can set process restart triggers, alert triggers
- Works by polling
- Set a polling interval of one second
- Check each node process by its pidfile
# daemonize and set a polling interval of 1 second
set daemon 1
check process nodejs1 with pidfile /var/run/nodejs.pid.1
start program = "/etc/init.d/nodejs start"
stop program = "/etc/init.d/nodejs stop"
group nodejs
# ...repeat for each node instance
- Enterprise Linux 5 uses the SysV Init system based on Bash script configuration
- Init is only concerned with basic lifecycle commands, process monitoring is an external concern
- Use system tools such as Monit to monitor and restart processes when they die