From b0eb23c0930611889ed615bc2f431e30b35bbbbe Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 4 May 2016 11:14:03 +0200 Subject: Makefile, manpage neu, Versionsupdate --- .gitignore | 3 +++ Makefile | 44 ++++++++++++++++++++++++++++++++++ shutdownasap | 65 -------------------------------------------------- shutdownasap.8.in | 36 ++++++++++++++++++++++++++++ shutdownasap.conf | 24 ------------------- shutdownasap.conf.in | 32 +++++++++++++++++++++++++ shutdownasap.in | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 182 insertions(+), 89 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile delete mode 100755 shutdownasap create mode 100644 shutdownasap.8.in delete mode 100755 shutdownasap.conf create mode 100755 shutdownasap.conf.in create mode 100755 shutdownasap.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03c8959 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +shutdownasap +shutdownasap.8 +shutdownasap.conf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2eb0c1e --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +# +# shutdownasap - simple script for shutdown waiting for certain processes and files to disapear +# +# Copyright (c) 2015-2016 Erich Eckner +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +DESTDIR = +ETCDIR = /etc +BINDIR = /usr/bin +MANDIR = /usr/share/man + +VERSION = 0.2 + +all: shutdownasap shutdownasap.conf shutdownasap.8 + +%: %.in + sed "s/#VERSION#/$(VERSION)/; s@#BINDIR#@$(BINDIR)@; s@#ETCDIR#@$(ETCDIR)@" $< > $@ + +.PHONY: install clean + +install: all + install -D -m0755 -t $(DESTDIR)$(BINDIR) shutdownasap + install -D -m0644 -t $(DESTDIR)$(MANDIR)/man8 shutdownasap.8 + install -D -m0644 -t $(DESTDIR)$(ETCDIR) shutdownasap.conf + +clean: + rm -f shutdownasap{,.8,.conf} + +# End of file diff --git a/shutdownasap b/shutdownasap deleted file mode 100755 index 027511b..0000000 --- a/shutdownasap +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -. /etc/shutdownasap.conf - -[ -r "${pidFile}" ] && ps aux | grep -q "^\S\+\s\+$(cat "${pidFile}") " && exit - -echo $$ > "${pidFile}" - -beforeWatchHook - -i=1 -while [ ${i} -gt 0 ] -do - sleep 1 - prozesse="$(ps aux | grep -v grep)" - - nochwarten=false - - if [ -d "${waitForDir}" ] && ls -1A "${waitForDir}" | grep -q "." - then - nochwarten=true - echo ".warteauf: " - ls -1A "${waitForDir}" - fi - - if users | grep -q "." - then - nochwarten=true - echo -n "users: " - users - fi - - for synActFile in /sys/block/md*/md/sync_action - do - if [ -r "${synActFile}" ] && ! grep -q "^idle\$" "${synActFile}" - then - nlochWarten=true - echo -n "raid ${synActFile}: " - cat "${synActFile}" - fi - done - - for s in "${!shutDownNoGos[@]}" - do - if [ -e "${shutDownNoGos[${s}]}" ] || echo "${prozesse}" | grep -q "\(\s\|/\)${shutDownNoGos[${s}]}\(\$\|\s\)" - then - nochwarten=true - echo "prozess: ${s}" - fi - done - - if ${nochwarten} - then - echo "warten ..." - i=10 - continue - else - echo "noch ${i} Sekunden" - fi - i=$[${i}-1] -done - -beforeShutDownHook - -sudo /sbin/poweroff diff --git a/shutdownasap.8.in b/shutdownasap.8.in new file mode 100644 index 0000000..34e3aad --- /dev/null +++ b/shutdownasap.8.in @@ -0,0 +1,36 @@ +.TH shutdownasap 8 "" "shutdownasap #VERSION#" "" +.SH NAME +shutdownasap \- simple script for \fBshutdown\fP waiting for certain processes and files to disapear +.SH SYNOPSIS +\fBshutdownasap\fP +.SH DESCRIPTION +\fBshutdownasap\fP shuts down the computer after a certain directory becomes empty and certain processes are not running. +For actually shutting down it calls \fBsudo shutdown\fP. +.SH CONFIGURATION +The configfile \fB#ETCDIR#/shutdownasap.conf\fP is a bash script, which defines the following variables and routines: +.TP +.B "pidFile" +file to store pid in +.TP +.B "waitForDir" +directory which must be empty before shutting down +.TP +.B "shutDownNoGos" +list of processes which must not be running before shutting down +.TP +.B "beforeWatchHook" +routine which is called after start of \fBshutdownasap\fP, before watching above conditions +.TP +.B "beforeShutDownHook" +routine which is called before shutting down +.SH FILES +.TP +.B "#BINDIR#/shutdownasap" +program file +.TP +.B "#ETCDIR#/shutdownasap.conf" +contains configuration +.SH AUTHOR +.nf +Erich Eckner +.fi diff --git a/shutdownasap.conf b/shutdownasap.conf deleted file mode 100755 index 50d32eb..0000000 --- a/shutdownasap.conf +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - - -pidFile="/tmp/shutdownasap.pid" -waitForDir="/home/shutdown/.warteauf" - -declare -A shutDownNoGos - -shutDownNoGos["backup"]="[^/ ]*backup" -shutDownNoGos["dd"]="dd" -shutDownNoGos["ncat"]="ncat" -shutDownNoGos["ports"]="ports" -shutDownNoGos["prt-get"]="prt-get" -shutDownNoGos["rsync"]="rsync" -shutDownNoGos["wget"]="wget" -shutDownNoGos["wetter"]="/tmp/wetter.pid" - -beforeWatchHook() { - true -} - -beforeShutDownHook() { - true -} diff --git a/shutdownasap.conf.in b/shutdownasap.conf.in new file mode 100755 index 0000000..cb8e603 --- /dev/null +++ b/shutdownasap.conf.in @@ -0,0 +1,32 @@ +#!/bin/bash + +# configuration file for shutdownasap version #VERSION# +# it should be named #ETCDIR#/shutdownasap.conf + +# shutdownasap's pid +pidFile="/tmp/shutdownasap.pid" + +# directory must be empty before shutdown +waitForDir="/home/shutdown/.warteauf" + +# list of processes which must not be running before shutdown +declare -A shutDownNoGos + +shutDownNoGos["backup"]="[^/ ]*backup" +shutDownNoGos["dd"]="dd" +shutDownNoGos["ncat"]="ncat" +shutDownNoGos["ports"]="ports" +shutDownNoGos["prt-get"]="prt-get" +shutDownNoGos["rsync"]="rsync" +shutDownNoGos["wget"]="wget" +shutDownNoGos["wetter"]="/tmp/wetter.pid" + +# hook to execute after start of shutdownasap, before watching above conditions +beforeWatchHook() { + true +} + +# hook to execute before shutting down +beforeShutDownHook() { + true +} diff --git a/shutdownasap.in b/shutdownasap.in new file mode 100755 index 0000000..0afd586 --- /dev/null +++ b/shutdownasap.in @@ -0,0 +1,67 @@ +#!/bin/bash + +# shutdownasap version #VERSION# + +. #ETCDIR#/shutdownasap.conf + +[ -r "${pidFile}" ] && ps aux | grep -q "^\S\+\s\+$(cat "${pidFile}") " && exit + +echo $$ > "${pidFile}" + +beforeWatchHook + +i=1 +while [ ${i} -gt 0 ] +do + sleep 1 + prozesse="$(ps aux | grep -v grep)" + + nochwarten=false + + if [ -d "${waitForDir}" ] && ls -1A "${waitForDir}" | grep -q "." + then + nochwarten=true + echo ".warteauf: " + ls -1A "${waitForDir}" + fi + + if users | grep -q "." + then + nochwarten=true + echo -n "users: " + users + fi + + for synActFile in /sys/block/md*/md/sync_action + do + if [ -r "${synActFile}" ] && ! grep -q "^idle\$" "${synActFile}" + then + nlochWarten=true + echo -n "raid ${synActFile}: " + cat "${synActFile}" + fi + done + + for s in "${!shutDownNoGos[@]}" + do + if [ -e "${shutDownNoGos[${s}]}" ] || echo "${prozesse}" | grep -q "\(\s\|/\)${shutDownNoGos[${s}]}\(\$\|\s\)" + then + nochwarten=true + echo "prozess: ${s}" + fi + done + + if ${nochwarten} + then + echo "warten ..." + i=10 + continue + else + echo "noch ${i} Sekunden" + fi + i=$[${i}-1] +done + +beforeShutDownHook + +sudo /sbin/poweroff -- cgit v1.2.3-54-g00ecf