-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cleanup script for hanging Chrome processes and temp files (#2173)
- Loading branch information
1 parent
6f03eb1
commit 3909301
Showing
11 changed files
with
220 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
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
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,21 @@ | ||
; Documentation of this file format -> http://supervisord.org/configuration.html | ||
|
||
; Priority 0 - xvfb & fluxbox, 5 - x11vnc, 10 - noVNC, 15 - selenium-node | ||
|
||
[program:browserleftoverscleanup] | ||
priority=0 | ||
command=bash -c "if [ ${SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP} = "true" ]; then /opt/bin/chrome-cleanup.sh; fi" | ||
autostart=true | ||
exitcodes=0 | ||
autorestart=unexpected | ||
|
||
;Logs | ||
redirect_stderr=false | ||
stdout_logfile=/var/log/supervisor/browser-leftover-cleanup-stdout.log | ||
stderr_logfile=/var/log/supervisor/browser-leftover-cleanup-stderr.log | ||
stdout_logfile_maxbytes=50MB | ||
stderr_logfile_maxbytes=50MB | ||
stdout_logfile_backups=5 | ||
stderr_logfile_backups=5 | ||
stdout_capture_maxbytes=50MB | ||
stderr_capture_maxbytes=50MB |
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,37 @@ | ||
#!/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 chrome/chrome | 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 Chrome files in /tmp... " | ||
find /tmp -name ".com.google.Chrome.*" -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 |
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
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,21 @@ | ||
; Documentation of this file format -> http://supervisord.org/configuration.html | ||
|
||
; Priority 0 - xvfb & fluxbox, 5 - x11vnc, 10 - noVNC, 15 - selenium-node | ||
|
||
[program:browserleftoverscleanup] | ||
priority=0 | ||
command=bash -c "if [ ${SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP} = "true" ]; then /opt/bin/edge-cleanup.sh; fi" | ||
autostart=true | ||
exitcodes=0 | ||
autorestart=unexpected | ||
|
||
;Logs | ||
redirect_stderr=false | ||
stdout_logfile=/var/log/supervisor/browser-leftover-cleanup-stdout.log | ||
stderr_logfile=/var/log/supervisor/browser-leftover-cleanup-stderr.log | ||
stdout_logfile_maxbytes=50MB | ||
stderr_logfile_maxbytes=50MB | ||
stdout_logfile_backups=5 | ||
stderr_logfile_backups=5 | ||
stdout_capture_maxbytes=50MB | ||
stderr_capture_maxbytes=50MB |
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,37 @@ | ||
#!/bin/bash | ||
|
||
# Return error exit code in case of any failure, so supervisord will restart the script | ||
set -e | ||
|
||
cleanup_stuck_edge_processes() { | ||
echo -n "Killing Edge processes older than ${SE_BROWSER_LEFTOVERS_PROCESSES_SECS} seconds... " | ||
ps -e -o pid,etimes,command | grep -v grep | grep msedge/msedge | awk '{if($2>'${SE_BROWSER_LEFTOVERS_PROCESSES_SECS}') print $0}' | awk '{print $1}' | xargs -r kill -9 | ||
echo "DONE." | ||
} | ||
|
||
cleanup_tmp_edge_files() { | ||
echo -n "Deleting all Edge files in /tmp... " | ||
find /tmp -name ".com.microsoft.Edge.*" -type d -mtime +${SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS} -exec rm -rf "{}" + | ||
echo "DONE." | ||
} | ||
|
||
echo "Edge 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_edge_processes | ||
|
||
# Wait a few seconds for the processes to stop before removing files | ||
sleep 5 | ||
|
||
# Clean up temporary files | ||
cleanup_tmp_edge_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 |
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
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,21 @@ | ||
; Documentation of this file format -> http://supervisord.org/configuration.html | ||
|
||
; Priority 0 - xvfb & fluxbox, 5 - x11vnc, 10 - noVNC, 15 - selenium-node | ||
|
||
[program:browserleftoverscleanup] | ||
priority=0 | ||
command=bash -c "if [ ${SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP} = "true" ]; then /opt/bin/firefox-cleanup.sh; fi" | ||
autostart=true | ||
exitcodes=0 | ||
autorestart=unexpected | ||
|
||
;Logs | ||
redirect_stderr=false | ||
stdout_logfile=/var/log/supervisor/browser-leftover-cleanup-stdout.log | ||
stderr_logfile=/var/log/supervisor/browser-leftover-cleanup-stderr.log | ||
stdout_logfile_maxbytes=50MB | ||
stderr_logfile_maxbytes=50MB | ||
stdout_logfile_backups=5 | ||
stderr_logfile_backups=5 | ||
stdout_capture_maxbytes=50MB | ||
stderr_capture_maxbytes=50MB |
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,25 @@ | ||
#!/bin/bash | ||
|
||
# Return error exit code in case of any failure, so supervisord will restart the script | ||
set -e | ||
|
||
cleanup_stuck_firefox_processes() { | ||
echo -n "Killing Firefox processes older than ${SE_BROWSER_LEFTOVERS_PROCESSES_SECS} seconds... " | ||
ps -e -o pid,etimes,command | grep -v grep | grep firefox-bin | awk '{if($2>'${SE_BROWSER_LEFTOVERS_PROCESSES_SECS}') print $0}' | awk '{print $1}' | xargs -r kill -9 | ||
echo "DONE." | ||
} | ||
|
||
echo "Firefox cleanup script init with parameters: 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_firefox_processes | ||
|
||
# Go to sleep for 1 hour | ||
echo "Cleanup daemon sleeping for ${SE_BROWSER_LEFTOVERS_INTERVAL_SECS} seconds." | ||
sleep ${SE_BROWSER_LEFTOVERS_INTERVAL_SECS} | ||
done |
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