Laravel Forge server with a huge /var/spool/mqueue-client folder size
Published 15 March 2021 08:15 (2-minute read)
When you have provisioned your server using Laravel Forge (or Ploi) and are running cronjobs on it, it could be that your /var/spool/mqueue-client folder contains a lot of files. In my case, the server had around 4GB of files in that folder.
Note: this doesn't mean it is by every server, but some had multiple cron-schedules. That's the reason why it could be that many files in the folder.
The /var/spool/mqueue directory contains temporary files associated with the messages in the mail queue and may contain the log file.
To see how big your folder is, you can run the following command:
du -sh /var/spool/mqueue-client
In my case, the folder was around 4GB:
[email protected]:/var/spool/mqueue-client# du -sh /var/spool/mqueue-client/ 4.3G /var/spool/mqueue-client/
You can use a command, like rm, to remove the files:
But when there are too many files in it, you could get an error like:
-bash: /bin/rm: Argument list too long
This folder can be huge. To clear it, you could use a script like:
cd /var/spool/mqueue-client echo "Starting..." echo "Checking the amount of files in the folder..." deleted=0 totalFiles=$(ls | wc -l) echo "Found $totalFiles, time to delete..." for i in `ls` do rm -f $i percentage=$(bc <<< "scale=2; ($deleted / $totalFiles) * 100") ((deleted++)) echo "Deleted $i. Files deleted $deleted / $totalFiles. $percentage% complete." done
It will log all deleted files; this could take a while:
... Deleted df12A8K182014661. Files deleted 491. 0% complete. Deleted df12A8K183014661. Files deleted 492. 0% complete. Deleted df12A8K184014661. Files deleted 493. 0% complete. Deleted df12A8K185014661. Files deleted 494. 0% complete. Deleted df12A8K186014661. Files deleted 495. 0% complete. Deleted df12A8K187014661. Files deleted 496. 0% complete. Deleted df12A8K188014661. Files deleted 497. 0% complete. Deleted df12A8K189014661. Files deleted 498. 0% complete. ...
You can disable the emails by setting the output of a cronjob to "/dev/null".
0 1 5 10 * /path/to/script.sh > /dev/null
It's also possible to add an extra variable to your crontab configuration: