Skip to content

Commit c17025d

Browse files
committed
Chatto: configure everything in chatto.toml
The data directory and the operator API were still set as environment variables in the unit, which override chatto.toml the same way the URL did. Install writes all three into chatto.toml, and the update moves them there and empties the unit; data_dir always takes the unit's value, since that is where the store is.
1 parent a76abe4 commit c17025d

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

‎ct/chatto.sh‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,25 @@ function update_script() {
3636
exit
3737
fi
3838

39-
# Environment beats chatto.toml, so a URL set in the unit hid any change to webserver.url
40-
if grep -q '^Environment=CHATTO_WEBSERVER_URL=' /etc/systemd/system/chatto.service; then
41-
msg_info "Moving the public URL into chatto.toml"
42-
url="$(sed -n 's/^Environment=CHATTO_WEBSERVER_URL=//p' /etc/systemd/system/chatto.service)"
43-
sed -i "/^\[webserver\]/,/^\[/ s|^url = 'http://localhost:4000'$|url = '${url}'|" /opt/chatto_data/chatto.toml
44-
sed -i '/^Environment=CHATTO_WEBSERVER_URL=/d' /etc/systemd/system/chatto.service
39+
# Environment beats chatto.toml; the unit's data_dir is where the store is, a URL edited in the file stays
40+
local unit=/etc/systemd/system/chatto.service toml=/opt/chatto_data/chatto.toml url data_dir
41+
if grep -q '^Environment=CHATTO_' "$unit"; then
42+
msg_info "Moving the service settings into chatto.toml"
43+
url="$(sed -n 's/^Environment=CHATTO_WEBSERVER_URL=//p' "$unit")"
44+
data_dir="$(sed -n 's/^Environment=CHATTO_NATS_EMBEDDED_DATA_DIR=//p' "$unit")"
45+
if [[ -n "$url" ]]; then
46+
sed -i "/^\[webserver\]/,/^\[/ s|^url = 'http://localhost:4000'$|url = '${url}'|" "$toml"
47+
fi
48+
if [[ -n "$data_dir" ]]; then
49+
sed -i "/^\[nats.embedded\]/,/^\[/ s|^data_dir = .*|data_dir = '${data_dir}'|" "$toml"
50+
fi
51+
if grep -q '^Environment=CHATTO_OPERATOR_API_ENABLED=true$' "$unit"; then
52+
sed -i '/^# \[operator_api\]$/,/^$/ { s|^# \[operator_api\]$|[operator_api]|; s|^# enabled = false$|enabled = true| }' "$toml"
53+
fi
54+
sed -i '/^Environment=CHATTO_/d' "$unit"
4555
systemctl daemon-reload
4656
systemctl restart chatto
47-
msg_ok "Moved the public URL into chatto.toml"
57+
msg_ok "Moved the service settings into chatto.toml"
4858
fi
4959

5060
if check_for_gh_release "chatto" "chattocorp/chatto"; then

‎install/chatto-install.sh‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ mkdir -p /opt/chatto_data
2121
cd /opt/chatto
2222
$STD ./chatto init
2323
mv /opt/chatto/chatto.toml /opt/chatto_data/chatto.toml
24-
sed -i "/^\[webserver\]/,/^\[/ s|^url = .*|url = 'http://${LOCAL_IP}:4000'|" /opt/chatto_data/chatto.toml
24+
sed -i \
25+
-e "/^\[webserver\]/,/^\[/ s|^url = .*|url = 'http://${LOCAL_IP}:4000'|" \
26+
-e "/^\[nats.embedded\]/,/^\[/ s|^data_dir = .*|data_dir = '/opt/chatto_data/data'|" \
27+
-e '/^# \[operator_api\]$/,/^$/ { s|^# \[operator_api\]$|[operator_api]|; s|^# enabled = false$|enabled = true| }' \
28+
/opt/chatto_data/chatto.toml
2529
msg_ok "Configured Chatto"
2630

2731
msg_info "Creating Service"
@@ -35,8 +39,6 @@ Wants=network-online.target
3539
Type=simple
3640
User=root
3741
WorkingDirectory=/opt/chatto
38-
Environment=CHATTO_NATS_EMBEDDED_DATA_DIR=/opt/chatto_data/data
39-
Environment=CHATTO_OPERATOR_API_ENABLED=true
4042
ExecStart=/opt/chatto/chatto run -c /opt/chatto_data/chatto.toml
4143
Restart=always
4244
RestartSec=5

0 commit comments

Comments
 (0)