|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# PROVIDE: cbsd_mq_api |
| 4 | +# REQUIRE: NETWORK |
| 5 | +# BEFORE: DAEMON |
| 6 | + |
| 7 | +. /etc/rc.subr |
| 8 | + |
| 9 | +name="cbsd_mq_api" |
| 10 | +desc="CBSD cbsd API Module" |
| 11 | +rcvar="cbsd_mq_api_enable" |
| 12 | +pidfile="/var/run/${name}.pid" |
| 13 | +daemon_pidfile="/var/run/${name}-daemon.pid" |
| 14 | +logdir="/var/log/${name}" |
| 15 | +logfile="${logdir}/cbsd_mq_api.log" |
| 16 | +extra_commands="reload" |
| 17 | +command="/usr/local/bin/cbsd-mq-api" |
| 18 | +cbsd_mq_api_user=${cbsd_mq_api_user-"cbsd"} |
| 19 | +cbsd_mq_api_config=${cbsd_mq_api_config-"/usr/local/etc/cbsd-mq-api.json"} |
| 20 | +required_files="${cbsd_mq_api_config}" |
| 21 | + |
| 22 | +cbsd_mq_api_args=${cbsd_mq_api_args-"-config ${cbsd_mq_api_config}"} |
| 23 | +cbsd_mq_api_flags=${cbsd_mq_api_flags="-listen 127.0.0.1:65531"} |
| 24 | + |
| 25 | +load_rc_config ${name} |
| 26 | + |
| 27 | +start_cmd="start" |
| 28 | +stop_cmd="stop" |
| 29 | +status_cmd="status" |
| 30 | +reload_cmd="reload" |
| 31 | + |
| 32 | +stop() |
| 33 | +{ |
| 34 | + if [ -f "${daemon_pidfile}" ]; then |
| 35 | + pids=$( pgrep -F ${daemon_pidfile} 2>&1 ) |
| 36 | + _err=$? |
| 37 | + [ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${daemon_pidfile} |
| 38 | + fi |
| 39 | + if [ -f "${pidfile}" ]; then |
| 40 | + pids=$( pgrep -F ${pidfile} 2>&1 ) |
| 41 | + _err=$? |
| 42 | + [ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${pidfile} |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +start() |
| 47 | +{ |
| 48 | + [ ! -d ${logdir} ] && mkdir -p ${logdir} |
| 49 | + touch ${logfile} |
| 50 | + chown ${cbsd_mq_api_user} ${logdir} ${logfile} |
| 51 | + /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} |
| 52 | +} |
| 53 | + |
| 54 | +reload() |
| 55 | +{ |
| 56 | + stop |
| 57 | + start |
| 58 | +} |
| 59 | + |
| 60 | +status() |
| 61 | +{ |
| 62 | + if [ -f "${pidfile}" ]; then |
| 63 | + pids=$( pgrep -F ${pidfile} 2>&1 ) |
| 64 | + _err=$? |
| 65 | + if [ ${_err} -eq 0 ]; then |
| 66 | + echo "${name} is running as pid ${pids}" |
| 67 | + exit 0 |
| 68 | + else |
| 69 | + echo "wrong pid: ${pids}" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + else |
| 73 | + echo "no pidfile $pidfile" |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | +} |
| 77 | + |
| 78 | +run_rc_command "$1" |
0 commit comments