2022-03-16 23:33:44 +01:00
|
|
|
# TO MAKE THIS SCRIPT WORK:
|
|
|
|
|
# create the following file: scripts/sync_to_blitz.personal.sh (it will be ignored by git and not commited)
|
|
|
|
|
# add the following two lines to that files and fill with personal data of your development blitz:
|
|
|
|
|
localIP=""
|
2022-05-05 13:27:59 +02:00
|
|
|
sshPort="22"
|
2022-03-16 23:33:44 +01:00
|
|
|
passwordA=""
|
2021-12-05 21:14:25 +01:00
|
|
|
|
2022-03-16 23:33:44 +01:00
|
|
|
# get personal blitz info
|
|
|
|
|
source scripts/sync_to_blitz.personal.sh
|
|
|
|
|
if [ "${localIP}" = "" ] || [ "${passwordA}" == "" ]; then
|
|
|
|
|
echo "FAIL: please create scripts/sync_to_blitz.personal.sh file with localIP & passwordA info."
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# check if sshpass is installed
|
|
|
|
|
sshpassInstalled=$(sshpass -V | grep -c "sshpass")
|
|
|
|
|
if [ ${sshpassInstalled} -eq 0 ]; then
|
2022-03-23 00:52:37 +01:00
|
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
2022-03-16 23:33:44 +01:00
|
|
|
echo "FAIL: please make sure that sshpass is installed on your system"
|
|
|
|
|
echo "macOS: brew install hudochenkov/sshpass/sshpass"
|
2022-03-19 12:22:15 +01:00
|
|
|
echo "Linux(Debian): apt install sshpass"
|
2022-03-20 17:20:56 +01:00
|
|
|
exit
|
2022-03-19 12:22:15 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# check if ping is installed
|
2022-03-23 00:52:37 +01:00
|
|
|
pingInstalled=$(ping -c 1 1.1.1.1 | grep -c "PING")
|
2022-03-19 12:22:15 +01:00
|
|
|
if [ ${pingInstalled} -eq 0 ]; then
|
2022-03-23 00:52:37 +01:00
|
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
2022-03-19 12:22:15 +01:00
|
|
|
echo "FAIL: please make sure that ping is installed on your system"
|
|
|
|
|
echo "Linux(Debian): apt install inetutils-ping OR apt install iputils-ping"
|
2022-03-20 17:20:56 +01:00
|
|
|
exit
|
2022-03-16 23:33:44 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# check if localIP is available&responding
|
|
|
|
|
ping -c 1 $localIP
|
|
|
|
|
if [ "$?" != "0" ]; then
|
2022-03-23 00:52:37 +01:00
|
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
2022-03-16 23:33:44 +01:00
|
|
|
echo "FAIL: was not able to ping $localIP"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
2021-12-05 21:14:25 +01:00
|
|
|
|
|
|
|
|
local=.
|
2022-06-30 12:44:13 +02:00
|
|
|
remoteRepoPath="/home/blitzapi/blitz_api"
|
2022-06-04 16:45:32 +02:00
|
|
|
remote="admin@$localIP:${remoteRepoPath}"
|
2021-12-05 21:14:25 +01:00
|
|
|
|
2022-05-05 13:27:59 +02:00
|
|
|
# clean pycache just in case the code was compiled locally before
|
2022-05-12 19:49:01 +02:00
|
|
|
echo "# local cache delete .."
|
|
|
|
|
rm -r ./app/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/repositories/ln_impl/protos/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/repositories/ln_impl/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/external/fastapi_versioning/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/external/sse_starlette/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/external/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/models/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/repositories/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/routers/__pycache__ 2>/dev/null
|
|
|
|
|
rm -r ./app/auth/__pycache__ 2>/dev/null
|
2022-05-05 13:27:59 +02:00
|
|
|
|
2022-06-04 16:45:32 +02:00
|
|
|
# make sure remote repo files can be overwritten bei user admin
|
2022-12-18 10:20:51 +01:00
|
|
|
echo "# sshpass Test"
|
2022-06-04 16:45:32 +02:00
|
|
|
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP "sudo chown -R admin:admin ${remoteRepoPath}"
|
|
|
|
|
result=$?
|
|
|
|
|
echo "result(${result})"
|
|
|
|
|
if [ "$result" != "0" ]; then
|
|
|
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
|
|
|
echo "FAIL: was not able to ssh in: ssh -p ${sshPort} admin@$localIP"
|
2022-12-18 10:20:51 +01:00
|
|
|
echo "Is password correct? --> ${passwordA}"
|
|
|
|
|
echo "Too often wrong password? Wait a bit."
|
2022-06-04 16:45:32 +02:00
|
|
|
echo "SSH in once manually. Then try again."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2021-12-05 21:14:25 +01:00
|
|
|
# Needs sshpass installed
|
2022-03-16 23:33:44 +01:00
|
|
|
echo "# syncing local code to: ${remote}"
|
2025-11-10 11:51:15 +01:00
|
|
|
sshpass -p "$passwordA" rsync -rvz --exclude .devenv/ --exclude .venv/ --exclude .env --exclude test_env_data/ --exclude .git/ -e "ssh -p ${sshPort}" $local $remote
|
2022-03-23 00:52:37 +01:00
|
|
|
result=$?
|
|
|
|
|
echo "result(${result})"
|
2022-05-05 13:27:59 +02:00
|
|
|
if [ "$result" != "0" ]; then
|
2022-03-23 00:52:37 +01:00
|
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
2022-06-04 16:45:32 +02:00
|
|
|
echo "FAIL: was not able to rsync"
|
2022-03-23 00:52:37 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2022-03-13 18:46:47 +01:00
|
|
|
|
2025-04-14 15:37:19 +02:00
|
|
|
# make sure uploaded/synced files belong again to the correct raspiblitz user to run
|
2022-06-30 12:48:58 +02:00
|
|
|
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP "sudo chown -R blitzapi:blitzapi ${remoteRepoPath}"
|
|
|
|
|
|
2022-03-13 18:46:47 +01:00
|
|
|
# Restart the blitz service to activate changes
|
2025-04-14 15:37:19 +02:00
|
|
|
echo "# restarting service 'blitzapi.service'"
|
2022-05-05 13:27:59 +02:00
|
|
|
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP 'sudo systemctl restart blitzapi.service'
|
2025-04-14 15:37:19 +02:00
|
|
|
echo "# restarting service 'blitzapi-celery-beat.service'"
|
|
|
|
|
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP 'sudo systemctl restart blitzapi-celery-beat.service'
|
|
|
|
|
echo "# restarting service 'blitzapi-celery-worker.service'"
|
|
|
|
|
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP 'sudo systemctl restart blitzapi-celery-worker.service'
|
2022-03-13 18:46:47 +01:00
|
|
|
|
|
|
|
|
# Get latest logs entries
|
2022-03-16 23:33:44 +01:00
|
|
|
echo "# latest log entries"
|
2025-04-14 15:37:19 +02:00
|
|
|
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP "sudo journalctl -u blitzapi-celery-worker.service -n 40 --no-pager --no-hostname"
|
2022-03-13 18:46:47 +01:00
|
|
|
|
|
|
|
|
# Watch the logs
|
2022-03-16 23:33:44 +01:00
|
|
|
echo "# watching logs - CTRL+C to exit"
|
2025-04-14 15:37:19 +02:00
|
|
|
sshpass -p "$passwordA" ssh -p $sshPort admin@$localIP "sudo journalctl -u 'blitzapi*' -f --no-hostname"
|