Skip to content

Commit ca7bdd9

Browse files
authored
Merge pull request #6424 from rglidden/truenas_ws_remote
truenas_ws: Add ability to deploy to remote TrueNAS server via WebSockets
2 parents b4a5149 + 070cd0f commit ca7bdd9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

deploy/truenas_ws.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ _ws_call() {
3939
_debug "_ws_call arg2" "$2"
4040
_debug "_ws_call arg3" "$3"
4141
if [ $# -eq 3 ]; then
42-
_ws_response=$(midclt -K "$DEPLOY_TRUENAS_APIKEY" call "$1" "$2" "$3")
42+
_ws_response=$(midclt --uri "$_ws_uri" -K "$DEPLOY_TRUENAS_APIKEY" call "$1" "$2" "$3")
4343
fi
4444
if [ $# -eq 2 ]; then
45-
_ws_response=$(midclt -K "$DEPLOY_TRUENAS_APIKEY" call "$1" "$2")
45+
_ws_response=$(midclt --uri "$_ws_uri" -K "$DEPLOY_TRUENAS_APIKEY" call "$1" "$2")
4646
fi
4747
if [ $# -eq 1 ]; then
48-
_ws_response=$(midclt -K "$DEPLOY_TRUENAS_APIKEY" call "$1")
48+
_ws_response=$(midclt --uri "$_ws_uri" -K "$DEPLOY_TRUENAS_APIKEY" call "$1")
4949
fi
5050
_debug "_ws_response" "$_ws_response"
5151
printf "%s" "$_ws_response"
@@ -60,7 +60,7 @@ _ws_upload_cert() {
6060
import sys
6161
6262
from truenas_api_client import Client
63-
with Client() as c:
63+
with Client(uri="$_ws_uri") as c:
6464
6565
### Login with API key
6666
print("I:Trying to upload new certificate...")
@@ -121,7 +121,7 @@ _ws_check_jobid() {
121121
# n/a
122122
_ws_get_job_result() {
123123
while true; do
124-
sleep 2
124+
_sleep 2
125125
_ws_response=$(_ws_call "core.get_jobs" "[[\"id\", \"=\", $1]]")
126126
if [ "$(printf "%s" "$_ws_response" | jq -r '.[]."state"')" != "RUNNING" ]; then
127127
_ws_result="$(printf "%s" "$_ws_response" | jq '.[]."result"')"
@@ -179,11 +179,27 @@ truenas_ws_deploy() {
179179

180180
_info "Checking environment variables..."
181181
_getdeployconf DEPLOY_TRUENAS_APIKEY
182+
_getdeployconf DEPLOY_TRUENAS_HOSTNAME
183+
_getdeployconf DEPLOY_TRUENAS_PROTOCOL
182184
# Check API Key
183185
if [ -z "$DEPLOY_TRUENAS_APIKEY" ]; then
184186
_err "TrueNAS API key not found, please set the DEPLOY_TRUENAS_APIKEY environment variable."
185187
return 1
186188
fi
189+
# Check Hostname, default to localhost if not set
190+
if [ -z "$DEPLOY_TRUENAS_HOSTNAME" ]; then
191+
_info "TrueNAS hostname not set. Using 'localhost'."
192+
DEPLOY_TRUENAS_HOSTNAME="localhost"
193+
fi
194+
# Check protocol, default to ws if not set
195+
if [ -z "$DEPLOY_TRUENAS_PROTOCOL" ]; then
196+
_info "TrueNAS protocol not set. Using 'ws'."
197+
DEPLOY_TRUENAS_PROTOCOL="ws"
198+
fi
199+
_ws_uri="$DEPLOY_TRUENAS_PROTOCOL://$DEPLOY_TRUENAS_HOSTNAME/websocket"
200+
_debug2 DEPLOY_TRUENAS_HOSTNAME "$DEPLOY_TRUENAS_HOSTNAME"
201+
_debug2 DEPLOY_TRUENAS_PROTOCOL "$DEPLOY_TRUENAS_PROTOCOL"
202+
_debug _ws_uri "$_ws_uri"
187203
_secure_debug2 DEPLOY_TRUENAS_APIKEY "$DEPLOY_TRUENAS_APIKEY"
188204
_info "Environment variables: OK"
189205

@@ -205,6 +221,8 @@ truenas_ws_deploy() {
205221
return 2
206222
fi
207223
_savedeployconf DEPLOY_TRUENAS_APIKEY "$DEPLOY_TRUENAS_APIKEY"
224+
_savedeployconf DEPLOY_TRUENAS_HOSTNAME "$DEPLOY_TRUENAS_HOSTNAME"
225+
_savedeployconf DEPLOY_TRUENAS_PROTOCOL "$DEPLOY_TRUENAS_PROTOCOL"
208226
_info "TrueNAS health: OK"
209227

210228
########## System info
@@ -304,7 +322,7 @@ truenas_ws_deploy() {
304322
_info "Restarting WebUI..."
305323
_ws_response=$(_ws_call "system.general.ui_restart")
306324
_info "Waiting for UI restart..."
307-
sleep 6
325+
_sleep 15
308326

309327
########## Certificates
310328

0 commit comments

Comments
 (0)