From 58554db5796cdb904c67e1e546fdd52ff0cd58c241e5fd0279b70239833df364 Mon Sep 17 00:00:00 2001 From: reclusejay Date: Wed, 29 Oct 2025 21:17:03 +0000 Subject: [PATCH] init.d script for shutterlinksort --- scripts/shutterlinksort-etc-init.d | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 scripts/shutterlinksort-etc-init.d diff --git a/scripts/shutterlinksort-etc-init.d b/scripts/shutterlinksort-etc-init.d new file mode 100644 index 0000000..e615e89 --- /dev/null +++ b/scripts/shutterlinksort-etc-init.d @@ -0,0 +1,67 @@ +#!/bin/bash /etc/rc.common +# shutterlinksort.init +# Copyright (C) 2025 reclusejay (James Blackmore) +# OpenWrt init script for shutterlinksort + +# shellcheck disable=SC2034 # START/STOP used in rc.common +# START/STOP handled by /etc/rc.common +START=96 +STOP=10 + +SCRIPT_NAME="shutterlinksort" +LOCK_FILE="/var/lock/$SCRIPT_NAME" + +start() { + if [ -f "$LOCK_FILE" ]; then + echo "$SCRIPT_NAME is already running (pid=$(cat "$LOCK_FILE"))" + return 0 + fi + + echo "Starting $SCRIPT_NAME..." + "$SCRIPT_NAME" >/dev/null 2>&1 & + pid=$! + + # Verify the process started successfully + if kill -0 "$pid" 2>/dev/null; then + echo "$pid" > "$LOCK_FILE" + echo "$SCRIPT_NAME started with pid=$pid" + else + echo "Failed to start $SCRIPT_NAME" + return 1 + fi +} + +stop() { + if [ ! -f "$LOCK_FILE" ]; then + echo "$SCRIPT_NAME not running" + return 0 + fi + + pid=$(cat "$LOCK_FILE") + echo "Stopping $SCRIPT_NAME (pid=$pid)..." + + if kill "$pid" 2>/dev/null; then + sleep 1 + rm -f "$LOCK_FILE" + echo "$SCRIPT_NAME stopped" + else + echo "Failed to stop $SCRIPT_NAME (process may not exist)" + rm -f "$LOCK_FILE" + return 1 + fi +} + +restart() { + echo "Restarting $SCRIPT_NAME..." + stop + sleep 2 + start +} + +boot() { + start +} + +shutdown() { + stop +}