machine_setup/router/unifi_rc.bash

48 lines
1.1 KiB
Bash
Raw Normal View History

2024-01-09 22:31:12 +00:00
#!/bin/sh
#
# REQUIRE: FILESYSTEMS kld
# PROVIDE: unifi
# BEFORE: netif
. /etc/rc.subr
2024-07-06 18:43:37 +00:00
name=unifi
2024-01-09 22:31:12 +00:00
rcvar=${name}_enable
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
load_rc_config $name
tmux_name="unifi"
2024-07-06 18:43:37 +00:00
unifi_start() {
/usr/local/bin/tmux new-session -d -s "$tmux_name" "/usr/bin/env VNC_ENABLE=YES VNC_LISTEN=0.0.0.0:5900 /usr/local/bin/bash /home/talexander/launch_unifi.bash"
# /usr/local/bin/tmux new-session -d -s "$tmux_name" "/usr/bin/env VNC_ENABLE=NO VNC_LISTEN=0.0.0.0:5900 /usr/local/bin/bash /home/talexander/launch_unifi.bash"
2024-01-09 22:31:12 +00:00
}
2024-07-06 18:43:37 +00:00
unifi_status() {
2024-01-09 22:31:12 +00:00
if /usr/local/bin/tmux has-session -t $tmux_name 2>/dev/null; then
echo "$tmux_name is running."
else
echo "$tmux_name is not running."
return 1
fi
}
2024-07-06 18:43:37 +00:00
unifi_stop() {
2024-01-09 22:31:12 +00:00
/usr/local/bin/tmux has-session -t $tmux_name 2>/dev/null && (
/usr/local/bin/tmux kill-session -t $tmux_name
sleep 10
bhyvectl --vm=unifi --destroy
2024-07-06 18:43:37 +00:00
# kill `cat /var/run/unifi.pid`
2024-01-09 22:31:12 +00:00
)
2024-07-06 18:43:37 +00:00
unifi_wait_for_end
2024-01-09 22:31:12 +00:00
}
2024-07-06 18:43:37 +00:00
unifi_wait_for_end() {
2024-01-09 22:31:12 +00:00
while /usr/local/bin/tmux has-session -t $tmux_name 2>dev/null; do
sleep 1
done
}
run_rc_command "$1"