Skip to content

Instantly share code, notes, and snippets.

@tspspi
Created February 29, 2020 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspspi/ee03afad146cbd72298ffbf56d602dc9 to your computer and use it in GitHub Desktop.
Save tspspi/ee03afad146cbd72298ffbf56d602dc9 to your computer and use it in GitHub Desktop.
FreeBSD NodeRED rc.d init script
#!/bin/sh
#
# PROVIDE: nodered
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Configuration variables:
#
# Variable Default Description
# ====================================================================================================
# nodered_enable NO Can be YES or NO to enable or disable automatic launch of nodered on boot.
# nodered_user nodered Specifies the user that should be used to run nodered.
# nodered_args Additional arguments
#
# PID-File: /var/run/nodered.pid
# LOG-File: /var/log/nodered.log (Should be added to /etc/newsyslog.conf)
#
# Usage: Copy to /usr/local/etc/rc.d/nodered
. /etc/rc.subr
# Specify some core information
name="nodered"
program_name="node-red"
title="NodeRED"
load_rc_config ${name}
: ${nodered_enable="NO"}
: ${nodered_user="nodered"}
rcvar=nodered_enable
# Determine HOME directory to be set for daemon
export HOME=$( getent passwd "$nodered_user" | cut -d: -f6 )
# Some other properties for node
exec_path="/usr/local/bin/${program_name}" # Path to the node-red exec, /usr/local/bin/ when installed globally
output_file="/var/log/${program_name}.log" # Path to Node-RED output file
pidfile=/var/run/${program_name}.pid
# We'll use "daemon" to run nodered in background ...
command="/usr/sbin/daemon"
command_args="-r -t ${title} -u ${nodered_user} -o ${output_file} -P ${pidfile} ${exec_path} ${nodered_args}"
# Execute rc.d script commands
load_rc_config ${name}
run_rc_command "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment