#!/bin/sh # PROVIDE: cbsd_mq_api # REQUIRE: NETWORK # BEFORE: DAEMON . /etc/rc.subr name="cbsd_mq_api" desc="CBSD API Module" rcvar="cbsd_mq_api_enable" pidfile="/var/run/${name}.pid" daemon_pidfile="/var/run/${name}-daemon.pid" logdir="/var/log/${name}" logfile="${logdir}/cbsd_mq_api.log" extra_commands="reload" command="%%PREFIX%%/bin/cbsd-mq-api" cbsd_mq_api_user=${cbsd_mq_api_user-"cbsd"} cbsd_mq_api_config=${cbsd_mq_api_config-"%%PREFIX%%/etc/cbsd-mq-api.json"} required_files="${cbsd_mq_api_config}" cbsd_mq_api_args=${cbsd_mq_api_args-"-config ${cbsd_mq_api_config}"} # ACL flags sample: #cbsd_mq_api_flags="-listen 127.0.0.1:65531 -allowlist %%PREFIX%%/etc/cbsd-mq-api.allow" cbsd_mq_api_flags=${cbsd_mq_api_flags="-listen 127.0.0.1:65531"} load_rc_config ${name} start_cmd="start" stop_cmd="stop" status_cmd="status" reload_cmd="reload" stop() { if [ -f "${daemon_pidfile}" ]; then pids=$( pgrep -F ${daemon_pidfile} 2>&1 ) _err=$? [ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${daemon_pidfile} fi if [ -f "${pidfile}" ]; then pids=$( pgrep -F ${pidfile} 2>&1 ) _err=$? [ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${pidfile} fi } start() { [ ! -d ${logdir} ] && mkdir -p ${logdir} touch ${logfile} chown ${cbsd_mq_api_user} ${logdir} ${logfile} /usr/sbin/daemon -u ${cbsd_mq_api_user} -f -R5 -p ${pidfile} -P ${daemon_pidfile} -o ${logfile} ${command} ${cbsd_mq_api_args} ${cbsd_mq_api_flags} } reload() { stop start } status() { if [ -f "${pidfile}" ]; then pids=$( pgrep -F ${pidfile} 2>&1 ) _err=$? if [ ${_err} -eq 0 ]; then echo "${name} is running as pid ${pids}" exit 0 else echo "wrong pid: ${pids}" exit 1 fi else echo "no pidfile $pidfile" exit 1 fi } run_rc_command "$1"