Skip to content

Commit b4dd2c0

Browse files
committed
feat: freebsd / starup script
1 parent 13f7371 commit b4dd2c0

File tree

8 files changed

+222
-105
lines changed

8 files changed

+222
-105
lines changed

scripts/FreeBSD/bin/reload

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/FreeBSD/bin/start

Lines changed: 0 additions & 13 deletions
This file was deleted.

scripts/FreeBSD/bin/start_homekit

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
# ConsonXP HomeKit start script
4+
# Called by daemon from rc.d/consonxp_homekit
5+
# Runs inside tmux for easy attach/debug
6+
7+
basedir="${CONSONXP_CHDIR:-/usr/local/consonxp}"
8+
config="${CONSONXP_CONFIG:-cli-xp130.yml}"
9+
pidfile="${CONSONXP_PIDFILE:-/var/run/consonxp/homekit.pid}"
10+
session="consonxp_homekit"
11+
12+
cd "${basedir}" || exit 1
13+
. ./venv/bin/activate
14+
cd src || exit 1
15+
16+
# Kill existing session if any
17+
tmux kill-session -t "${session}" 2>/dev/null
18+
19+
# Start new detached tmux session
20+
tmux new-session -d -s "${session}" "xp --pid-file=${pidfile} --cli-config=${config} term homekit"
21+
22+
# Wait for tmux session to end (keeps daemon alive)
23+
while tmux has-session -t "${session}" 2>/dev/null; do
24+
sleep 5
25+
done
26+
27+
# Session ended, exit (daemon -r will restart)
28+
exit 1

scripts/FreeBSD/bin/start_protocol

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
# ConsonXP Protocol Monitor start script
4+
# Called by daemon from rc.d/consonxp_protocol
5+
# Runs inside tmux for easy attach/debug
6+
7+
basedir="${CONSONXP_CHDIR:-/usr/local/consonxp}"
8+
config="${CONSONXP_CONFIG:-cli-xp230.yml}"
9+
pidfile="${CONSONXP_PIDFILE:-/var/run/consonxp/protocol.pid}"
10+
session="consonxp_protocol"
11+
12+
cd "${basedir}" || exit 1
13+
. ./venv/bin/activate
14+
cd src || exit 1
15+
16+
# Kill existing session if any
17+
tmux kill-session -t "${session}" 2>/dev/null
18+
19+
# Start new detached tmux session
20+
tmux new-session -d -s "${session}" "xp --pid-file=${pidfile} --cli-config=${config} term protocol"
21+
22+
# Wait for tmux session to end (keeps daemon alive)
23+
while tmux has-session -t "${session}" 2>/dev/null; do
24+
sleep 5
25+
done
26+
27+
# Session ended, exit (daemon -r will restart)
28+
exit 1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ConsonXP FreeBSD rc.conf configuration
2+
# Copy to /etc/rc.conf.d/consonxp or add to /etc/rc.conf
3+
4+
# Enable services
5+
consonxp_protocol_enable="YES"
6+
consonxp_homekit_enable="YES"
7+
8+
# Protocol service configuration (optional overrides)
9+
#consonxp_protocol_chdir="/usr/local/consonxp"
10+
#consonxp_protocol_pidfile="/var/run/consonxp/protocol.pid"
11+
#consonxp_protocol_log="/var/log/consonxp/protocol.log"
12+
#consonxp_protocol_user="consonxp"
13+
#consonxp_protocol_config="cli-xp230.yml"
14+
15+
# Homekit service configuration (optional overrides)
16+
#consonxp_homekit_chdir="/usr/local/consonxp"
17+
#consonxp_homekit_pidfile="/var/run/consonxp/homekit.pid"
18+
#consonxp_homekit_log="/var/log/consonxp/homekit.log"
19+
#consonxp_homekit_user="consonxp"
20+
#consonxp_homekit_config="cli-xp130.yml"

scripts/FreeBSD/rc.d/consonxp

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
3+
# PROVIDE: consonxp_homekit
4+
# REQUIRE: LOGIN DAEMON NETWORKING FILESYSTEMS netif routing defaultroute
5+
# BEFORE: securelevel
6+
# KEYWORD: jail python
7+
8+
. /etc/rc.subr
9+
10+
name="consonxp_homekit"
11+
12+
rcvar=${name}_enable
13+
14+
# Default values (before load_rc_config to allow overrides)
15+
: ${consonxp_homekit_enable="NO"}
16+
: ${consonxp_homekit_chdir="/usr/local/consonxp"}
17+
: ${consonxp_homekit_pidfile="/var/run/consonxp/homekit.pid"}
18+
: ${consonxp_homekit_log="/var/log/consonxp/homekit.log"}
19+
: ${consonxp_homekit_user="consonxp"}
20+
: ${consonxp_homekit_config="cli-xp130.yml"}
21+
22+
load_rc_config $name
23+
24+
pidfile="${consonxp_homekit_pidfile}"
25+
26+
start_cmd="${name}_start"
27+
stop_cmd="${name}_stop"
28+
status_cmd="${name}_status"
29+
30+
consonxp_homekit_start()
31+
{
32+
# Create directories with correct ownership
33+
mkdir -p "$(dirname ${consonxp_homekit_pidfile})"
34+
chown "${consonxp_homekit_user}:${consonxp_homekit_user}" "$(dirname ${consonxp_homekit_pidfile})"
35+
mkdir -p "$(dirname ${consonxp_homekit_log})"
36+
chown "${consonxp_homekit_user}:${consonxp_homekit_user}" "$(dirname ${consonxp_homekit_log})"
37+
38+
echo "Starting ${name}."
39+
CONSONXP_CHDIR="${consonxp_homekit_chdir}" \
40+
CONSONXP_CONFIG="${consonxp_homekit_config}" \
41+
CONSONXP_PIDFILE="${consonxp_homekit_pidfile}" \
42+
/usr/sbin/daemon -u "${consonxp_homekit_user}" \
43+
-o "${consonxp_homekit_log}" \
44+
-r \
45+
"${consonxp_homekit_chdir}/bin/start_homekit"
46+
}
47+
48+
consonxp_homekit_stop()
49+
{
50+
if [ -f "${consonxp_homekit_pidfile}" ]; then
51+
echo "Stopping ${name}."
52+
kill -TERM $(cat "${consonxp_homekit_pidfile}") 2>/dev/null
53+
rm -f "${consonxp_homekit_pidfile}"
54+
else
55+
echo "${name} is not running."
56+
fi
57+
}
58+
59+
consonxp_homekit_status()
60+
{
61+
if [ -f "${consonxp_homekit_pidfile}" ]; then
62+
pid=$(cat "${consonxp_homekit_pidfile}")
63+
if ps -p ${pid} > /dev/null 2>&1; then
64+
echo "${name} is running (PID ${pid})."
65+
else
66+
echo "${name} is not running (stale PID file)."
67+
fi
68+
else
69+
echo "${name} is not running."
70+
fi
71+
}
72+
73+
run_rc_command "$1"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
3+
# PROVIDE: consonxp_protocol
4+
# REQUIRE: LOGIN DAEMON NETWORKING FILESYSTEMS netif routing defaultroute
5+
# BEFORE: securelevel
6+
# KEYWORD: jail python
7+
8+
. /etc/rc.subr
9+
10+
name="consonxp_protocol"
11+
12+
rcvar=${name}_enable
13+
14+
# Default values (before load_rc_config to allow overrides)
15+
: ${consonxp_protocol_enable="NO"}
16+
: ${consonxp_protocol_chdir="/usr/local/consonxp"}
17+
: ${consonxp_protocol_pidfile="/var/run/consonxp/protocol.pid"}
18+
: ${consonxp_protocol_log="/var/log/consonxp/protocol.log"}
19+
: ${consonxp_protocol_user="consonxp"}
20+
: ${consonxp_protocol_config="cli-xp230.yml"}
21+
22+
load_rc_config $name
23+
24+
pidfile="${consonxp_protocol_pidfile}"
25+
26+
start_cmd="${name}_start"
27+
stop_cmd="${name}_stop"
28+
status_cmd="${name}_status"
29+
30+
consonxp_protocol_start()
31+
{
32+
# Create directories with correct ownership
33+
mkdir -p "$(dirname ${consonxp_protocol_pidfile})"
34+
chown "${consonxp_protocol_user}:${consonxp_protocol_user}" "$(dirname ${consonxp_protocol_pidfile})"
35+
mkdir -p "$(dirname ${consonxp_protocol_log})"
36+
chown "${consonxp_protocol_user}:${consonxp_protocol_user}" "$(dirname ${consonxp_protocol_log})"
37+
38+
echo "Starting ${name}."
39+
CONSONXP_CHDIR="${consonxp_protocol_chdir}" \
40+
CONSONXP_CONFIG="${consonxp_protocol_config}" \
41+
CONSONXP_PIDFILE="${consonxp_protocol_pidfile}" \
42+
/usr/sbin/daemon -u "${consonxp_protocol_user}" \
43+
-o "${consonxp_protocol_log}" \
44+
-r \
45+
"${consonxp_protocol_chdir}/bin/start_protocol"
46+
}
47+
48+
consonxp_protocol_stop()
49+
{
50+
if [ -f "${consonxp_protocol_pidfile}" ]; then
51+
echo "Stopping ${name}."
52+
kill -TERM $(cat "${consonxp_protocol_pidfile}") 2>/dev/null
53+
rm -f "${consonxp_protocol_pidfile}"
54+
else
55+
echo "${name} is not running."
56+
fi
57+
}
58+
59+
consonxp_protocol_status()
60+
{
61+
if [ -f "${consonxp_protocol_pidfile}" ]; then
62+
pid=$(cat "${consonxp_protocol_pidfile}")
63+
if ps -p ${pid} > /dev/null 2>&1; then
64+
echo "${name} is running (PID ${pid})."
65+
else
66+
echo "${name} is not running (stale PID file)."
67+
fi
68+
else
69+
echo "${name} is not running."
70+
fi
71+
}
72+
73+
run_rc_command "$1"

0 commit comments

Comments
 (0)