-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
there could only be one startstop.sh
- Loading branch information
Showing
4 changed files
with
204 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
/paperless-ngx-* | ||
/pngquant-* | ||
/Python-* | ||
/redis-* | ||
/sqlite-* | ||
/tessconfigs | ||
/tessdata | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
#!/bin/bash | ||
set -e | ||
set -u | ||
|
||
. build.profile | ||
|
||
TO=${PROJECT}/startstop.sh | ||
|
||
install -m 755 <( cat <<_EOP_ | ||
#!/bin/bash | ||
set -e | ||
set -u | ||
export XDG_RUNTIME_DIR=/run/user/\$(id -u \$USER) | ||
. profile | ||
cd ${PROJECT} | ||
cmd="\${1:-help}" | ||
srv="\${2:-all}" | ||
if [[ \${srv} = 'all' ]]; then | ||
for srv in redis nginx ; do # gunicorn consumer scheduler worker; do | ||
echo "### ./startstop.sh \${cmd} \${srv}" | ||
./startstop.sh \${cmd} \${srv} | ||
done | ||
exit | ||
fi | ||
echo "## ${PROJECT}" | ||
PIDFILE=${DEVSHM}/srv-\${srv}.pid | ||
SIDFILE=${DEVSHM}/srv-\${srv}.sid | ||
PGIDFILE=${DEVSHM}/srv-\${srv}.pgid | ||
function rm_pidfiles() { | ||
rm -fv "\${PIDFILE}" "\${SIDFILE}" "\${PGIDFILE}" | ||
} | ||
#### nginx #### | ||
srv_nginx_start() { | ||
nginx -t | ||
trap rm_pidfiles EXIT | ||
nginx -g 'daemon off;' | ||
} | ||
srv_nginx_restart() { | ||
nginx -s reload | ||
} | ||
srv_nginx_stop() { | ||
nginx -s quit | ||
} | ||
#### redis #### | ||
srv_redis_start() { | ||
local _opts=( | ||
--port 0 | ||
--unixsocket "${DEVSHM}/redis.sock" | ||
--pidfile "${DEVSHM}/redis.pid" | ||
) | ||
trap rm_pidfiles EXIT | ||
redis-server "\${_opts[@]}" | ||
} | ||
#### gunicorn #### | ||
srv_gunicorn_start() { | ||
cd "${PROJECT}/paperless-ngx/src" | ||
_opts=( | ||
--config ../gunicorn.conf.py | ||
paperless.asgi:application | ||
--bind "unix:${DEVSHM}/gunicorn.sock" | ||
--pid "${DEVSHM}/gunicorn.pid" | ||
--error-logfile "${LOGDIR}/gunicorn-error.log" | ||
--access-logfile "${LOGDIR}/gunicorn-access.log" | ||
--worker-tmp-dir "${DEVSHM}" | ||
) | ||
trap rm_pidfiles EXIT | ||
gunicorn "\${_opts[@]}" | ||
} | ||
#### consumer #### | ||
srv_consumer_start() { | ||
cd "${PROJECT}/paperless-ngx/src" | ||
trap rm_pidfiles EXIT | ||
./manage.py document_consumer | ||
} | ||
#### scheduler #### | ||
srv_scheduler_start() { | ||
cd "${PROJECT}/paperless-ngx/src" | ||
trap rm_pidfiles EXIT | ||
celery --app paperless beat --loglevel INFO | ||
} | ||
#### worker #### | ||
srv_worker_start() { | ||
cd "${PROJECT}/paperless-ngx/src" | ||
trap rm_pidfiles EXIT | ||
celery --app paperless worker --loglevel WARNING | ||
} | ||
#### generic #### | ||
srv_generic_status() { | ||
if [[ -s "\${PGIDFILE}" ]]; then | ||
local pgid | ||
read -a pgid < "\${PGIDFILE}" | ||
local pids | ||
pids=\$(pgrep -g \${pgid}) | ||
if [[ \$? = 0 ]]; then | ||
ps -f --pid \${pids} | ||
else | ||
echo "processs group \${pgid} has no running processes for \${PGIDFILE}" | ||
fi | ||
else | ||
if [[ -s "\${PIDFILE}" ]]; then | ||
local pid | ||
read -a pid < "\${PIDFILE}" | ||
ps -f --pid \${pid} --ppid \${pid} | ||
else | ||
echo "# no pgid or pid file found: \${PGIDFILE} \${PIDFILE} " | ||
fi | ||
fi | ||
} | ||
srv_generic_stop() { | ||
if [[ -s "\${PGIDFILE}" ]]; then | ||
local pgid | ||
read -a pgid < "\${PGIDFILE}" | ||
echo "killing process group \${pgid}" | ||
kill -- -\${pgid} | ||
echo "waiting for process group \${pgid} to die" | ||
pwait --pgroup \${pgid} | ||
else | ||
if [[ -s "\${PIDFILE}" ]]; then | ||
local pid | ||
read -a pid < "\${PIDFILE}" | ||
ps -f --pid \${pid} --ppid \${pid} | ||
else | ||
echo "# no pid file found: \${PGIDFILE}" | ||
fi | ||
fi | ||
} | ||
srv_generic_restart() { | ||
srv_generic_stop | ||
srv_generic_start | ||
} | ||
#### main() #### | ||
set -x | ||
if [[ \$(type -t srv_\${srv}_\${cmd}) = 'function' ]]; then | ||
case "\${cmd}" in | ||
start) | ||
mkdir -p "${DEVSHM}" "${LOGDIR}" "${TMPDIR}" | ||
[[ -s "\${PIDFILE}" ]] && echo "# \${PIDFILE} found, refuse start of \${srv}" && exit 0 | ||
[[ -s "\${SIDFILE}" ]] && echo "# \${SIDFILE} found, refuse start of \${srv}" && exit 0 | ||
[[ -s "\${PGIDFILE}" ]] && echo "# \${PGIDFILE} found, refuse start of \${srv}" && exit 0 | ||
coproc { | ||
set -m | ||
srv_\${srv}_\${cmd}; | ||
} > ${LOGDIR}/srv-\${srv}.log 2>&1 | ||
echo "\${COPROC_PID}" > "\${PIDFILE}" | ||
ps opgid= "\${COPROC_PID}" > "\${PGIDFILE}" | ||
ps osid= "\${COPROC_PID}" > "\${SIDFILE}" | ||
exit | ||
;; | ||
*) | ||
srv_\${srv}_\${cmd} | ||
exit | ||
;; | ||
esac | ||
else | ||
echo "srv_\${srv}_\${cmd}() not declared" | ||
if [[ \$(type -t srv_generic_\${cmd}) = 'function' ]]; then | ||
srv_generic_\${cmd} | ||
exit | ||
fi | ||
fi | ||
echo "#### oh no... ####" | ||
_EOP_ | ||
) ${TO} |