0

I keep running out of inodes (Ubuntu 14.04).

In my root mail I get the following message:

From root@web.site.com  Sun May 29 04:09:01 2016
Return-Path: <root@web.site.com>
X-Original-To: root
Delivered-To: root@web.site.com
Received: by web.site.com (Postfix, from userid 0)
    id 7D8B41A230A; Sun, 29 May 2016 04:09:01 -0400 (EDT)
From: root@web.site.com (Cron Daemon)
To: root@web.site.com
Subject: Cron <root@web>   [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20160529080901.7D8B41A230A@web.site.com>
Date: Sun, 29 May 2016 04:09:01 -0400 (EDT)

/usr/lib/php5/sessionclean: 12: /usr/lib/php5/sessionclean: php5: not found

I believe that the last part refers to line 12 of the sessionclean file? Here is that:

session_config=$(php5 -c /etc/php5/${conf_dir}/php.ini -d "error_reporting='~E_ALL'" -r 'foreach(ini_get_all("session") as $k => $v) echo "$k=".$v["local_value"]."\n";')

My php.ini file is stored within .../php5/cli/php.ini. I even edited the sessionclean file to expressly refer to the php.ini file, and while the error when running the sessionclean command then stops, my sessions are still not cleaned out.

I am also running HHVM and have made some changes to my HHVM config (/etc/hhvm/php.ini) as follows:

session.save_handler = files
session.save_path = /var/lib/php5/sessions
session.gc_probability = 0
session.gc_maxlifetime = 1440

I have also tried editing the save path to /var/lib/hhvm/sessions and running the sessionclean command again and that does not work.

At the moment the only way for me to clean sessions is manually, using the following command:

cd /var/lib/php5 OR .../hhvm
find . -name "sess_*" -print | xargs rm -v

Does anyone have any ideas?

  • This is not an NGINX question and does not need that tag. – Thomas Ward May 31 '16 at 11:14
  • PATH issue? Can you set a full path to php5 bin and try to run it again? – user508889 May 31 '16 at 11:34
  • @bc2946088 thanks I have tried that and no longer get any errors when I run it manually, however monitoring the number of files in each of the two possible sessions directories /var/lib/php5 OR /var/lib/hhvm, I get the same result before and after running: root@web:/usr/bin# for i in /var/lib/hhvm*; do echo $i; find $i |wc -l; done /var/lib/hhvm 60929 root@web:/usr/bin# for i in /var/lib/php5*; do echo $i; find $i |wc -l; done /var/lib/php5 22641 – Matt May 31 '16 at 11:58
  • Check your memory as you run the script. There was a bug in php5 sessionclean, i'll see if I can find it. That being said, I think it's running but then running out resources and crashes. – user508889 May 31 '16 at 12:07
  • @bc2946088 Thank you I don't think it is memory issues, I have 32GB - 31997 12150 used 19847 free. I monitored when I when ran it. Is there any way to log what happens when I run the script? As you've probably guessed I am no expert I mainly diagnose any problems via Google searches and forums! – Matt May 31 '16 at 12:18
0

I solved this by changing the sessions directory to /var/lib/php/sessions in /etc/hhvm/php.ini. And then also hardcoding the variables in the sessionclean script /usr/lib/php5/sessionclean

#!/bin/sh -e

SAPIS="apache2:apache2\napache2filter:apache2\ncgi:php5\nfpm:php5-fpm\n"

# Iterate through all web SAPIs
(
proc_names=""
printf "$SAPIS" | \
while IFS=: read -r conf_dir proc_name; do
    if [ -e /etc/php5/cli/php.ini ]; then
        # Get all session variables once so we don't need to start PHP to get each config option
        session_config=$(/usr/bin/php -c /etc/php5/cli/php.ini -d "error_reporting='~E_ALL'" -r 'foreach(ini_get_all("session") as $k => $v) echo "$k=".$v["local_value"]."\n";')
        save_handler=files
        save_path=/var/lib/php/sessions
        gc_maxlifetime=1440
        if [ "$save_handler" = "files" -a -d "$save_path" ]; then
            proc_names="$proc_names $proc_name";
            printf "%s:%s\n" "$save_path" "$gc_maxlifetime"
        fi
    fi
done
# first find all open session files and touch them (hope it's not massive amount of files)
for pid in $(pidof $proc_names); do
    find "/proc/$pid/fd" -ignore_readdir_race -lname "$save_path/sess_\*" -exec touch -c {} \;
done
) | sort -rn -t: -k2,2 | sort -u -t: -k 1,1 | while IFS=: read -r save_path gc_maxlifetime; do
    # find all files older then maxlifetime and delete them
    find -O3 "$save_path" -depth -mindepth 1 -name 'sess_*' -ignore_readdir_race -type f -cmin "+$gc_maxlifetime" -delete
done

exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.