Skip to content

Commit 6e71846

Browse files
author
olevole
committed
add rc.d
1 parent ecbf052 commit 6e71846

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.idea/
2-
src
3-
cbsd-mq-router
4-
log
2+
./src
3+
./cbsd-mq-router
4+
./log

rc.d/cbsd-mq-router

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/sh
2+
3+
# PROVIDE: cbsd_mq_router
4+
# REQUIRE: NETWORK
5+
# BEFORE: DAEMON
6+
7+
. /etc/rc.subr
8+
9+
name="cbsd_mq_router"
10+
desc="CBSD K8S API Module"
11+
rcvar="cbsd_mq_router_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_router.log"
16+
extra_commands="reload"
17+
command="/usr/local/sbin/cbsd-mq-router"
18+
cbsd_mq_router_user=${cbsd_mq_router_user-"nobody"}
19+
cbsd_mq_router_config=${cbsd_mq_router_config-"/usr/local/etc/cbsd-mq-router.json"}
20+
required_files="${cbsd_mq_router_config}"
21+
22+
cbsd_mq_router_args=${cbsd_mq_router_args-"-config ${cbsd_mq_router_config}"}
23+
24+
load_rc_config ${name}
25+
26+
start_cmd="start"
27+
stop_cmd="stop"
28+
status_cmd="status"
29+
reload_cmd="reload"
30+
31+
stop()
32+
{
33+
if [ -f "${daemon_pidfile}" ]; then
34+
pids=$( pgrep -F ${daemon_pidfile} 2>&1 )
35+
_err=$?
36+
[ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${daemon_pidfile}
37+
fi
38+
if [ -f "${pidfile}" ]; then
39+
pids=$( pgrep -F ${pidfile} 2>&1 )
40+
_err=$?
41+
[ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${pidfile}
42+
fi
43+
}
44+
45+
start()
46+
{
47+
[ ! -d ${logdir} ] && mkdir -p ${logdir}
48+
touch ${logfile}
49+
chown ${cbsd_mq_router_user} ${logdir} ${logfile}
50+
/usr/sbin/daemon -u ${cbsd_mq_router_user} -f -R5 -p ${pidfile} -P ${daemon_pidfile} -o ${logfile} ${command} ${cbsd_mq_router_args}
51+
}
52+
53+
reload()
54+
{
55+
stop
56+
start
57+
}
58+
59+
status()
60+
{
61+
if [ -f "${pidfile}" ]; then
62+
pids=$( pgrep -F ${pidfile} 2>&1 )
63+
_err=$?
64+
if [ ${_err} -eq 0 ]; then
65+
echo "${name} is running as pid ${pids}"
66+
exit 0
67+
else
68+
echo "wrong pid: ${pids}"
69+
exit 1
70+
fi
71+
else
72+
echo "no pidfile $pidfile"
73+
exit 1
74+
fi
75+
}
76+
77+
run_rc_command "$1"

0 commit comments

Comments
 (0)