summaryrefslogtreecommitdiffstats
path: root/net-mgmt/unifi3/files/unifi.in
blob: 99db99fb7c38dfbbfad4a0243eb2b6a936d70af9 (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
#!/bin/sh
#
# Created by: Mark Felder <feld@FreeBSD.org>
# $FreeBSD: head/net-mgmt/unifi/files/unifi.in 334865 2013-11-25 16:52:21Z feld $
#

# PROVIDE: unifi
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following line to /etc/rc.conf to enable `unifi':
#
# unifi_enable="YES"

. /etc/rc.subr
name=unifi

rcvar=unifi_enable
load_rc_config ${name}

: ${unifi_enable:=NO}
: ${unifi_user:=%%USERS%%}
: ${unifi_group:=%%GROUPS%%}
: ${unifi_chdir=%%JAVASHAREDIR%%/unifi}
: ${unifi_javaflags:="-Djava.awt.headless=true -Xmx1024M"}

command_interpreter=.
command="%%PREFIX%%/bin/java"
command_args="${unifi_javaflags} -jar lib/ace.jar"
start_cmd=start_cmd
start_precmd=start_precmd
stop_cmd=stop_cmd
status_cmd=status_cmd
pidfile="/var/run/${name}.pid"

procname=$(JAVAVM_DRYRUN=yes ${command} | fgrep JAVAVM_COMMAND)

start_precmd()
{
	if [ ! -e /var/run/unifi ] ; then
		install -d -o %%USERS%% -g %%GROUPS%% /var/run/unifi;
	fi
}

start_cmd()
{
	check_startmsgs && echo "Starting ${name}."
	cd ${unifi_chdir}
	daemon -u %%USERS%% -f -p ${pidfile} ${command} ${command_args} start
}

stop_cmd()
{
	check_startmsgs && echo "Stopping ${name}."
	rc_pid=$(check_pidfile $pidfile $procname)
	cd ${unifi_chdir}
	${command} ${command_args} stop
	wait_for_pids $rc_pid
}

status_cmd()
{
	if [ -e ${pidfile} ] && $(pgrep -F ${pidfile} > /dev/null) ; then
                mypid=$(cat ${pidfile})
	fi

        if [ ! ${mypid} = '' ]; then
                echo "${name} is running with PID ${mypid}.";
        else
                echo "${name} not running?";
        fi
}

run_rc_command "$1"
OpenPOWER on IntegriCloud