Samir Parikh / Blog


Originally published on 21 February 2020

In my last post, I described how to install The Lounge IRC client on Ubuntu. In this post, thanks to a FreeBSD Forum post by user Trigex, I want to document how to install The Lounge on FreeBSD. I'm going to dispense with a lot of the background information and context that I provided in the previous post and just document the steps you need to take for reference. Trigex does a good job of explaining the steps in the forum post if you need additional detail.

Unless indicated otherwise, this post assumes that you are logged in as root.

Install node:

# pkg install yarn node

Create the user lounger and required directories:

# pw adduser lounger -d /nonexistent -s /usr/sbin/nologin -c "The Lounge User"
# mkdir /usr/local/etc/thelounge
# chown lounger /usr/local/etc/thelounge

Install The Lounge, run it under the newly created user, and create a new The Lounge user:

# yarn global add thelounge
# su -m lounger
$ setenv THELOUNGE_HOME /usr/local/etc/thelounge
$ /usr/local/bin/thelounge start

Press <Ctrl>-C after the text finishes printing.

$ /usr/local/bin/thelounge add newusername
$ exit

Create an rc script which you can control via a service:

# mkdir -p /usr/local/etc/rc.d && vi /usr/local/etc/rc.d/thelounge

Put the following in the script:

#!/bin/sh

. /etc/rc.subr

name="thelounge"
rcvar=thelounge_enable

load_rc_config ${name}

command=/usr/local/bin/thelounge

start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"

: ${thelounge_enable="NO"}
: ${thelounge_user="lounger"}
: ${thelounge_home="/usr/local/etc/thelounge"}

thelounge_start(){
        cmd="${command} start"
        if thelounge_running; then
                echo "The Lounge is already running!"
        else
                su -m ${thelounge_user} -c "setenv THELOUNGE_HOME ${thelounge_home}; ${cmd} &" > /dev/null 2>&1
        fi
}

thelounge_stop(){
        # pretty bad way to do this, but it'll work lol
        if thelounge_running; then
                pgrep -u ${thelounge_user} | xargs -I _ kill -s SIGINT _
        else
                echo "The Lounge isn't currently running!"
        fi
}

thelounge_status(){
        if thelounge_running; then
                echo "The Lounge is up and running!"
        else
                echo "The Lounge isn't currently running! Aww!"
        fi
}

thelounge_running(){
        pids=$(pgrep -u ${thelounge_user})
        [ ! -z "$pids" ] && return 0 || return 1
}

run_rc_command "$1"

Make the script executable, enable the The Lounge service and start The Lounge:

# chmod +x /usr/local/etc/rc.d/thelounge
# sysrc thelounge_enable="YES"
# service thelounge start

Make sure port 9000 is open on your firewall (if applicable) and visit http://irc.example.com:9000 to confirm that you can access the site.

To enable the reverse proxy and HTTPS, first install and configure NGINX:

# sudo pkg install nginx
# sudo mv /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.bak

Create a new NGINX configuration file called /usr/local/etc/nginx/nginx.conf with the following:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        server_name irc.example.com;
        listen 80;
        client_max_body_size 10m;

        location / {
            proxy_pass http://irc.example.com:9000/;
            proxy_http_version 1.1;
            proxy_set_header Connection "upgrade";
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

Enable and start NGINX:

# sysrc nginx_enable="YES"
# service nginx start

Enable HTTPS via Let's Encrypt and Certbot:

# pkg install py37-certbot-nginx
# certbot --nginx -d irc.example.com

Update The Lounge configuration file located at /usr/local/etc/thelounge/config.js

reverseProxy: true;

https: {
        enable: true,
        key: "/etc/letsencrypt/live/irc.example.com/privkey.pem",
        certificate: "/etc/letsencrypt/live/irc.example.com/fullchain.pem",
        ca: "",
},

Restart NGINX:

# service nginx restart

You should now be able to visit The Lounge at https://irc.example.com.