summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Graham <joseph@fibreglass.tunachunks>2014-07-13 07:47:28 +0100
committerJoseph Graham <joseph@fibreglass.tunachunks>2014-07-13 07:47:28 +0100
commit7aeaf3525f58c710ed68c5e3cd8d6937b5fb2c7d (patch)
treee32bb4f7057932feded5c0d4868971d52284bd2a
parentf77996ae7cffaec854bc88b66e7eb6a6ad325c62 (diff)
improvements
-rw-r--r--pbot60
1 files changed, 40 insertions, 20 deletions
diff --git a/pbot b/pbot
index ac65193..a619241 100644
--- a/pbot
+++ b/pbot
@@ -1,29 +1,49 @@
#! /bin/bash
-declare -a pids
+if [[ "${1}" == 'start' ]]
+then
+ declare -a pids
-cd /home/pbot
+ cd /home/pbot
-./envbot &
-pids[0]=$!
+ ./envbot &
+ pids[0]=$!
-./pbot-ng_fixer &
-pids[1]=$!
+ ./pbot-ng_fixer &
+ pids[1]=$!
-./labs_change_detector &
-pids[2]=$!
+ ./labs_change_detector &
+ pids[2]=$!
-function closedown
-{
- for pid in ${pids[@]}
- do
- kill $pid
- done
-}
+ function closedown
+ {
+ for pid in ${pids[@]}
+ do
+ kill $pid
+ done
-trap "closedown" SIGINT SIGTERM
+ exit
+ }
-while true
-do
- sleep 5h
-done
+ trap "closedown" SIGINT SIGTERM
+
+ while true
+ do
+ sleep 5h
+ done
+elif [[ "${1}" == 'stop' ]]
+then
+ while true
+ do
+ pid=$(pgrep -u pbot | head -1)
+
+ if [[ -n "${pid}" ]]
+ then
+ kill ${pid} &>/dev/null
+ else
+ exit
+ fi
+ done
+else
+ echo "first arg must be \`start' or \`stop'"
+fi