Skip to content

Commit

Permalink
Improvement on shell script log per service & uninstall (#210)
Browse files Browse the repository at this point in the history
* run on fork codeql and pylint

* use service name for /var/log folder

* remove the whole service directory

* fix typo

* break while loop

* service removal, check for directory delete link
  • Loading branch information
henne49 committed Aug 14, 2024
1 parent bc71633 commit 40017c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion service/log/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/sh
exec 2>&1
#Script Directory
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SCRIPT_DIR=$(realpath $SCRIPT_DIR/../../)
SERVICE_NAME=$(basename $SCRIPT_DIR)
# documentation on how to use multilog https://manpages.debian.org/stretch/daemontools/multilog.8.en.html
exec multilog t s153600 n2 /var/log/dbus-opendtu
exec multilog t s153600 n2 /var/log/${SERVICE_NAME}
19 changes: 17 additions & 2 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SERVICE_NAME=$(basename $SCRIPT_DIR)
LOG_DIR=/var/log/$SERVICE_NAME
RC_LOCAL_FILE=/data/rc.local

#remove the service
rm /service/$SERVICE_NAME
if [ -d /service/$SERVICE_NAME ]; then
rm /service/$SERVICE_NAME
fi

# end the dbus-opendtu process
kill $(pgrep -f "python $SCRIPT_DIR/dbus-opendtu.py")
Expand All @@ -16,4 +19,16 @@ fi

# remove install.sh from rc.local
STARTUP=$SCRIPT_DIR/install.sh
sed -i "\~$STARTUP~d" $RC_LOCAL_FILE
sed -i "\~$STARTUP~d" $RC_LOCAL_FILE

# delete log folder in var log if they exist
if [ -d $LOG_DIR ]; then
while true; do
read -p "Do you really wish to delete the log folder $LOG_DIR? [y/n]" yn
case $yn in
[Yy]* ) rm -rf $LOG_DIR; echo $LOG_DIR is deleted ; break;;
[Nn]* ) break;;
* ) echo "Please answer y or n.";;
esac
done
fi

0 comments on commit 40017c5

Please sign in to comment.