forked from elpaso/qgis-feed
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cron job to remove old django sessions (#17)
- Loading branch information
1 parent
b023198
commit 41f07dd
Showing
3 changed files
with
27 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
# How to | ||
|
||
Run `sh add_cronjob.sh` to add the `remove_old_django_session.sh` to crontab. | ||
|
||
If you get a message 'no crontab for [user]' make sure you have a crontab by running this command : | ||
``` | ||
crontab -e | ||
``` |
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,9 @@ | ||
#!/bin/bash | ||
|
||
crontab -l > remove_django_session_cronjob | ||
|
||
echo "0 0 * * * sh ${PWD}/remove_old_django_session.sh" >> remove_django_session_cronjob | ||
|
||
crontab remove_django_session_cronjob | ||
|
||
rm remove_django_session_cronjob |
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,9 @@ | ||
#!/bin/bash | ||
|
||
DOCKER_DB=$(docker ps --format '{{.Names}}' | grep qgis-feed_postgis | head -1) | ||
DB_USER=postgres | ||
DB_NAME=qgisfeed | ||
INTERVAL=1 | ||
|
||
docker exec $DOCKER_DB su - $DB_USER -c "psql -d $DB_NAME -c \"DELETE FROM | ||
DJANGO_SESSION WHERE expire_date < now() - interval '$INTERVAL days';\"" |