Skip to content

Instantly share code, notes, and snippets.

@apearson

apearson/node-red

Last active Nov 23, 2020
Embed
What would you like to do?
Node-RED FreeBSD RC Script
#!/bin/sh
#
# PROVIDE: nodered
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Author: Andrew Pearson (apearson.io)
# Version: 1.0.2
# Description:
# This script runs Node-RED as a service under the supplied user on boot
# How to use:
# Place this file in /usr/local/etc/rc.d/
# Add nodered_enable="YES" to /etc/rc.config
# (Optional) To run as non-root, add nodered_runAs="node-red" to /etc/rc.config
# (Optional) To pass Node-RED args, add nodered_args="" to /etc/rc.config
# Freebsd rc library
. /etc/rc.subr
# General Info
name="nodered" # Safe name of program
program_name="node-red" # Name of exec
title="Node-RED" # Title to display in top/htop
# RC.config vars
load_rc_config $name # Loading rc config vars
: ${nodered_enable="NO"} # Default: Do not enable Node-RED
: ${nodered_runAs="root"} # Default: Run Node-RED as root
# Freebsd Setup
rcvar=nodered_enable # Enables the rc.conf YES/NO flag
pidfile="/var/run/${program_name}.pid" # File that allows the system to keep track of node-red status
# Env Setup
export HOME=$( getent passwd "$nodered_runAs" | cut -d: -f6 ) # Gets the home directory of the runAs user
# Command Setup
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
# Command
command="/usr/sbin/daemon"
command_args="-r -t ${title} -u ${nodered_runAs} -o ${output_file} -P ${pidfile} ${exec_path} ${nodered_args}"
# Loading Config
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