mirror of https://github.com/jetkvm/kvm.git
Compare commits
5 Commits
3cef992e36
...
439b898d3b
| Author | SHA1 | Date |
|---|---|---|
|
|
439b898d3b | |
|
|
4b6e796a0e | |
|
|
79098d3546 | |
|
|
50fc88aae1 | |
|
|
204909b49a |
|
|
@ -305,11 +305,11 @@ func wakeDisplay(force bool, reason string) {
|
|||
displayLogger.Warn().Err(err).Msg("failed to wake display")
|
||||
}
|
||||
|
||||
if config.DisplayDimAfterSec != 0 {
|
||||
if config.DisplayDimAfterSec != 0 && dimTicker != nil {
|
||||
dimTicker.Reset(time.Duration(config.DisplayDimAfterSec) * time.Second)
|
||||
}
|
||||
|
||||
if config.DisplayOffAfterSec != 0 {
|
||||
if config.DisplayOffAfterSec != 0 && offTicker != nil {
|
||||
offTicker.Reset(time.Duration(config.DisplayOffAfterSec) * time.Second)
|
||||
}
|
||||
backlightState = 0
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ type Client struct {
|
|||
var (
|
||||
defaultTimerDuration = 1 * time.Second
|
||||
defaultLinkUpTimeout = 30 * time.Second
|
||||
defaultDHCPTimeout = 5 * time.Second // DHCP request timeout (not link up timeout)
|
||||
maxRenewalAttemptDuration = 2 * time.Hour
|
||||
)
|
||||
|
||||
|
|
@ -125,11 +126,11 @@ func NewClient(ctx context.Context, ifaces []string, c *Config, l *zerolog.Logge
|
|||
}
|
||||
|
||||
if cfg.Timeout == 0 {
|
||||
cfg.Timeout = defaultLinkUpTimeout
|
||||
cfg.Timeout = defaultDHCPTimeout
|
||||
}
|
||||
|
||||
if cfg.Retries == 0 {
|
||||
cfg.Retries = 3
|
||||
cfg.Retries = 4
|
||||
}
|
||||
|
||||
return &Client{
|
||||
|
|
@ -153,9 +154,15 @@ func NewClient(ctx context.Context, ifaces []string, c *Config, l *zerolog.Logge
|
|||
}, nil
|
||||
}
|
||||
|
||||
func resetTimer(t *time.Timer, l *zerolog.Logger) {
|
||||
l.Debug().Dur("delay", defaultTimerDuration).Msg("will retry later")
|
||||
t.Reset(defaultTimerDuration)
|
||||
func resetTimer(t *time.Timer, attempt int, l *zerolog.Logger) {
|
||||
// Exponential backoff: 1s, 2s, 4s, 8s, max 8s
|
||||
backoffAttempt := attempt
|
||||
if backoffAttempt > 3 {
|
||||
backoffAttempt = 3
|
||||
}
|
||||
delay := time.Duration(1<<backoffAttempt) * time.Second
|
||||
l.Debug().Dur("delay", delay).Int("attempt", attempt).Msg("will retry later")
|
||||
t.Reset(delay)
|
||||
}
|
||||
|
||||
func getRenewalTime(lease *Lease) time.Duration {
|
||||
|
|
@ -168,12 +175,14 @@ func getRenewalTime(lease *Lease) time.Duration {
|
|||
|
||||
func (c *Client) requestLoop(t *time.Timer, family int, ifname string) {
|
||||
l := c.l.With().Str("interface", ifname).Int("family", family).Logger()
|
||||
attempt := 0
|
||||
for range t.C {
|
||||
l.Info().Msg("requesting lease")
|
||||
l.Info().Int("attempt", attempt).Msg("requesting lease")
|
||||
|
||||
if _, err := c.ensureInterfaceUp(ifname); err != nil {
|
||||
l.Error().Err(err).Msg("failed to ensure interface up")
|
||||
resetTimer(t, c.l)
|
||||
l.Error().Err(err).Int("attempt", attempt).Msg("failed to ensure interface up")
|
||||
resetTimer(t, attempt, c.l)
|
||||
attempt++
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -188,11 +197,14 @@ func (c *Client) requestLoop(t *time.Timer, family int, ifname string) {
|
|||
lease, err = c.requestLease6(ifname)
|
||||
}
|
||||
if err != nil {
|
||||
l.Error().Err(err).Msg("failed to request lease")
|
||||
resetTimer(t, c.l)
|
||||
l.Error().Err(err).Int("attempt", attempt).Msg("failed to request lease")
|
||||
resetTimer(t, attempt, c.l)
|
||||
attempt++
|
||||
continue
|
||||
}
|
||||
|
||||
// Successfully obtained lease, reset attempt counter
|
||||
attempt = 0
|
||||
c.handleLeaseChange(lease)
|
||||
|
||||
nextRenewal := getRenewalTime(lease)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,31 @@ show_help() {
|
|||
echo " $0 -r 192.168.0.17 -u admin"
|
||||
}
|
||||
|
||||
# Function to check if device is pingable
|
||||
check_ping() {
|
||||
local host=$1
|
||||
msg_info "▶ Checking if device is reachable at ${host}..."
|
||||
if ! ping -c 3 -W 5 "${host}" > /dev/null 2>&1; then
|
||||
msg_err "Error: Cannot reach device at ${host}"
|
||||
msg_err "Please verify the IP address and network connectivity"
|
||||
exit 1
|
||||
fi
|
||||
msg_info "✓ Device is reachable"
|
||||
}
|
||||
|
||||
# Function to check if SSH is accessible
|
||||
check_ssh() {
|
||||
local user=$1
|
||||
local host=$2
|
||||
msg_info "▶ Checking SSH connectivity to ${user}@${host}..."
|
||||
if ! ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=10 "${user}@${host}" "echo 'SSH connection successful'" > /dev/null 2>&1; then
|
||||
msg_err "Error: Cannot establish SSH connection to ${user}@${host}"
|
||||
msg_err "Please verify SSH access and credentials"
|
||||
exit 1
|
||||
fi
|
||||
msg_info "✓ SSH connection successful"
|
||||
}
|
||||
|
||||
# Default values
|
||||
SCRIPT_PATH=$(realpath "$(dirname $(realpath "${BASH_SOURCE[0]}"))")
|
||||
REMOTE_USER="root"
|
||||
|
|
@ -113,6 +138,10 @@ if [ -z "$REMOTE_HOST" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Check device connectivity before proceeding
|
||||
check_ping "${REMOTE_HOST}"
|
||||
check_ssh "${REMOTE_USER}" "${REMOTE_HOST}"
|
||||
|
||||
# check if the current CPU architecture is x86_64
|
||||
if [ "$(uname -m)" != "x86_64" ]; then
|
||||
msg_warn "Warning: This script is only supported on x86_64 architecture"
|
||||
|
|
@ -147,10 +176,10 @@ if [ "$RUN_GO_TESTS" = true ]; then
|
|||
make build_dev_test
|
||||
|
||||
msg_info "▶ Copying device-tests.tar.gz to remote host"
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > /tmp/device-tests.tar.gz" < device-tests.tar.gz
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" "cat > /tmp/device-tests.tar.gz" < device-tests.tar.gz
|
||||
|
||||
msg_info "▶ Running go tests"
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" ash << 'EOF'
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" ash << 'EOF'
|
||||
set -e
|
||||
TMP_DIR=$(mktemp -d)
|
||||
cd ${TMP_DIR}
|
||||
|
|
@ -193,10 +222,10 @@ then
|
|||
ENABLE_SYNC_TRACE=${ENABLE_SYNC_TRACE}
|
||||
|
||||
# Copy the binary to the remote host as if we were the OTA updater.
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > /userdata/jetkvm/jetkvm_app.update" < bin/jetkvm_app
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" "cat > /userdata/jetkvm/jetkvm_app.update" < bin/jetkvm_app
|
||||
|
||||
# Reboot the device, the new app will be deployed by the startup process.
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" "reboot"
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" "reboot"
|
||||
else
|
||||
msg_info "▶ Building development binary"
|
||||
do_make build_dev \
|
||||
|
|
@ -205,21 +234,21 @@ else
|
|||
ENABLE_SYNC_TRACE=${ENABLE_SYNC_TRACE}
|
||||
|
||||
# Kill any existing instances of the application
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app_debug || true"
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app_debug || true"
|
||||
|
||||
# Copy the binary to the remote host
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > ${REMOTE_PATH}/jetkvm_app_debug" < bin/jetkvm_app
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" "cat > ${REMOTE_PATH}/jetkvm_app_debug" < bin/jetkvm_app
|
||||
|
||||
if [ "$RESET_USB_HID_DEVICE" = true ]; then
|
||||
msg_info "▶ Resetting USB HID device"
|
||||
msg_warn "The option has been deprecated and will be removed in a future version, as JetKVM will now reset USB gadget configuration when needed"
|
||||
# Remove the old USB gadget configuration
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" "rm -rf /sys/kernel/config/usb_gadget/jetkvm/configs/c.1/hid.usb*"
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" "ls /sys/class/udc > /sys/kernel/config/usb_gadget/jetkvm/UDC"
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" "rm -rf /sys/kernel/config/usb_gadget/jetkvm/configs/c.1/hid.usb*"
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" "ls /sys/class/udc > /sys/kernel/config/usb_gadget/jetkvm/UDC"
|
||||
fi
|
||||
|
||||
# Deploy and run the application on the remote host
|
||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" ash << EOF
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${REMOTE_USER}@${REMOTE_HOST}" ash << EOF
|
||||
set -e
|
||||
|
||||
# Set the library path to include the directory where librockit.so is located
|
||||
|
|
@ -229,6 +258,17 @@ export LD_LIBRARY_PATH=/oem/usr/lib:\$LD_LIBRARY_PATH
|
|||
killall jetkvm_app || true
|
||||
killall jetkvm_app_debug || true
|
||||
|
||||
# Wait until both binaries are killed, max 10 seconds
|
||||
i=1
|
||||
while [ \$i -le 10 ]; do
|
||||
echo "Waiting for jetkvm_app and jetkvm_app_debug to be killed, \$i/10 ..."
|
||||
if ! pgrep -f "jetkvm_app" > /dev/null && ! pgrep -f "jetkvm_app_debug" > /dev/null; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
i=\$((i + 1))
|
||||
done
|
||||
|
||||
# Navigate to the directory where the binary will be stored
|
||||
cd "${REMOTE_PATH}"
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { useRTCStore, PostRebootAction } from "@/hooks/stores";
|
|||
import LogoBlue from "@/assets/logo-blue.svg";
|
||||
import LogoWhite from "@/assets/logo-white.svg";
|
||||
import { isOnDevice } from "@/main";
|
||||
import { sleep } from "@/utils";
|
||||
|
||||
|
||||
interface OverlayContentProps {
|
||||
|
|
@ -481,8 +482,11 @@ export function RebootingOverlay({ show, postRebootAction }: RebootingOverlayPro
|
|||
// - Protocol-relative URLs: resolved with current protocol
|
||||
// - Fully qualified URLs: used as-is
|
||||
const targetUrl = new URL(postRebootAction.redirectTo, window.location.origin);
|
||||
clearInterval(intervalId); // Stop polling before redirect
|
||||
|
||||
window.location.href = targetUrl.href;
|
||||
// Add 1s delay between setting location.href and calling reload() to prevent reload from interrupting the navigation.
|
||||
await sleep(1000);
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ export default function SettingsHardwareRoute() {
|
|||
}
|
||||
|
||||
setBacklightSettings(settings);
|
||||
handleBacklightSettingsSave();
|
||||
handleBacklightSettingsSave(settings);
|
||||
};
|
||||
|
||||
const handleBacklightSettingsSave = () => {
|
||||
const handleBacklightSettingsSave = (backlightSettings: BacklightSettings) => {
|
||||
send("setBacklightSettings", { params: backlightSettings }, (resp: JsonRpcResponse) => {
|
||||
if ("error" in resp) {
|
||||
notifications.error(
|
||||
|
|
@ -81,7 +81,7 @@ export default function SettingsHardwareRoute() {
|
|||
const duration = enabled ? 90 : -1;
|
||||
send("setVideoSleepMode", { duration }, (resp: JsonRpcResponse) => {
|
||||
if ("error" in resp) {
|
||||
notifications.error(m.hardware_power_saving_failed_error({ error: resp.error.data ||m.unknown_error() }));
|
||||
notifications.error(m.hardware_power_saving_failed_error({ error: resp.error.data || m.unknown_error() }));
|
||||
setPowerSavingEnabled(!enabled); // Attempt to revert on error
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue