-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathev
More file actions
executable file
·626 lines (572 loc) · 16.6 KB
/
ev
File metadata and controls
executable file
·626 lines (572 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_NAME="$(basename "$ROOT_DIR" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//')"
REPO_NAME="${REPO_NAME:-evpoly}"
DEFAULT_SESSION="${REPO_NAME}-live"
SESSION_NAME="${EV_SESSION_NAME:-$DEFAULT_SESSION}"
BIN_NAME="${EV_BIN_NAME:-polymarket-arbitrage-bot}"
CONFIG_FILE="${EV_CONFIG:-config.json}"
DISK_GUARD_ENABLE="${EV_DISK_GUARD_ENABLE:-1}"
DISK_GUARD_MIN_FREE_GB="${EV_DISK_GUARD_MIN_FREE_GB:-5}"
DISK_AUTO_PRUNE_ENABLE="${EV_DISK_AUTO_PRUNE_ENABLE:-1}"
DISK_AUTO_PRUNE_CROSS_REPOS="${EV_DISK_AUTO_PRUNE_CROSS_REPOS:-1}"
DISK_AUTO_PRUNE_DEPLOY_TARGET="${EV_DISK_AUTO_PRUNE_DEPLOY_TARGET:-1}"
RETENTION_SCRIPT="${EV_RETENTION_SCRIPT:-$ROOT_DIR/scripts/evpoly_retention_cleanup.sh}"
WALLET_SYNC_AUTOSTART="${EV_WALLET_SYNC_AUTOSTART:-1}"
WALLET_SYNC_WORKER_SCRIPT="${EV_WALLET_SYNC_WORKER_SCRIPT:-$ROOT_DIR/scripts/wallet_sync_worker.sh}"
AUTO_RESTART_SCRIPT="${EV_AUTO_RESTART_SCRIPT:-$ROOT_DIR/scripts/ev_auto_restart.sh}"
AUTO_RESTART_ON_LIVE="${EV_AUTO_RESTART_ON_LIVE:-1}"
AUTO_RESTART_LIVE_SCHEDULE="${EV_AUTO_RESTART_LIVE_SCHEDULE:-6h}"
FORCE_REBUILD="${EV_FORCE_REBUILD:-0}"
FAST_START="${EV_FAST_START:-0}"
ALLOW_STALE_BINARY_ON_BUILD_FAIL="${EV_ALLOW_STALE_BINARY_ON_BUILD_FAIL:-1}"
usage() {
cat <<EOF
Usage:
./ev start [live|dry]
./ev restart [live|dry]
./ev stop
./ev status
./ev logs [lines]
./ev cleanup [--dry-run]
./ev autorestart on [10m|1h|6h|daily]
./ev autorestart off
./ev autorestart status
./ev autorestart run-now
Defaults:
session: $SESSION_NAME
mode: live
Env overrides:
EV_SESSION_NAME, EV_BIN_NAME, EV_CONFIG
EV_FORCE_REBUILD (1/0)
EV_ALLOW_STALE_BINARY_ON_BUILD_FAIL (1/0)
EV_FAST_START (1/0) # skips heavy startup recoveries for faster boot
EV_DISK_GUARD_ENABLE (1/0), EV_DISK_GUARD_MIN_FREE_GB
EV_DISK_AUTO_PRUNE_ENABLE (1/0)
EV_DISK_AUTO_PRUNE_CROSS_REPOS (1/0)
EV_DISK_AUTO_PRUNE_DEPLOY_TARGET (1/0)
Low-disk auto-prune also removes:
- target/release artifacts except the live bot binary
- Cargo registry cache ($HOME/.cargo/registry)
- pip cache ($HOME/.cache/pip)
- old Cursor server versions under $HOME/.cursor-server/bin/linux-x64
EV_RETENTION_SCRIPT
EV_WALLET_SYNC_AUTOSTART (1/0)
EV_WALLET_SYNC_WORKER_SCRIPT
EV_AUTO_RESTART_SCRIPT
EV_AUTO_RESTART_ON_LIVE (1/0)
EV_AUTO_RESTART_LIVE_SCHEDULE (default: 6h)
EOF
}
need_tmux() {
if ! command -v tmux >/dev/null 2>&1; then
echo "tmux is required but not installed." >&2
exit 1
fi
}
has_session() {
tmux has-session -t "$SESSION_NAME" 2>/dev/null
}
wallet_sync_should_manage() {
[[ "$WALLET_SYNC_AUTOSTART" != "0" ]]
}
wallet_sync_should_manage_for_mode() {
local mode="${1:-live}"
[[ "${mode,,}" == "live" ]] && wallet_sync_should_manage
}
wallet_sync_worker_exists() {
[[ -x "$WALLET_SYNC_WORKER_SCRIPT" ]]
}
wallet_sync_start() {
if ! wallet_sync_should_manage; then
return 0
fi
if ! wallet_sync_worker_exists; then
echo "wallet sync worker script not executable: $WALLET_SYNC_WORKER_SCRIPT" >&2
return 0
fi
"$WALLET_SYNC_WORKER_SCRIPT" start || true
}
wallet_sync_stop() {
if ! wallet_sync_should_manage; then
return 0
fi
if ! wallet_sync_worker_exists; then
return 0
fi
"$WALLET_SYNC_WORKER_SCRIPT" stop || true
}
wallet_sync_status() {
if ! wallet_sync_should_manage; then
echo "wallet sync worker: unmanaged (EV_WALLET_SYNC_AUTOSTART=0)"
return 0
fi
if ! wallet_sync_worker_exists; then
echo "wallet sync worker: script missing ($WALLET_SYNC_WORKER_SCRIPT)"
return 0
fi
"$WALLET_SYNC_WORKER_SCRIPT" status || true
}
disk_free_kb() {
df -Pk "$ROOT_DIR" | awk 'NR==2 {print $4}'
}
disk_required_kb() {
local min_gb="${DISK_GUARD_MIN_FREE_GB:-0}"
if [[ "$min_gb" =~ ^[0-9]+$ ]]; then
echo $(( min_gb * 1024 * 1024 ))
else
echo 0
fi
}
disk_free_meets_guard() {
local free_kb required_kb
free_kb="$(disk_free_kb)"
required_kb="$(disk_required_kb)"
[[ "$free_kb" =~ ^[0-9]+$ ]] && (( free_kb >= required_kb ))
}
prune_path_if_exists() {
local path="${1:-}"
if [[ -z "$path" ]]; then
return 0
fi
if [[ -d "$path" ]]; then
echo "[disk-prune] removing: $path"
rm -rf -- "$path"
fi
}
prune_release_artifacts_keep_bin() {
local repo_root="${1:-}"
local bin_name="${2:-$BIN_NAME}"
local release_dir="${repo_root%/}/target/release"
if [[ -z "$repo_root" || ! -d "$release_dir" ]]; then
return 0
fi
mapfile -t paths < <(
find "$release_dir" -mindepth 1 -maxdepth 1 \
! -name "$bin_name" \
! -name "${bin_name}.d" \
-print
)
if (( ${#paths[@]} == 0 )); then
return 0
fi
echo "[disk-prune] pruning release artifacts under: $release_dir"
rm -rf -- "${paths[@]}"
}
prune_cursor_server_old_versions() {
local base_dir="${HOME}/.cursor-server/bin/linux-x64"
if [[ ! -d "$base_dir" ]]; then
return 0
fi
local newest_dir=""
newest_dir="$(find "$base_dir" -maxdepth 1 -mindepth 1 -type d -printf '%T@ %p\n' 2>/dev/null | sort -nr | awk 'NR==1 {print $2}')"
mapfile -t preserve_dirs < <(
{
[[ -n "$newest_dir" ]] && printf '%s\n' "$newest_dir"
pgrep -af "${base_dir}/" 2>/dev/null | sed -n "s#.*\\(${base_dir}/[^ /]*\\).*#\\1#p"
} | awk 'NF && !seen[$0]++'
)
local dir keep
while IFS= read -r dir; do
[[ -n "$dir" ]] || continue
keep=0
for preserved in "${preserve_dirs[@]}"; do
if [[ "$dir" == "$preserved" ]]; then
keep=1
break
fi
done
if (( keep == 0 )); then
echo "[disk-prune] removing old Cursor server: $dir"
rm -rf -- "$dir"
fi
done < <(find "$base_dir" -maxdepth 1 -mindepth 1 -type d -print 2>/dev/null)
}
disk_auto_prune() {
if [[ "${DISK_AUTO_PRUNE_ENABLE}" == "0" ]]; then
return 0
fi
if [[ -x "$RETENTION_SCRIPT" ]]; then
(cd "$ROOT_DIR" && "$RETENTION_SCRIPT") || true
fi
prune_path_if_exists "$ROOT_DIR/target/debug"
if disk_free_meets_guard; then
return 0
fi
if [[ "${DISK_AUTO_PRUNE_CROSS_REPOS}" != "0" ]]; then
if [[ "$ROOT_DIR" != "/root/EVPOLY" ]]; then
prune_path_if_exists "/root/EVPOLY/target/debug"
fi
if [[ "$ROOT_DIR" != "/root/poly-remote" ]]; then
prune_path_if_exists "/root/poly-remote/target/debug"
fi
fi
if disk_free_meets_guard; then
return 0
fi
prune_release_artifacts_keep_bin "$ROOT_DIR" "$BIN_NAME"
if [[ "${DISK_AUTO_PRUNE_CROSS_REPOS}" != "0" ]]; then
if [[ "$ROOT_DIR" != "/root/EVPOLY" ]]; then
prune_release_artifacts_keep_bin "/root/EVPOLY" "$BIN_NAME"
fi
if [[ "$ROOT_DIR" != "/root/poly-remote" ]]; then
prune_release_artifacts_keep_bin "/root/poly-remote" "$BIN_NAME"
fi
fi
if disk_free_meets_guard; then
return 0
fi
if [[ "${DISK_AUTO_PRUNE_DEPLOY_TARGET}" != "0" ]]; then
prune_path_if_exists "/root/EVPOLY-deploy-target"
fi
if disk_free_meets_guard; then
return 0
fi
prune_path_if_exists "${CARGO_HOME:-$HOME/.cargo}/registry"
if disk_free_meets_guard; then
return 0
fi
prune_path_if_exists "$HOME/.cache/pip"
if disk_free_meets_guard; then
return 0
fi
prune_cursor_server_old_versions
}
disk_guard_check() {
if [[ "${DISK_GUARD_ENABLE}" == "0" ]]; then
return 0
fi
if ! [[ "${DISK_GUARD_MIN_FREE_GB}" =~ ^[0-9]+$ ]]; then
echo "invalid EV_DISK_GUARD_MIN_FREE_GB='${DISK_GUARD_MIN_FREE_GB}' (must be integer GB)" >&2
exit 1
fi
local free_kb required_kb
free_kb="$(disk_free_kb)"
required_kb=$(( DISK_GUARD_MIN_FREE_GB * 1024 * 1024 ))
if [[ -z "$free_kb" ]] || ! [[ "$free_kb" =~ ^[0-9]+$ ]]; then
echo "failed to read free disk space for '$ROOT_DIR'" >&2
exit 1
fi
if (( free_kb < required_kb )); then
local free_gb_before
free_gb_before="$(awk "BEGIN {printf \"%.2f\", $free_kb/1024/1024}")"
echo "disk guard: low space (${free_gb_before}G < ${DISK_GUARD_MIN_FREE_GB}G). Running auto-prune..." >&2
disk_auto_prune
free_kb="$(disk_free_kb)"
fi
if (( free_kb < required_kb )); then
local free_gb
free_gb="$(awk "BEGIN {printf \"%.2f\", $free_kb/1024/1024}")"
echo "disk guard failed: free ${free_gb}G < required ${DISK_GUARD_MIN_FREE_GB}G. Refusing to start." >&2
echo "Run: ./ev cleanup --dry-run (or ./ev cleanup) before restart." >&2
exit 1
fi
}
load_local_ev_overrides() {
if [[ -f "$ROOT_DIR/.env" ]]; then
# shellcheck disable=SC1091
set -f
source "$ROOT_DIR/.env" || true
set +f
DISK_GUARD_ENABLE="${EV_DISK_GUARD_ENABLE:-$DISK_GUARD_ENABLE}"
DISK_GUARD_MIN_FREE_GB="${EV_DISK_GUARD_MIN_FREE_GB:-$DISK_GUARD_MIN_FREE_GB}"
DISK_AUTO_PRUNE_ENABLE="${EV_DISK_AUTO_PRUNE_ENABLE:-$DISK_AUTO_PRUNE_ENABLE}"
DISK_AUTO_PRUNE_CROSS_REPOS="${EV_DISK_AUTO_PRUNE_CROSS_REPOS:-$DISK_AUTO_PRUNE_CROSS_REPOS}"
DISK_AUTO_PRUNE_DEPLOY_TARGET="${EV_DISK_AUTO_PRUNE_DEPLOY_TARGET:-$DISK_AUTO_PRUNE_DEPLOY_TARGET}"
ALLOW_STALE_BINARY_ON_BUILD_FAIL="${EV_ALLOW_STALE_BINARY_ON_BUILD_FAIL:-$ALLOW_STALE_BINARY_ON_BUILD_FAIL}"
fi
}
mode_flag_from() {
local mode="${1:-live}"
case "${mode,,}" in
live) echo "--no-simulation" ;;
dry|sim|simulation|test) echo "--simulation" ;;
*)
echo "invalid mode: $mode (use live or dry)" >&2
exit 1
;;
esac
}
release_bin_path() {
printf "%s/target/release/%s" "$ROOT_DIR" "$BIN_NAME"
}
binary_needs_rebuild() {
local bin_path
bin_path="$(release_bin_path)"
if [[ "$FORCE_REBUILD" == "1" ]]; then
return 0
fi
if [[ ! -x "$bin_path" ]]; then
return 0
fi
if [[ "$ROOT_DIR/Cargo.toml" -nt "$bin_path" ]]; then
return 0
fi
if [[ -f "$ROOT_DIR/Cargo.lock" && "$ROOT_DIR/Cargo.lock" -nt "$bin_path" ]]; then
return 0
fi
if [[ -f "$ROOT_DIR/build.rs" && "$ROOT_DIR/build.rs" -nt "$bin_path" ]]; then
return 0
fi
if find "$ROOT_DIR/src" "$ROOT_DIR/crates" "$ROOT_DIR/bin" \
-type f \( -name '*.rs' -o -name 'Cargo.toml' -o -name 'Cargo.lock' -o -name 'build.rs' \) \
-newer "$bin_path" -print -quit 2>/dev/null | grep -q .; then
return 0
fi
return 1
}
ensure_release_binary() {
local bin_path
bin_path="$(release_bin_path)"
if binary_needs_rebuild; then
echo "building release binary (code changed or missing binary)..."
if (cd "$ROOT_DIR" && cargo build --release --bin "$BIN_NAME"); then
return 0
fi
local build_status=$?
if [[ "$ALLOW_STALE_BINARY_ON_BUILD_FAIL" == "1" && -x "$bin_path" ]]; then
echo "build failed (status=$build_status); using stale release binary fallback: $bin_path" >&2
return 0
fi
echo "build failed (status=$build_status); no fallback available." >&2
return "$build_status"
else
echo "using prebuilt binary: $bin_path"
fi
}
start_session() {
local mode="${1:-live}"
local mode_flag
load_local_ev_overrides
mode_flag="$(mode_flag_from "$mode")"
disk_guard_check
if has_session; then
echo "session '$SESSION_NAME' is already running."
return 0
fi
ensure_release_binary
local cmd
local fast_env_prefix=""
if [[ "$FAST_START" == "1" ]]; then
fast_env_prefix="export EVPOLY_STARTUP_CANCEL_ALL_ORDERS=false EVPOLY_STARTUP_PENDING_RECONCILE_ENABLE=false EVPOLY_MARKET_PREWARM_ENABLE=false; "
fi
cmd="cd '$ROOT_DIR' && set -a && set -f && { [ -f .env ] && source .env; true; } && set +f && set +a && ${fast_env_prefix}'$(release_bin_path)' --config '$CONFIG_FILE' $mode_flag"
tmux new-session -d -s "$SESSION_NAME" "bash -lc \"$cmd\""
echo "started session '$SESSION_NAME' ($mode)."
if wallet_sync_should_manage_for_mode "$mode"; then
wallet_sync_start
fi
}
cleanup_retention() {
if [[ ! -x "$RETENTION_SCRIPT" ]]; then
echo "retention script not found or not executable: $RETENTION_SCRIPT" >&2
exit 1
fi
(cd "$ROOT_DIR" && "$RETENTION_SCRIPT" "${1:-}")
}
stop_session() {
if has_session; then
tmux kill-session -t "$SESSION_NAME"
echo "stopped session '$SESSION_NAME'."
else
echo "session '$SESSION_NAME' is not running."
fi
wallet_sync_stop
}
status_session() {
if has_session; then
echo "session '$SESSION_NAME' is running."
tmux list-panes -t "$SESSION_NAME" -F "pane=#{pane_index} pid=#{pane_pid} cmd=#{pane_current_command}" | head -n 3
else
echo "session '$SESSION_NAME' is not running."
fi
wallet_sync_status
}
logs_session() {
local lines="${1:-200}"
if ! [[ "$lines" =~ ^[0-9]+$ ]]; then
echo "invalid lines value: $lines" >&2
exit 1
fi
if has_session; then
tmux capture-pane -pt "$SESSION_NAME" -S "-$lines"
else
echo "session '$SESSION_NAME' is not running."
exit 1
fi
}
autorestart_block_begin() {
echo "# EVPOLY_AUTORESTART_BEGIN $ROOT_DIR"
}
autorestart_block_end() {
echo "# EVPOLY_AUTORESTART_END $ROOT_DIR"
}
cron_expr_from_schedule() {
local spec="${1:-6h}"
case "${spec,,}" in
daily)
echo "5 0 * * *"
return 0
;;
[0-9]*m)
local mins="${spec%m}"
if [[ -n "$mins" && "$mins" =~ ^[0-9]+$ && "$mins" -ge 1 && "$mins" -le 59 ]]; then
echo "*/${mins} * * * *"
return 0
fi
;;
[0-9]*h)
local hours="${spec%h}"
if [[ -n "$hours" && "$hours" =~ ^[0-9]+$ && "$hours" -ge 1 && "$hours" -le 23 ]]; then
echo "5 */${hours} * * *"
return 0
fi
;;
esac
echo "invalid schedule '$spec' (use 10m, 1h, 6h, daily, or Nh/Nm)" >&2
return 1
}
autorestart_strip_block() {
awk -v begin="$(autorestart_block_begin)" -v end="$(autorestart_block_end)" '
$0 == begin {in_block=1; next}
$0 == end {in_block=0; next}
!in_block {print}
'
}
autorestart_status() {
local current
current="$(crontab -l 2>/dev/null || true)"
local begin end
begin="$(autorestart_block_begin)"
end="$(autorestart_block_end)"
if printf "%s\n" "$current" | grep -Fqx "$begin"; then
echo "auto-restart: enabled"
printf "%s\n" "$current" | awk -v begin="$begin" -v end="$end" '
$0==begin {in_block=1; next}
$0==end {in_block=0; next}
in_block && $0 !~ /^#/ && length($0) > 0 {print "schedule: " $0}
'
else
echo "auto-restart: disabled"
fi
}
autorestart_on() {
local schedule="${1:-6h}"
if [[ ! -x "$AUTO_RESTART_SCRIPT" ]]; then
echo "auto-restart script not found/executable: $AUTO_RESTART_SCRIPT" >&2
exit 1
fi
local cron_expr
cron_expr="$(cron_expr_from_schedule "$schedule")"
local begin end
begin="$(autorestart_block_begin)"
end="$(autorestart_block_end)"
local existing stripped tmp
existing="$(crontab -l 2>/dev/null || true)"
stripped="$(printf "%s\n" "$existing" | autorestart_strip_block)"
tmp="$(mktemp)"
{
printf "%s\n" "$stripped"
printf "%s\n" "$begin"
printf "%s %s\n" "$cron_expr" "$AUTO_RESTART_SCRIPT"
printf "%s\n" "$end"
} > "$tmp"
crontab "$tmp"
rm -f "$tmp"
echo "auto-restart enabled: $cron_expr"
autorestart_status
}
autorestart_off() {
local existing stripped tmp
existing="$(crontab -l 2>/dev/null || true)"
stripped="$(printf "%s\n" "$existing" | autorestart_strip_block)"
tmp="$(mktemp)"
printf "%s\n" "$stripped" > "$tmp"
crontab "$tmp"
rm -f "$tmp"
echo "auto-restart disabled"
}
autorestart_run_now() {
if [[ ! -x "$AUTO_RESTART_SCRIPT" ]]; then
echo "auto-restart script not found/executable: $AUTO_RESTART_SCRIPT" >&2
exit 1
fi
"$AUTO_RESTART_SCRIPT"
}
maybe_enable_live_autorestart() {
local mode="${1:-live}"
if [[ "$AUTO_RESTART_ON_LIVE" == "0" ]]; then
return 0
fi
if [[ "${mode,,}" != "live" ]]; then
return 0
fi
autorestart_on "$AUTO_RESTART_LIVE_SCHEDULE"
}
main() {
need_tmux
local action="${1:-}"
case "$action" in
start)
local mode="${2:-live}"
start_session "$mode"
maybe_enable_live_autorestart "$mode"
;;
restart)
local mode="${2:-live}"
# Build/preflight first so a compile failure cannot cause downtime.
if has_session; then
load_local_ev_overrides
disk_guard_check
ensure_release_binary
fi
stop_session
start_session "$mode"
maybe_enable_live_autorestart "$mode"
;;
stop)
stop_session
;;
status)
status_session
;;
logs)
logs_session "${2:-200}"
;;
cleanup)
cleanup_retention "${2:-}"
;;
autorestart)
local sub="${2:-status}"
case "$sub" in
on)
autorestart_on "${3:-6h}"
;;
off)
autorestart_off
;;
status)
autorestart_status
;;
run-now)
autorestart_run_now
;;
*)
echo "unknown autorestart action: $sub" >&2
usage
exit 1
;;
esac
;;
""|-h|--help|help)
usage
;;
*)
echo "unknown action: $action" >&2
usage
exit 1
;;
esac
}
main "$@"