summaryrefslogtreecommitdiff
path: root/net-p2p/bitmark/files/recorderd.in
blob: f2728c9114a11fc31a741d9e7454ba4ad2977e96 (plain)
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
#!/bin/sh
# $FreeBSD$

# PROVIDE: recorderd
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable:
# recorderd_enable (bool)         Set to "NO" by default.
#                                 Set it to "YES" to enable recorderd
# recorderd_options (str)         Set to "" by default
# recorderd_user (str)            Set to "%%RECORDERD_USER%%" by default.
# recorderd_group (str)           Set to "%%RECORDERD_GROUP%%" by default.
# recorderd_config_file (str)     Set to "%%PREFIX%%/etc/${name}.conf" by default.
# recorderd_data_dir (str)        Set to "%%RECORDERD_DATA%%" by default.
# recorderd_run_dir (str)         Set to "%%RECORDERD_RUN%%" by default.
# recorderd_syslog_enable (bool)  Set to "NO" by default.
#                                 Set it to "YES" to enable syslog stdout/stderr
# recorderdlimits_enable (bool)   Set to "NO" by default.
#                                 Set it to "YES" to enable recorderdlimits
# recorderdlimits_args (str)      Set to "-e -U ${recorderd_user}" by default

. /etc/rc.subr

name="recorderd"
rcvar=recorderd_enable

load_rc_config ${name}

: ${recorderd_enable:="NO"}
: ${recorderd_options:=""}
: ${recorderd_user:="%%RECORDERD_USER%%"}
: ${recorderd_group:="%%RECORDERD_GROUP%%"}
: ${recorderd_config_file:="%%PREFIX%%/etc/${name}.conf"}
: ${recorderd_data_dir:="%%RECORDERD_DATA%%"}
: ${recorderd_run_dir:="%%RECORDERD_RUN%%"}
: ${recorderd_syslog_enable:="NO"}

: ${recorderdlimits_enable:="NO"}
: ${recorderdlimits_args:="-e -U ${recorderd_user}"}

start_precmd="${name}_precmd"
restart_precmd="${name}_checkconfig"
stop_postcmd="${name}_poststop"
keygen_cmd="${name}_keygen"
keygen_precmd="${name}_checkconfig"

extra_commands='keygen'

pidfile="${recorderd_run_dir}/${name}.pid"

# recorderd creates it own PID file so need to remove  if stale
lock_file="${recorderd_data_dir}/${name}.pid"

required_files="${recorderd_config_file}"

_recorderd_program="%%PREFIX%%/sbin/recorderd"
_recorderd_arguments="--quiet --config-file=${recorderd_config_file} ${recorderd_options}"

command="/usr/sbin/daemon"
command_args="-f"
checkyesno recorderd_syslog_enable && command_args="-S -T recorderd"
command_args="${command_args} -P ${pidfile} -R 60 -- ${_recorderd_program} ${_recorderd_arguments}"
#procname=${_recorderd_program} # do not override procname as program runs under daemon

# setup environment to reduce memory loading
export GODEBUG='madvdontneed=1'
export MALLOC_CONF='abort:true,narenas:1'

recorderd_checkdirs()
{
  local dir
  for dir in "${recorderd_data_dir}" "${recorderd_run_dir}"
  do
    [ -d "${dir}" ] || install -d -o "${recorderd_user}" -g "${recorderd_group}" -m 770 "${dir}"
  done
  cd "${recorderd_data_dir}"
}

recorderd_checkconfig()
{
  recorderd_checkdirs

  #echo "Performing sanity check on recorderd configuration:"
  #eval ${command} ${recorderd_flags} -t
}

recorderd_precmd()
{
  recorderd_checkconfig

  if [ -e "${lock_file}" ]
  then
    pid=$(check_pidfile "${lock_file}" "${_recorderd_program}")
    if [ -n "${pid}" ]
    then
      echo "another recorderd is running on pid: ${pid}"
    else
      rm -f "${lock_file}"
    fi
  fi

  if checkyesno recorderdlimits_enable
  then
    eval $(/usr/bin/limits ${recorderdlimits_args}) 2>/dev/null
  else
    return 0
  fi
}

recorderd_poststop()
{
    rm -f "${pidfile}"
    rm -f "${lock_file}"
}

recorderd_keygen()
{
  for c in generate-identity
  do
    su -m "${recorderd_user}" -c "${_recorderd_program} ${_recorderd_arguments} ${c} ${recorderd_data_dir}"
  done
}

run_rc_command "$1"