Invoice Ninja & SnapPDF: Process has been signaled with signal …

Invoice Ninja is a great self-hosted invoicing software written in PHP utilizing the Laravel Web Application Framework and uses SnapPDF for its invoice generation. I use a moderately modified version of the software to tackle my invoicing needs. Overall, it works well mostly.

I recently had to reinstall one of my production servers due to a networking glitch that was causing duplicated ICMP messages to be received by clients. In doing so, I migrated away from Arch to Debian.

I originally thought this was a mistake but turns out it wasn’t, apart from not having the freshest packages available.

At the time of writing, I believe Invoice Ninja uses their own PDF generating stack that basically just sends data to their “PDF printer” server which then converts to a PDF and spits it back to you. I opted to choose SnapPDF because I want to run my stuff on my own server. The less dependencies on cloud-based stuff the better.

The Problem

When using SnapPDF going to generate PDFs, one can encounter “Server Error – 500”. This is usually caused by SnapPDF unable to initialize Chromium to do the PDF generation.

Invoice Ninja cloaks this error as a Permissions Error, but SnapPDF actually returns a error with the actual error and the signal it received.

This is a snippet from the modified module that has a ton of added debugging. Please excuse the mild profanity:

[2024-10-17 05:31:53] production.INFO: Apparently I need to make a PDF now.
[2024-10-17 05:31:53] production.INFO: Okay, looks good. Off to the printer...
[2024-10-17 05:31:53] production.ERROR: Creating Raw PDF failed. Here comes the exception, because Invoice Ninja just treats this as a fucking permissions error when may not be.
[2024-10-17 05:31:53] production.ERROR: The process has been signaled with signal "5". {"userId":1,"exception":"[object] (Exception(code: 0): The process has been signaled with signal \"5\". at /var/www/accounts. (...snip...)

Signal 5 is SIGTRAP. Sometimes you can get Signal 6 which is SIGABRT.

This post on the forums (also here’s a Archive.is link for your convenience) kind of pointed me in the right direction but unfortunately did not solve the issue.

So… how can we fix it?

The Solution

The solution lies in the configuration of how your server is configured. Normally, on standard Linux distro like Debian and Arch your web server will run under the www-data or http system user account. Chromium will start up under this user account, do its business and then quit.

If you look at the home directory for that account, it might be /var/www or /srv/http. Taking a look at the permissions for that directory and we’ll see an issue.

[coburn@kako ~]$ ls -al /srv/http
total 8
drwxr-xr-x 2 root root 4096 Apr 8 2024 .
drwxr-xr-x 5 root root 4096 Sep 16 19:59 ..

Note that the above is from an Arch Linux installation. The issue here is that the folder is owned by root – the super user – and therefore unwritable by the www-data/http user.

The easiest option is to do a chown (change owner) on the parent directory, then make two folders and chown those as well. Note that this may be lead to security issues, but as far as I can see you should be fine. It’s another “trust me bro” moment unfortunately.

Run the following as root (or sudo), adapting the paths where required:

chown root:http /srv/http
mkdir /srv/http/.config
mkdir /srv/http/.local
chown http:http /srv/http/.config
chown http:http /srv/http/.local

If using a Debian based system, run the following instead:

chown root:www-data /srv/http
mkdir /var/www/.config
mkdir /var/www/.local
chown www-data:www-data /var/www/.config
chown www-data:www-data /var/www/.local

This should be enough to get things working. Go back to Invoice Ninja and attempt to generate a PDF. If all goes according to plan™ then the 500 Error should go away.

There’s some other solutions but they are somewhat more involved and should only be explored if required.

Why does this happen?

Apple iOS Weary FaceApparently Chromium takes a massive shit if it can’t create a Crash Report directory for one reason or another.

Seriously, this fucking browser has the dominant market share and it’ll crash if it can’t make a Crash Report directory. What the hell, Google?

Anyway, I hope this guide was useful for you. If you still have issues with permissions, let me know in the comments and I’ll do my best to assist.

Now, if you excuse me… I have a ton of invoices to generate.

Leave a Reply

Your email address will not be published. Required fields are marked *