**LEGACY** ‐ Installing FlareSolverr in FreeBSD or TrueNAS CORE jail
ilike2burnthing edited this page 2024-02-28 02:51:01 +00:00

These are legacy instructions, please use steps in README



These are instructions in order to get FlareSolverr configured and running at boot in a FreeBSD system or in a FreeBSD jail.

  • This tutorial was most recently used to install on a FreeBSD 13.2-RELEASE-p9 jail in TrueNAS.
  • All instructions consider that you will be using the root user to execute the commands and FlareSolverr will run with the flaresolverr user.

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

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 /tmp/ and clone the repository:

cd /tmp/
git clone https://github.com/FlareSolverr/FlareSolverr.git

3.2 Using Zip (Skip if you've already used GIT)

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:

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

4. Installing the necessary packages and load necessary kernel module

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

4.1 Load Kernel module

  • Load the kernel module required by the Linux compatibility package (linux64 is probably all that's required but in my scenario I needed both linux and linux64)
  • Make sure to perform these commands outside of the TrueNAS Jail as kldload cannot be called from within a jail. The jail has access to the same kernels that primary system has access to, thus this command must be run from a shell directly within your TrueNAS System.
#to load kernels module now
kldload -n -v linux
kldload -n -v linux64

#to load kernels module at boot
sysrc kld_list+="linux"
sysrc kld_list+="linux64"

4.2 Install package

Install these packages and all their required dependencies:

pkg install python39 py39-pip chromium xorg-vfbserver linux_base-c7

158 of packages aprox should be installed and will require near a 3GiB of storage.

5. Installing virtuaenv and requirement

To keep most of thing clean on the host after the build will be completed

5.1. virtual

pip install virtualenv

5.2. Create and activate virtual env

virtualenv /tmp/venv
source /tmp/venv/bin/activate.csh

5.3. Installing requirements

cd /tmp/FlareSolverr/
pip install pyinstaller
pip install -r requirements.txt
pip install -r test-requirements.txt

6. building the apps

cd ./src/
python3 build_package.py
cd ..

7. Doing some particular things to make it work!

7.1. Special folders

Those things are required because the program ask for access to particular folder.

mkdir /home/flaresolverr
chmod 777 /home/flaresolverr
mkdir /app
chmod 777 /app
mkdir /.undetected_chromedriver
chmod 755 /.undetected_chromedriver
mkdir /root/.undetected_chromedriver
chmod 755 /root/.undetected_chromedriver
cp /usr/local/bin/chromedriver /app/chromedriver
chmod 777 /app/chromedriver
cp /usr/local/bin/chromedriver /app/chromedriver.exe
chmod 777 /app/chromedriver.exe

7.2. Linux compatibility

Those things are required for Linux compatibility.

rm -rf ./dist/package/flaresolverr/_internal/chrome/*
cp /usr/local/bin/chrome ./dist/package/flaresolverr/_internal/chrome/chrome

#showing the ELF mark on the file
brandelf ./dist/package/flaresolverr/flaresolverr

#change the ELF mark on the file (if is not 'Linux')
brandelf -t Linux ./dist/package/flaresolverr/flaresolverr

#showing the result of the change
brandelf ./dist/package/flaresolverr/flaresolverr

# There may be a bug with the Linux compatibility package installed earlier.
# The libc.so.7 file did not exist so we create the file with a symlink from an existing file.
ln -s /compat/linux/usr/lib64/libc.so.6 /compat/linux/usr/lib64/libc.so.7

8. Create user

pw useradd flaresolverr -s /usr/sbin/nologin

9. Moving folder and changing owner and permission

mv ./dist/package/flaresolverr /usr/local/share/flaresolverr
chown -R flaresolverr:flaresolverr /usr/local/share/flaresolverr
chmod -R 770 /usr/local/share/flaresolverr

10. Create the rc.d config file to define the service

create the file

touch /usr/local/etc/rc.d/flaresolverr
chmod 755 /usr/local/etc/rc.d/flaresolverr

edit the file with your preferred text editor

#!/bin/sh
#
# PROVIDE: flaresolverr
# REQUIRE: networking
# KEYWORD: shutdown

# flaresolverr_enable="YES"

. /etc/rc.subr

name="flaresolverr"
rcvar="flaresolverr_enable"


flaresolverr_log_file="/var/log/flaresolverr/flaresolverr.log"

start_precmd=flaresolverr_prestart
stop_postcmd=flaresolverr_poststop

load_rc_config ${name}
# Defaults
# Usable parameter in rc.conf with those default parameter
: ${flaresolverr_enable:=NO}
: ${flaresolverr_daemon_user:=flaresolverr}
: ${flaresolverr_path:="/usr/local/share/flaresolverr"}
: ${flaresolverr_LOG_LEVEL:="info"}
: ${flaresolverr_LOG_HTML:="false"}
: ${flaresolverr_CAPTCHA_SOLVER:="false"}
: ${flaresolverr_TZ:="UTC"}
: ${flaresolverr_HEADLESS:="true"}
: ${flaresolverr_BROWSER_TIMEOUT:="40000"}
: ${flaresolverr_PORT:="8191"}
: ${flaresolverr_HOST:="0.0.0.0"}
: ${flaresolverr_TEST_URL:="https://www.google.com"}

pidfile_daemon="/var/run/flaresolverr/flaresolverr_daemon.pid"
pidfile_child="/var/run/flaresolverr/flaresolverr_child.pid"
procname="${flaresolverr_path}/flaresolverr"
command="/usr/sbin/daemon"

command_args="-f -p ${pidfile_child} -P ${pidfile_daemon} -o $flaresolverr_log_file -u ${flaresolverr_daemon_user} ${flaresolverr_path}/flaresolverr"

flaresolverr_prestart()
{

    install -d -o root -g $flaresolverr_daemon_user /var/run/flaresolverr
    install -d -o root -g $flaresolverr_daemon_user /var/log/flaresolverr

    export LOG_LEVEL=$flaresolverr_LOG_LEVEL
    export LOG_HTML=$flaresolverr_LOG_HTML
    export CAPTCHA_SOLVER=$flaresolverr_CAPTCHA_SOLVER
    export TZ=$flaresolverr_TZ
    export HEADLESS=$flaresolverr_HEADLESS
    export BROWSER_TIMEOUT=$flaresolverr_BROWSER_TIMEOUT
    export PORT=$flaresolverr_PORT
    export HOST=$flaresolverr_HOST
    export TEST_URL=$flaresolverr_TEST_URL

    
}

flaresolverr_poststop()
{
    sleep 2
    killall -u ${flaresolverr_daemon_user} -c Xvfb
}

run_rc_command "$1"

11. Clean up old residual files and folders

Before running these commands make sure to cancel out of the Python venv. rm -rf /tmp/venv rm -rf /tmp/FlareSolverr rm -rf /tmp/build rm -rf /tmp/master.zip

12. Enable service in rc.conf and start the daemon

Enable the Service

sysrc flaresolverr_enable="YES"

Now you should be able to start the daemon and enjoy!

Start the Service

service flaresolverr start

Check the Status

service flaresolverr status

Check the Logs

tail -f /var/log/flaresolverr/flaresolverr.log