Question

Cleaning /var/lib/php/sessions - 100% inodes usage - Ubuntu 16.04

Posted March 23, 2021 461 views
PHPUbuntu 16.04

After having issues doing anything on one of my Ubuntu 16.04 droplets due to disc usage errors, I found that I was running out of inodes and there are about 6.2m of them in /var/lib/php/sessions.

I recently updated from PHP 5 to PHP 7, I think this has caused the issue.

My questions are:

What’s the best way to clean sessions from this folder to free up inodes?

How can I prevent this from happening again?

I have this

09,39 *     * * *     root   [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi

in etc/cron.d/php but it doesn’t appear to be working.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

I believe that this is a good approach.

What happens if you try to run the script manually:

/usr/lib/php/sessionclean

Do you get any errors?

Regards,
Bobby

  • Thanks for that.

    Running sudo /usr/lib/php/sessionclean seems to be working. It’s been 10 minutes now and no error has come up, but the command has not completed. However disk IO is 20MB/s so I think it’s working.

    What’s the best way to troubleshoot the cron job not executing this command?

    • Hi there @umpire,

      This is a good news!

      Regarding the cron job, what I could suggest is checking your cron log with:

      sudo grep CRON /var/log/syslog
      

      Let me know how it goes!

      Regards,
      Bobby

      • syslog was empty, looking in syslog.1 returned:

        May 15 06:40:58 box cron[1449]: (CRON) INFO (pidfile fd = 3)
        May 15 06:40:58 box cron[1449]: (CRON) INFO (Running @reboot jobs)
        May 15 07:09:01 box CRON[14624]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean)
        May 15 07:17:01 box CRON[14911]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
        May 15 07:39:01 box CRON[15612]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean)
        

        All entries in the file are dated May 15 - would it be logging anywhere else? I can’t see any more syslog files in /var/log. I believe my system time is setup correctly.

        • Hi there,

          This is quite interesting, I could suggest checking the status of your cron service and make sure that it is running:

          sudo systemctl status cron
          

          If it is not running you can start it with:

          sudo systemctl start cron
          

          Let me know if this helps!
          Regards,
          Bobby

          • Hi Bobby,

            It says that Cron is running with 1 task (plus some other information). No visible errors.

            syslog is still empty and syslog.1 still has nothing since May 15. However the inodes aren’t filling up which is good I suppose.

            Could cron be logging somewhere else perhaps?

            Thanks

        • Hi there,

          I think that you should be able to check the log with the following command instead:

          sudo journalctl -u cron.service
          

          You could search by pressing / and then typing the word that you are looking for.

          Let me know how it goes!
          Regards,
          Bobby