Added workers

merge-requests/2/head
Dominika 2020-07-27 10:59:15 +02:00
parent 0c44c92dab
commit 4132345e3d
5 changed files with 37 additions and 0 deletions

6
config/app.sh Normal file
View File

@ -0,0 +1,6 @@
# app config - loaded on server bootup
# this example file will get overwritten with application-specific config
# worker_add <worker> <interval>
# ---
# worker_add example 5

View File

@ -6,6 +6,12 @@ function ctrl_c() {
echo -e "Killed all remaining processes.\nHave a great day!!"
}
source src/worker.sh
if [[ -f "config/app.sh" ]]; then
source config/app.sh
fi
source config/master.sh
echo "HTTP.sh"

22
src/worker.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
# worker.sh - setup and control of workers
# worker_add(name, interval)
function worker_add() {
if [[ -x "workers/$1/worker.sh" ]]; then
while true; do workers/$1/worker.sh; sleep $2; if [[ $(cat workers/$1/control) == "die" ]]; then echo "" > workers/$1/control; while true; do if [[ $(cat workers/$1/control) == "run" ]]; then echo "" > workers/$1/control; break; fi; sleep $2; done; fi; done &
else
echo "You have a broken worker configuration! Please check if worker.sh in worker $1 is executable."
fi
}
# worker_kill(name)
function worker_kill() {
echo "die" > workers/$1/control
}
# worker_resume(name)
function worker_resume() {
echo "run" > workers/$i/control
}

1
workers/example/control Normal file
View File

@ -0,0 +1 @@

2
workers/example/worker.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
date