Repository navigation
Expand file tree
/
Copy pathworker.sh
More file actions
executable file
·125 lines (110 loc) · 3.99 KB
/
Copy pathworker.sh
File metadata and controls
executable file
·125 lines (110 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
__dirname=$(cd $(dirname "$0"); pwd -P)
cd ${__dirname}
# Drop from root to the corral service account (WO_RUN_AS_USER) for the process
# that writes media, so files land owned by that account instead of nobody on the
# root-squashed corral NFS mount. No-op (runs as current user) when WO_RUN_AS_USER
# is unset or gosu is unavailable, so existing deployments are unaffected.
# See docs/design/2026-07-01-corral-ownership-group-inheritance.md
# Hand the app's root-owned, boot-writable dirs to the service account before
# dropping privileges. WebODM rebuilds plugin assets (webpack.config.js, node_modules,
# public/build) under coreplugins/ at boot; those are root-owned from the image build,
# so a non-root process cannot write them. Persistent plugin data lives on the corral
# media bind (MEDIA_ROOT/plugins), which is already owned by the service account -- do
# NOT chown media here.
prepare_service_account_dirs() {
[ -d /webodm/coreplugins ] && chown -R "$WO_RUN_AS_USER" /webodm/coreplugins 2>/dev/null || true
}
run_as_service() {
if [ -n "$WO_RUN_AS_USER" ] && [ "$(id -u)" = "0" ] && command -v gosu >/dev/null 2>&1; then
prepare_service_account_dirs
exec gosu "$WO_RUN_AS_USER" "$@"
fi
exec "$@"
}
usage(){
echo "Usage: $0 <command>"
echo
echo "This program manages the background worker processes. WebODM requires at least one background process worker to be running at all times."
echo
echo "Command list:"
echo " start Start background worker"
echo " scheduler start Start background worker scheduler"
echo " scheduler stop Stop background worker scheduler"
exit
}
check_command(){
check_msg_prefix="Checking for $1... "
check_msg_result="\033[92m\033[1m OK\033[0m\033[39m"
hash $1 2>/dev/null || not_found=true
if [[ $not_found ]]; then
# Can we attempt to install it?
if [[ ! -z "$3" ]]; then
echo -e "$check_msg_prefix \033[93mnot found, we'll attempt to install\033[39m"
run "$3 || sudo $3"
# Recurse, but don't pass the install command
check_command "$1" "$2"
else
check_msg_result="\033[91m can't find $1! Check that the program is installed and that you have added the proper path to the program to your PATH environment variable before launching WebODM. If you change your PATH environment variable, remember to close and reopen your terminal. $2\033[39m"
fi
fi
echo -e "$check_msg_prefix $check_msg_result"
if [[ $not_found ]]; then
return 1
fi
}
environment_check(){
check_command "celery" "Run \033[1msudo pip install -U celery\033[0m" "pip install -U celery"
if [[ -z "$WO_BROKER" ]]; then
echo -e "\033[91mWO_BROKER environment variable is not set. Defaulting to redis://localhost\033[39m"
export WO_BROKER=redis://localhost
fi
# Only set if `WEB_CONCURRENCY` is not defined, allows overriding.
# See: https://docs.gunicorn.org/en/latest/settings.html#workers
if [ -z "$WEB_CONCURRENCY" ]; then
export WEB_CONCURRENCY=$((2*$(nproc)+1))
fi
}
start(){
action=$1
echo "Starting worker using broker at $WO_BROKER"
umask 002
# Keep the one-shot setup in a subshell: run_as_service uses exec.
(run_as_service python manage.py syncgrids) || return $?
# Group-writable default so media files created by task processing stay g+rw
# for the corral allocation group.
run_as_service celery -A worker worker --autoscale $WEB_CONCURRENCY,2 --max-tasks-per-child 1000 --loglevel=warn > /dev/null
}
start_scheduler(){
stop_scheduler
if [[ ! -f ./celerybeat.pid ]]; then
celery -A worker beat &
else
echo "Scheduler already running (celerybeat.pid exists)."
fi
}
stop_scheduler(){
if [[ -f ./celerybeat.pid ]]; then
kill -9 $(cat ./celerybeat.pid) 2>/dev/null
rm ./celerybeat.pid 2>/dev/null
echo "Scheduler has shutdown."
else
echo "Scheduler is not running."
fi
}
if [[ $1 = "start" ]]; then
environment_check
start
elif [[ $1 = "scheduler" ]]; then
if [[ $2 = "start" ]]; then
environment_check
start_scheduler
elif [[ $2 = "stop" ]]; then
environment_check
stop_scheduler
else
usage
fi
else
usage
fi