From 1fe503ab6a6c869b71f13a6ec66ca15efedc4cb3 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 2 Jun 2024 13:18:14 +0800 Subject: removed delay for idle, added cleanup for terminate and SIGINT(removing locks) --- idle.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'idle.sh') diff --git a/idle.sh b/idle.sh index 69d2b4c..f1f03f9 100755 --- a/idle.sh +++ b/idle.sh @@ -23,6 +23,16 @@ if [ ! -d $lockpath ]; then sudo /sbin/mkdir -vp $lockpath || /sbin/echo "Failed to create lock path at $lockpath" fi +function cleanup() { + /sbin/echo "Cleaning up..." + sudo /sbin/rm -f $lockpath/$lockfile || /sbin/echo "Failed removing lock file at $lockpath/$lockfile" + sudo /sbin/rm -f $lockpath/$pidfile || /sbin/echo "Failed removing PID file at $lockpath/$pidfile" + sudo /sbin/rm -f $lockpath/$disablelockfile || /sbin/echo "Failed removing disable lock file at $lockpath/$disablelockfile" + /sbin/echo "Exiting..." +} + +trap cleanup SIGINT SIGTERM + function idle() { if [[ -f $lockpath/$disablelockfile ]]; then /sbin/echo "idle: Idle is disabled" @@ -105,7 +115,6 @@ if [ "$1" ]; then stopidle continue else - sleep 1 continue fi fi -- cgit v1.2.3