]>
Commit | Line | Data |
---|---|---|
ee96ae59 | 1 | #!/bin/sh |
c29d80f3 | 2 | |
cebbf362 | 3 | [ -x /usr/sbin/tmpwatch ] || exit 0 |
c29d80f3 | 4 | |
3bb55b26 | 5 | session_dirs="/var/run/php /var/run/php-ug" |
ee96ae59 | 6 | |
3bb55b26 ER |
7 | # use tmpwatch with --test to remove only files matching to 'sess_*' pattern |
8 | cleanup_dir() { | |
9 | local session_dir=$1 | |
a4756071 | 10 | |
2c1170af ER |
11 | test -d "$session_dir" || return |
12 | ||
37fa3e25 AM |
13 | /usr/sbin/tmpwatch $gc_time $session_dir --test | while read action type file; do |
14 | case "$action $type $file" in | |
15 | 'removing file '*/sess_*) | |
16 | rm "$file" | |
17 | ;; | |
18 | esac | |
19 | done | |
3bb55b26 ER |
20 | } |
21 | ||
22 | # find minimum gc time from any of the php engines | |
c2fd47f2 ER |
23 | find_gc_time() { |
24 | gc_time=0 | |
25 | local gc php | |
26 | for php in php php4 php52 php53 php54 php55 php56; do | |
27 | gc= | |
28 | if [ -x /usr/bin/$php ]; then | |
29 | gc=$($php -r 'echo max(round(ini_get("session.gc_maxlifetime")/3600), 1);' 2> /dev/null) | |
30 | elif [ -r /etc/$php/php.ini ]; then | |
31 | gc=$(awk -F"=" '/^session.gc_maxlifetime[ \t]*=/ { t=sprintf("%d", ($2/3600)); if (t<1) { t=1; }; print t; exit;}' /etc/$php/php.ini) | |
32 | fi | |
33 | [ -n "$gc" ] || continue | |
34 | ||
35 | if [ "$gc" -lt "$gc_time" ] || [ $gc_time -eq 0 ]; then | |
36 | gc_time=$gc | |
37 | fi | |
38 | done | |
39 | } | |
3bb55b26 | 40 | |
c2fd47f2 | 41 | find_gc_time |
3bb55b26 ER |
42 | [ $gc_time -gt 0 ] || exit 0 |
43 | ||
44 | for session_dir in $session_dirs; do | |
45 | cleanup_dir $session_dir | |
a4756071 | 46 | done |
2c1170af ER |
47 | |
48 | exit 0 |