caharkness.com

Home · Contact · Git


Fine-tune xrdp

Set the kernel option net.core.wmem_max to 8388608 via issuing sysctl -w net.core.wmem_max=8388608. You can have this change persist across reboots by writing:

net.core.wmem_max = 8388608

...to /etc/sysctl.d/xrdp.conf.

Configure xrdp.ini

Ensure the following:

tcp_send_buffer_bytes=4194304
max_bpp=16

This was all that was needed to get my unbearably slow experience to something usable for connections over a private VPN. No tweaks to the compositor needed.

Source


Multi-session User in xrdp

Insert the following line

export $(dbus-launch)

...before the test -x and exec lines in /etc/xrdp/startwm.sh to allow signing into your user account more than once. This is especially useful for users coming from Windows environments where you can be signed in locally (at home) and connect to your same user account from afar via RDP.

Source


Links

  • Gitea — Self-hosted source code
  • GitHub — Source code hosted on GitHub
  • LinkedIn — My work history

Microblogging Engine

This site is running on a microblogging engine I wrote. If you have a LAMP stack of your own, you can combine these two projects to experiment with it:

Project Mission

  1. Maintain compatibility with old & text-based browsers

    • No JavaScript required
    • Posts and pages are readable as text alone
  2. Offer a balance of simplicity and customization

    • Posts and pages are ambiguous — every page is a feed of posts ordered by date descending
    • Global markdown for header and footer
    • Global CSS to style some or all pages via body[data-page='...'] selector

Why PHP?

Here are reasons why I elect PHP as my favorite language for back-end and server-side software:

  • It's free and open source

  • The source code you write is the output document

    • The controlling logic is where you define it to be. The php binary behaves much like the Linux cat (concatenate) command, but with the addition of the language's logic & execution interpreted between <?php and ?> tags read from the input. The output isn't required to be text/html, it can be anything UTF-8.
  • It's old — it has been out long enough to be supported & well understood

  • Apache is suggested but not required

    • PHP has a built-in web server. While one running instance not recommended for production and high volume traffic, it's perfect for microservice architecture and desktop applications.
  • It's trusted and vetted

    • Installing PHP (and its plugins) from the official Debian repository is safe. You are never blindly installing a large list of dependencies like you would be in the world of Node.js or Python.

Is Node.js Useless?

  • Short answer:

    • Mostly.
  • Long answer:

    • I would never recommend Node.js because writing JavaScript is a sloppy language. However, as a full-stack software engineer and system administrator, I recommend installing the Node.js runtime for one utility: PM2.

Why PM2?

PM2 makes daemonizing processes very easy. Most virtual machines I spin up are single-user Debian environments. I would rather use PM2 to host my server software spawned in by a shell script rather than doing this the systemd way. You can think of PM2 as giving you the "daemonize this" command.

For example:

pm2 start my-script.sh

Whatever my-script.sh is doing, PM2 will ensure that it continues to run in the background. Should you want my-script.sh to run automatically at startup, easy. Just run the commands below:

pm2 startup
pm2 save

When run as root, this will tell PM2 to start its list of processes when the system boots with no extra fuss. Want to see what's currently running under PM2? Run:

pm2 list

Seriously. The task of managing daemonized processes has never been easier. Here's how you prepare your Debian system to have Node.js and PM2:

apt install nodejs
apt install npm
npm install -g n
n latest
npm install -g pm2

This installs Node.js, the Node package manager, and the "n" utility for making sure that you are using the latest version of Node.js.

Now what?

Now that you have PM2, it's time to start hosting your microservices written in Python and PHP. I use shell scripting to spawn the processes like so:


PHP:

#!/bin/bash

# https://stackoverflow.com/a/1482133
SCRIPT_DIR="$(dirname -- "$(readlink -f -- "$0";)";)"
cd "${SCRIPT_DIR}"

# Allow port setting via first argument:
PORT=8000
if [[ ! "$1" == "" ]]
then
    PORT="$1"
fi

# Handle multiple simultaneous requests in Linux only:
export PHP_CLI_SERVER_WORKERS=4

php -S 0.0.0.0:$PORT index.php --enable-mbstring

Python:

#!/bin/bash

INSTALLATION=0

if [[ ! -d venv ]]
then
    python3 -m venv venv || python -m venv venv || (
        echo "Could not create a Python virtual environment."
        exit 1
    )

    INSTALLATION=1
fi

if [[ -f ./venv/bin/activate ]]; then source ./venv/bin/activate; fi
if [[ -f ./venv/Scripts/activate ]]; then source ./venv/Scripts/activate; fi


if [[ $INSTALLATION -eq 1 ]]
then
    pip install discord.py
    pip install pillow
fi

python -u bot.py