machine_setup/router/mediamtx_rc.bash

49 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2024-07-06 18:43:37 +00:00
#!/bin/sh
#
# PROVIDE: mediamtx
2024-07-07 22:09:15 +00:00
# REQUIRE: LOGIN opnsense
# KEYWORD: shutdown
2024-07-06 18:43:37 +00:00
. /etc/rc.subr
2024-07-07 22:09:15 +00:00
2024-07-06 18:43:37 +00:00
name=mediamtx
rcvar=${name}_enable
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
load_rc_config $name
tmux_name="mediamtx"
mediamtx_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_mediamtx.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_mediamtx.bash"
}
mediamtx_status() {
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
}
mediamtx_stop() {
/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=mediamtx --destroy
# kill `cat /var/run/mediamtx.pid`
)
mediamtx_wait_for_end
}
mediamtx_wait_for_end() {
while /usr/local/bin/tmux has-session -t $tmux_name 2>dev/null; do
sleep 1
done
}
run_rc_command "$1"