-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_db_update.sh
executable file
·64 lines (49 loc) · 1.57 KB
/
auto_db_update.sh
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
#!/bin/zsh
cd /Users/minho/code/django/childcare || exit
echo "childcare: auto_db_update.sh"
source .venv/bin/activate
echo "starting django server: childcare"
nohup python3 manage.py runserver 8999 >django.log 2>&1 &
DJANGO_PID=$!
/opt/homebrew/bin/redis-cli config set stop-writes-on-bgsave-error no
if /opt/homebrew/bin/redis-cli ping | grep -q "PONG"; then
echo "redis is running: 🏓 PONG"
echo "starting celery worker: childcare"
nohup celery -A project worker --beat --scheduler django --loglevel=info >celery.log 2>&1 &
CELERY_PID=$!
tail -f celery.log &
TAIL_PID=$!
else
echo "redis not running, celery will not start"
exit 1
fi
sleep 30
echo "committing changes..."
git add db.sqlite3
git commit -m "$(date '+%Y-%m-%d:%H:%M:%S-auto-db-update')"
git push
echo "cleaning up logs..."
/opt/homebrew/bin/trash django.log celery.log
echo "terminating processes..."
# kill $DJANGO_PID
# kill $CELERY_PID
# kill $TAIL_PID
if [ -n "$DJANGO_PID" ] && ps -p $DJANGO_PID >/dev/null; then
echo "Terminating Django process with PID: $DJANGO_PID"
kill $DJANGO_PID
else
echo "Django process with PID $DJANGO_PID is not running"
fi
if [ -n "$CELERY_PID" ] && ps -p $CELERY_PID >/dev/null; then
echo "Terminating Celery process with PID: $CELERY_PID"
kill $CELERY_PID
else
echo "Celery process with PID $CELERY_PID is not running"
fi
if [ -n "$TAIL_PID" ] && ps -p $TAIL_PID >/dev/null; then
echo "Terminating tail process with PID: $TAIL_PID"
kill $TAIL_PID
else
echo "Tail process with PID $TAIL_PID is not running"
fi
echo "done"