summaryrefslogtreecommitdiff
path: root/scripts/restart-app
diff options
context:
space:
mode:
authorryukamish <[email protected]>2026-04-11 18:25:38 +0530
committerryukamish <[email protected]>2026-04-11 18:25:38 +0530
commitb3474e85dcce03e7de0b4a4e30ff7fad1f38ee26 (patch)
treebcfe42ad76a825c283eec653140ab4052f0b3017 /scripts/restart-app
parent607891801fbf2051a0c9062d15a445dd238c1e1b (diff)
add: small bash scripts for added functionality
Diffstat (limited to 'scripts/restart-app')
-rwxr-xr-xscripts/restart-app31
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/restart-app b/scripts/restart-app
new file mode 100755
index 0000000..84edebc
--- /dev/null
+++ b/scripts/restart-app
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+# Exit if no app name provided
+[ -z "$1" ] && exit 1
+
+APP_NAME="$1"
+shift # Remove app name, leaving any additional arguments
+
+# Check if app exists in PATH
+command -v "$APP_NAME" >/dev/null 2>&1 || exit 1
+
+# Check if app is running and kill it
+if pgrep -x "$APP_NAME" >/dev/null 2>&1; then
+ # Send SIGTERM (graceful shutdown)
+ pkill -x "$APP_NAME"
+
+ # Wait for up to 2 seconds for the process to terminate
+ for i in {1..20}; do
+ pgrep -x "$APP_NAME" >/dev/null 2>&1 || break
+ sleep 0.1
+ done
+
+ # Force kill if still running
+ if pgrep -x "$APP_NAME" >/dev/null 2>&1; then
+ pkill -9 -x "$APP_NAME"
+ sleep 0.1
+ fi
+fi
+
+# Start the app detached with any additional arguments
+setsid -f "$APP_NAME" "$@" >/dev/null 2>&1