68 lines
1.3 KiB
Bash
68 lines
1.3 KiB
Bash
#!/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
|
|
}
|