aboutsummaryrefslogtreecommitdiff
path: root/sysutils/nomad/files/nomad.in
blob: 0a741a550c1bbe005e7f9fb4173c9fa67d7c37b7 (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
#!/bin/sh

# PROVIDE: nomad
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# nomad_enable (bool):      Set to NO by default.
#                               Set it to YES to enable nomad.
# nomad_debug (bool):       Set to NO by default.
#                               Set it to YES to enable nomad debugging to syslog.
# nomad_user (user):        Set user to run nomad.
#                               Default is "nomad".
# nomad_group (group):      Set group to run nomad.
#                               Default is "nomad".
# nomad_dir (dir):          Set dir to run nomad in.
#                               Default is "/var/tmp/nomad".
# nomad_env (dir):          Set environment variables used with nomad
#                               Default is "".
# nomad_mode (mode):        Set the nomad mode to be used
#                               Default is "agent".
# nomad_args (args):        Set arguments to be passed to nomad
#                               Default is "-data-dir=${nomad_dir}".

. /etc/rc.subr

name=nomad
rcvar=nomad_enable

load_rc_config $name

: ${nomad_enable:="NO"}
: ${nomad_debug:="NO"}
: ${nomad_user:="nomad"}
: ${nomad_group:="nomad"}
: ${nomad_dir:="/var/tmp/nomad"}
: ${nomad_env:=""}
: ${nomad_mode:="agent"}
: ${nomad_args:="-data-dir=${nomad_dir}"}

pidfile=/var/run/nomad.pid
procname="%%PREFIX%%/bin/nomad"
command="/usr/sbin/daemon"
extra_commands="reload"
nomad_command="/usr/bin/env ${nomad_env} ${procname} ${nomad_mode} ${nomad_args}"
command_args="-f -t ${name} -p ${pidfile} ${nomad_command}"

start_precmd=nomad_startprecmd

nomad_startprecmd()
{
	if [ ! -e ${pidfile} ]; then
		install -o ${nomad_user} -g ${nomad_group} /dev/null ${pidfile};
	fi

	if [ ! -d "${nomad_dir}" ]; then
		install -d -o ${nomad_user} -g ${nomad_group} "${nomad_dir}"
		chmod 0700 "${nomad_dir}"
	fi

	if [ "${nomad_debug}" != "NO" ]; then
		command_args="-T ${name} ${command_args}"
	fi

	if [ "$(stat -f "%Lp" "${nomad_dir}")" -ne "700" ]; then
		2>&1 echo "Error: File permissions of ${nomad_dir} must be 700, not starting."
		exit 1
	fi
}

run_rc_command "$1"