Skip to content

Instantly share code, notes, and snippets.

@c0psrul3
Last active January 18, 2017 00:40
Show Gist options
  • Save c0psrul3/210d255e389b195c4433238b1961bee1 to your computer and use it in GitHub Desktop.
Save c0psrul3/210d255e389b195c4433238b1961bee1 to your computer and use it in GitHub Desktop.
UniFi 5 start/stop script for OpenRC on TrueOS
#!/sbin/openrc-run
#
# Original Author: Mark Felder <[email protected]>
# Author: Mike N. <[email protected]>
# $FreeBSD$
#
# PROVIDE: unifi
# REQUIRE: LOGIN
# KEYWORD: shutdown
name=unifi
#rcvar=unifi_enable
#: ${unifi_enable:=NO}
: ${unifi_user:=unifi}
: ${unifi_group:=unifi}
: ${unifi_chdir=/usr/local/share/java/${name}}
: ${unifi_javaflags:="-Djava.awt.headless=true -Xmx1024M"}
piddir="/var/run/${name}"
pidfile="${piddir}/${name}.pid"
if [ -x /usr/local/openjdk8-jre/bin/java ] ; then
JREbin='/usr/local/openjdk8-jre/bin/java'
else
for _J in $(find /usr/local -type d -path "/usr/local/openjdk*" -name "bin" 2> /dev/null) ; do
if [ -x ${_J}/java ] ; then
Jbin="${_J}/java"
JREbin=$(echo ${Jbin} | grep "jre")
fi
done
fi
procname=${JREbin:-$Jbin}
command_args="${procname} ${unifi_javaflags} -jar lib/ace.jar start"
start() {
ebegin "Starting ${name}"
start-stop-daemon --start --progress --make-pidfile --background \
--user ${unifi_user}:${unifi_group} \
--chdir ${unifi_chdir} \
--pidfile ${pidfile} \
-- ${procname} ${unifi_javaflags} -jar lib/ace.jar start
eend $?
}
stop() {
ebegin "Stopping ${name}"
start-stop-daemon --stop --exec ${procname} \
--pidfile ${pidfile}
eend $?
}
start_pre()
{
if [ ! -e ${piddir} ] ; then
install -d -o ${unifi_user} -g ${unifi_group} ${piddir};
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment