diff --git a/backup.sh b/backup.sh index 4e88d56..562d596 100755 --- a/backup.sh +++ b/backup.sh @@ -176,6 +176,58 @@ function scriptHelp { exit 1 } +### start and stop seafile services +function svcSeafile { + if [ "$1" = "start" ]; then + # start services + systemctl start seafile.service + statusSeaf=$? + systemctl start seahub.service + statusShub=$? + # check for errors + if [ $statusSeaf -eq 0 ] && [ $statusShub -eq 0 ]; then + echo -e "${info}[$(stamp)] -- [INFO] Seafile services started" \ + "successfully --${normal}" >> "$logFile" + else + exitError+=("[$(stamp)] 100") + quit + fi + elif [ "$1" = "stop" ]; then + # stop services + systemctl stop seahub.service + statusShub=$? + systemctl stop seafile.service + statusSeaf=$? + # check for errors + if [ $statusSeaf -eq 0 ] && [ $statusShub -eq 0 ]; then + echo -e "${info}[$(stamp)] -- [INFO] Seafile services stopped" \ + "successfully --${normal}" >> "$logFile" + else + # verify services are still actually running + pidShub=$(pgrep -f "seahub") + pidSeaf=$(pgrep -f seafile-controller) + # force stop seahub + if [ $pidShub ]; then + pkill -f "seahub" + echo -e "${warn}[$(stamp)] -- [WARN] Could NOT stop" \ + "Seahub normally (forced stop) --${normal}" \ + >> "$logFile" + exitWarn+=("[$(stamp)]_101") + fi + # force stop seafile + if [ $pidSeaf ]; then + pkill -f seafile-controller + echo -e "${warn}[$(stamp)] -- [WARN] Could NOT stop" \ + "Seafile normally (forced stop) --${normal}" \ + >> "$logFile" + exitWarn+=("[$(stamp)]_101") + fi + echo -e "${info}[$(stamp)] -- [INFO] Seafile services stopped" \ + "successfully --${normal}" >> "$logFile" + fi + fi +} + ### generate dynamic timestamps function stamp { (date +%F" "%T)