Skip to content

Commit

Permalink
add logrotate
Browse files Browse the repository at this point in the history
  • Loading branch information
SkywalkerSpace committed Sep 2, 2021
1 parent aff7b45 commit 88af5f3
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docker/scripts/enterpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ if [[ -f /shared/ssl/renew_cert ]]; then
fi


# logrotate
chmod 0644 /scripts/logrotate-conf/logrotate-cron
/usr/bin/crontab /scripts/logrotate-conf/logrotate-cron


# autorun
echo
echo "Starting SeaTable Thumbnail"
Expand Down
3 changes: 3 additions & 0 deletions docker/scripts/logrotate-conf/logrotate-cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

54 23 * * * /usr/sbin/logrotate -vf /scripts/logrotate-conf/seatable-nginx 2>> /opt/seatable-thumbnail/logs/logrotate.log
55 23 * * * /usr/sbin/logrotate -vf /scripts/logrotate-conf/seatable-thumbnail 2>> /opt/seatable-thumbnail/logs/logrotate.log
53 changes: 53 additions & 0 deletions docker/scripts/logrotate-conf/logrotate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

function stop_server() {
pkill -9 -f seaf-server
pkill -9 -f uvicorn
pkill -9 -f multiprocessing

rm -f /opt/seatable-thumbnail/pids/*.pid
}

function set_env() {
export SRC_DIR=/opt/seatable-thumbnail/
export LD_LIBRARY_PATH=/opt/seatable-thumbnail/seafile/lib/
export PYTHONPATH=/opt/seatable-thumbnail/seafile/lib/python3.6/site-packages/:/usr/lib/python3.6/dist-packages:/usr/lib/python3.6/site-packages:/usr/local/lib/python3.6/dist-packages:/usr/local/lib/python3.6/site-packages
export PATH=/opt/seatable-thumbnail/seafile/bin/:$PATH

export CCNET_CONF_DIR=/opt/seatable-thumbnail/ccnet
export SEAFILE_CONF_DIR=/opt/seatable-thumbnail/seafile-data
export SEAFILE_CENTRAL_CONF_DIR=/opt/seatable-thumbnail/conf
}


function start_server() {

stop_server
sleep 0.5

set_env

seaf-server -F /opt/seatable-thumbnail/conf -c /opt/seatable-thumbnail/ccnet -d /opt/seatable-thumbnail/seafile-data -l /opt/seatable-thumbnail/logs/seafile.log -L /opt/seatable-thumbnail -P /opt/seatable-thumbnail/pids/seafile.pid - &
sleep 0.2

cd /opt/seatable-thumbnail/seatable-thumbnail-server/
/usr/local/bin/uvicorn main:app --host 127.0.0.1 --port 8088 --workers 4 --access-log --proxy-headers &>> /opt/seatable-thumbnail/logs/seatable-thumbnail.log &
sleep 0.2

echo "SeaTable-thumbnail-server started by logrotate"
echo

}


case $1 in
"start")
start_server
;;
"stop")
stop_server
;;
*)
start_server
;;
esac
17 changes: 17 additions & 0 deletions docker/scripts/logrotate-conf/seatable-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/opt/nginx-logs/*.log {
daily
missingok
rotate 7
# compress
# delaycompress
dateext
dateformat .%Y-%m-%d
notifempty
# create 640 nginx adm
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
17 changes: 17 additions & 0 deletions docker/scripts/logrotate-conf/seatable-thumbnail
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/opt/seatable-thumbnail/logs/seafile.log
/opt/seatable-thumbnail/logs/seatable-thumbnail.log
{
daily
missingok
rotate 7
# compress
# delaycompress
dateext
dateformat .%Y-%m-%d
notifempty
create 644 root root
sharedscripts
postrotate
/scripts/logrotate-conf/logrotate.sh restart
endscript
}
2 changes: 1 addition & 1 deletion docker/scripts/monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function monitor_seatable_thumbnail() {
pkill -9 -f multiprocessing
sleep 0.2
cd /opt/seatable-thumbnail/seatable-thumbnail-server/
uvicorn main:app --host 127.0.0.1 --port 8088 --workers 4 --access-log --proxy-headers &>> /opt/seatable-thumbnail/logs/seatable-thumbnail.log &
/usr/local/bin/uvicorn main:app --host 127.0.0.1 --port 8088 --workers 4 --access-log --proxy-headers &>> /opt/seatable-thumbnail/logs/seatable-thumbnail.log &
sleep 0.2
fi
}
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/seatable-thumbnail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function start_server() {
sleep 0.2

cd /opt/seatable-thumbnail/seatable-thumbnail-server/
uvicorn main:app --host 127.0.0.1 --port 8088 --workers 4 --access-log --proxy-headers &>> /opt/seatable-thumbnail/logs/seatable-thumbnail.log &
/usr/local/bin/uvicorn main:app --host 127.0.0.1 --port 8088 --workers 4 --access-log --proxy-headers &>> /opt/seatable-thumbnail/logs/seatable-thumbnail.log &
sleep 0.2

/scripts/monitor.sh &>> /opt/seatable-thumbnail/logs/monitor.log &
Expand Down

0 comments on commit 88af5f3

Please sign in to comment.