Skip to content

Instantly share code, notes, and snippets.

@Zamana
Last active March 20, 2023 12:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Zamana/68060da614909ed3531acbda6154f67d to your computer and use it in GitHub Desktop.
Save Zamana/68060da614909ed3531acbda6154f67d to your computer and use it in GitHub Desktop.

Installing FlareSolverr on FreeBSD or FreeNAS/TrueNAS jail

FlareSolverr is a proxy server to bypass Cloudflare protection.

I found it while looking for a way to fix a problem: my Jackett installation one day started to give errors when trying to access 1337x. You got the point...

Here are the instructions in order to get FlareSolverr configured and running at boot in a FreeBSD system or in a FreeNAS/TrueNAS jail (which is my case, by the way).

This works only for version 2.1.0. For version 2.2.0, I was unable to make it work. I'm sorry.

This was made in a TrueNAS Core 12.0-U7 which uses 12.2-RELEASE-p11 as base.

All instructions consider that you will be using the root user to execute the commands and to run FlareSolver. If you want or need to use a regular user, adapt the instructions accordingly.

I'll not enter in details about creation of jails, but here is the main screen of my jail creation form for your reference:

image

So, after creating a simple jail (clone jail, vnet interface), follow these instructions:

1. Check if you need to set your date/time

In my case it is necessary:

rm /etc/localtime
ln -s /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime

2. Update and upgrade your packages

Before anything else, make sure that your packages are updated and upgraded:

pkg update
pkg upgrade

3. Get FlareSolverr

Here you have the option to use Git or download the sources directly. It doesn't matter what you choose, the final product will be the same.

The advantage of the Git way is that it is easier to keep FlareSolverr updated.

So, follow 3.1 or 3.2, as you wish.

3.1 Using Git

Install the git-tiny package:

pkg install git-tiny

Then go to /usr/local/share folder and clone the repository:

cd /usr/local/share
git clone https://github.com/FlareSolverr/FlareSolverr.git

3.2 Using Zip

Go to the FlareSolverr Github page, click on Code, then right-click on "Download ZIP" and then choose "Copy link address":

image

Then execute the fetch command to download the zip file, by pasting the copied address in the command line, and then run the unzip command to extract it:

fetch https://github.com/FlareSolverr/FlareSolverr/archive/refs/heads/master.zip
unzip master.zip

Now move the FlareSolverr-master folder to /usr/local/share changing the folder's name to just FlareSolverr:

mv FlareSolverr-master /usr/local/share/FlareSolverr

4. Installing the necessary packages

Once you have the FlareSolverr source code downloaded through Git or Zip in /usr/local/share/FlareSolverr, the next step is to download the necessary packages.

Install these packages and all their required dependencies:

pkg install npm-node14 chromium

Around 170 packages should be installed.

5. Installing FlareSolverr

Notes:

  1. From now on, everything should be executed inside the FlareSolverr installation folder, that is /usr/local/share/FlareSolverr

  2. The command execution order is important!

  3. setenv is a CShell command; adapt if you're using another shell

  4. I confess that I don't understand yet why the double installation of puppeteer is necessary; I guess that this is a bug or something. I'll update this guide when I find the reason (I hope...)

Execute the following commands to install FlareSolverr:

cd /usr/local/share/FlareSolverr
setenv PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
setenv PUPPETEER_EXECUTABLE_PATH /usr/local/bin/chrome
npm install
node node_modules/puppeteer/install.js
npm install puppeteer@1.2.0
npm install puppeteer
npm run build

6. Testing

In order to test if FlareSolverr is configured and can run, execute:

cd /usr/local/share/FlareSolverr
npm start

If everything is fine, you should see something like this:

root@flaresolverr:/usr/local/share/FlareSolverr # npm start

> flaresolverr@2.1.0 start /usr/local/share/FlareSolverr
> node ./dist/server.js

2022-01-01T20:32:20-03:00 INFO FlareSolverr v2.1.0
2022-01-01T20:32:20-03:00 INFO Testing web browser installation...
2022-01-01T20:32:21-03:00 INFO FlareSolverr User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/94.0.4606.81 Safari/537.36
2022-01-01T20:32:21-03:00 INFO Test successful
2022-01-01T20:32:21-03:00 INFO Listening on http://flaresolverr:8191

This means that FlareSolverr is running and listening on port 8191 in the localhost interface (which is useless in some cases, but we will fix this in no time).

Congratulations!

If not... get back and check the steps above.

7. Run at system boot/jail start

In order to have FlareSolverr running at system boot or jail start, create a file named /usr/local/etc/rc.d/flaresolverr with the following content:

#!/bin/sh

#
# Author: C. R. Zamana (czamana at gmail dot com)
#
# PROVIDE: flaresolverr
# REQUIRE: networking
# KEYWORD:

. /etc/rc.subr

name="flaresolverr"
rcvar="${name}_enable"
load_rc_config ${name}

: ${flaresolverr_enable:="NO"}

pidfile="/var/run/flaresolverr.pid"

start_precmd="flaresolverr_precmd"

PATH=$PATH:/usr/local/bin

flaresolverr_precmd() {
        cd /usr/local/share/FlareSolverr
        export PUPPETEER_EXECUTABLE_PATH=/usr/local/bin/chrome
        export HOST=0.0.0.0
}

command="/usr/sbin/daemon"
command_args="-P ${pidfile} /usr/local/bin/npm start > /dev/null"

run_rc_command "$1"

Give it the execute permissions:

chmod +x /usr/local/etc/rc.d/flaresolverr

And make it run at sytem boot/jail start:

sysrc flaresolverr_enable=YES

And now you are ready to control the service with:

service flaresolverr start | stop | status

Note that the script sets the variable HOST as 0.0.0.0 which will make FlareSolverr to listen in all interfaces, which is what you want if you are using it in a system and acessing it from another. Feel free to change this according with your needs.

Beyond service flaresolverr status, another way to check that the process is really running and listening at the port 8191, is:

netstat -an | grep 8191

8. FlareSolverr and Jackett: a use case

Now that you have FlareSolverr alive and kicking, you can use it in your Jackett installation, like this:

image

Happy FlareSolverring ;-)

@zajc3w
Copy link

zajc3w commented Mar 20, 2023

Hi!

Thanks for commenting.

I confess that I did give up on running FlareSolverr on FreeBSD days after writing this article.

Now I have a small Alpine Linux VM inside TrueNAS where FlareSolverr is running through a docker. It's much better and avoids all the hassle...

I'm sorry, but I don't know how to solve this issue.

Regards.

TBH with TruenasScale reaching stability there is no need.
just switch from freenas/truenas core to Scale and use truecharts for all your apps,.
Flaresolverr installs in under a minute, once you get hang of truecharts, and that took me an one evening.
well worth it/ it does require ssd's for apps(some mwill take ages to deploy without them) but still runs on ancient hardware(i3-4170 in my case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment