forked from SeleniumHQ/docker-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrome-cleanup.sh
More file actions
executable file
·36 lines (27 loc) · 1.34 KB
/
chrome-cleanup.sh
File metadata and controls
executable file
·36 lines (27 loc) · 1.34 KB
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
#!/bin/bash
# Return error exit code in case of any failure, so supervisord will restart the script
set -e
cleanup_stuck_chrome_processes() {
echo -n "Killing Chrome processes older than ${SE_BROWSER_LEFTOVERS_PROCESSES_SECS} seconds... "
ps -e -o pid,etimes,command | grep -v grep | grep chromium/chromium | awk '{if($2>'${SE_BROWSER_LEFTOVERS_PROCESSES_SECS}') print $0}' | awk '{print $1}' | xargs -r kill -9
echo "DONE."
}
cleanup_tmp_chrome_files() {
echo -n "Deleting all Chromium files in /tmp... "
find /tmp -name "*org.chromium.Chromium.*" -type d -mtime +${SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS} -exec rm -rf "{}" +
echo "DONE."
}
echo "Chrome cleanup script init with parameters: SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS=${SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS}, SE_BROWSER_LEFTOVERS_PROCESSES_SECS=${SE_BROWSER_LEFTOVERS_PROCESSES_SECS}, SE_BROWSER_LEFTOVERS_INTERVAL_SECS=${SE_BROWSER_LEFTOVERS_INTERVAL_SECS}."
# Start the main loop
while :; do
echo "Starting cleanup daemon script."
# Clean up stuck processes
cleanup_stuck_chrome_processes
# Wait a few seconds for the processes to stop before removing files
sleep 5
# Clean up temporary files
cleanup_tmp_chrome_files
# Go to sleep for 1 hour
echo "Cleanup daemon sleeping for ${SE_BROWSER_LEFTOVERS_INTERVAL_SECS} seconds."
sleep ${SE_BROWSER_LEFTOVERS_INTERVAL_SECS}
done