blob: 9d7615ccba0b45a9cd8247307190f875c2732206 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#!/bin/sh
# PROVIDE: greptimedb
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to run greptimedb:
#
# greptimedb_profiles (str): Set to "" by default.
# Define your profiles here.
# greptimedb(_profile)?_enable (bool): Set it to "YES" to enable greptimedb.
# Default is "NO".
# greptimedb(_profile)?_args (flags): Set extra args here. More options in greptimedb(1)
# Default is "--log-dir=/var/log/greptimedb --log-level=info \
# standalone start -c %%ETCDIR%%/standalone.toml"
# for the 'standalone' mode.
# greptimedb(_profile)?_user (user): Set user to run greptimedb.
# Default is "%%USER%%".
# greptimedb(_profile)?_group (group): Set group to run greptimedb.
# Default is "%%GROUP%%".
# greptimedb(_profile)?_post_start (str): Set extra commands that should be executed after greptimedb was successfully
# started here.
# Default is empty "".
. /etc/rc.subr
name="greptimedb"
rcvar=greptimedb_enable
_piddir="/var/run/greptimedb"
pidfile="${_piddir}/greptimedb.pid"
: ${greptimedb_enable="NO"}
: ${greptimedb_user="%%USER%%"}
: ${greptimedb_group="%%GROUP%%"}
: ${greptimedb_args="--log-dir=/var/log/greptimedb --log-level=info standalone start -c %%ETCDIR%%/standalone.toml"} # standalone mode
load_rc_config ${name}
if [ -n "$2" ]; then # profile is provided
profile="$2"
if [ -n "${greptimedb_profiles}" ]; then
pidfile="${_piddir}/greptimedb.${profile}.pid"
eval greptimedb_enable="\${greptimedb_${profile}_enable:-${greptimedb_enable}}"
eval greptimedb_user="\${greptimedb_${profile}_user:-${greptimedb_user}}"
eval greptimedb_group="\${greptimedb_${profile}_group:-${greptimedb_group}}"
eval greptimedb_args="\${greptimedb_${profile}_args:-${greptimedb_args}}"
eval greptimedb_post_start="\${greptimedb_${profile}_post_start:-${greptimedb_post_start}}"
else
echo "%%PREFIX%%/etc/rc.d/greptimedb: extra argument ignored"
fi
else # profile is not provided
if [ -n "${greptimedb_profiles}" -a -n "$1" ]; then
for profile in ${greptimedb_profiles}; do
eval _enable="\${greptimedb_${profile}_enable}"
case "${_enable:-${greptimedb_enable}}" in
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
continue
;;
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
;;
*)
if test -z "$_enable"; then
_var=greptimedb_enable
else
_var=greptimedb_"${profile}"_enable
fi
warn \
"Bad value" \
"'${_enable:-${greptimedb_enable}}'" \
"for ${_var}. " \
"Profile ${profile} skipped."
continue
;;
esac
echo "===> greptimedb profile: ${profile}"
if %%PREFIX%%/etc/rc.d/greptimedb $1 ${profile} ; then
success="${profile} ${success:-}"
else
failed="${profile} (${retcode}) ${failed:-}"
fi
done
exit 0
fi
fi
greptimedb_poststart()
{
if [ -n "$greptimedb_post_start" ]; then
eval $greptimedb_post_start
fi
}
greptimedb_poststop()
{
if [ -n "${profile}" ]; then
[ -e "$pidfile" ] && unlink $pidfile
else
local file
for file in ${_piddir}/* ; do
case "$file" in
*\*)
continue ;;
esac
unlink $file
done
fi
}
_profsuffx=""
if [ -n "${profile}" ]; then
_profsuffx="-${profile}"
fi
procname=%%PREFIX%%/bin/greptime
command="/usr/sbin/daemon"
command_args="-f -S -p ${pidfile} \
-t greptimedb${_profsuffx} \
%%PREFIX%%/bin/greptime $greptimedb_args"
start_precmd="install -d -o $greptimedb_user -g $greptimedb_group -m 755 $_piddir"
start_postcmd="${name}_poststart"
stop_postcmd="${name}_poststop"
run_rc_command "$1"
|