zscripts-token-savers/bash/zrestart
KellyMichels 8e6ffea1a4 feat(bash): native bash port of all z-scripts for Linux/macOS/WSL
Full port: zhelpers.sh library (jq config, ssh, http/tcp, archive builder,
build-version, motd, port-kill), all commands (zstart/zkill/zrestart/zstop,
zdeploy with 5 kind handlers, zec2/zec2online/zrepair, zbackup/zbackup_ec2/
zsync/zbackup_and_sync, zstart_docker, zsetup_mail, setup_backup_schedule via
cron), Unix-path zconfig.example.json, and a bash/README.md.

Verified: bash -n clean on all scripts; archive exclusions, config semantics,
and zec2 tested against the real config and live server from Git Bash. Needs a
Linux/macOS/WSL shakedown for lsof/rsync/nohup paths before merging.
2026-07-16 14:07:02 -05:00

54 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# Evomedia.net Token Savers — https://github.com/kellymichels/zscripts-token-savers
# Created by Kelly Michels · dev@evomedia.net
# Licensed under the MIT License. See LICENSE.
#
# zrestart — kill then restart dev servers for any project in zconfig.json.
#
# Usage:
# zrestart <project> [<project> ...] [--port N] [--kill-all] [--no-restart] [--detached] [--bind-host host]
set -uo pipefail
_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$_HERE/zhelpers.sh"
z_need_config
projects=(); port_override=0; kill_all=0; no_restart=0; detached=0; bind_host="127.0.0.1"
while [ $# -gt 0 ]; do
case "$1" in
-p|--port) port_override="${2:-0}"; shift 2 ;;
--kill-all) kill_all=1; shift ;;
--no-restart) no_restart=1; shift ;;
-d|--detached) detached=1; shift ;;
--bind-host) bind_host="${2:-127.0.0.1}"; shift 2 ;;
-*) err "Unknown option: $1"; exit 1 ;;
*) projects+=("$1"); shift ;;
esac
done
if [ "${#projects[@]}" -eq 0 ]; then
printf '\n'; warn "Usage: zrestart <project> [<project> ...] [--port N] [--kill-all] [--no-restart] [--detached] [--bind-host host]"
dim " Projects in zconfig.json: $(zproj_csv)"
exit 1
fi
printf '\n'; info "=== zrestart ==="
for key in "${projects[@]}"; do
info "--- $key ---"
kill_args=("$key")
[ "$port_override" -gt 0 ] 2>/dev/null && kill_args+=(--port "$port_override")
[ "$kill_all" -eq 1 ] && kill_args+=(--kill-all)
"$_HERE/zkill" "${kill_args[@]}" || exit $?
if [ "$no_restart" -eq 0 ]; then
sleep 1
start_args=("$key")
[ "$port_override" -gt 0 ] 2>/dev/null && start_args+=(--port "$port_override")
[ "$bind_host" != "127.0.0.1" ] && start_args+=(--bind-host "$bind_host")
[ "$detached" -eq 1 ] && start_args+=(--detached)
"$_HERE/zstart" "${start_args[@]}" || exit $?
fi
done