-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathedge-cleanup.sh
executable file
·36 lines (27 loc) · 1.32 KB
/
edge-cleanup.sh
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_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