A (good) way to run Prax on Arch Linux


File under: arch prax .

(Edit 2016-12-10) This is a slightly rewritten copy of a pull request that I made. I have since made a PKGBUILD that will install Prax for you. The result would be the same as if you performed the steps described below.

What is Prax?

Prax is like Pow. Prax functions as a process supervisor. It is meant for starting webserver processes whenever you make a request to a .dev-URLs. For example, a request to http://circles.dev/foobar would start the “circles” application. This application would then handle your request for /foobar and prax makes sure the response gets back to you.

Outline

To make this work we need to do a few things:

  1. make traffic to *.dev *.test go to localhost (with dnsmasq)
  2. forward traffic on port 80/443 to 22559/22558 (with iptables)
  3. start the prax daemon itself when you log in

Step 1. Forward *.dev to localhost

You can do this by putting the prax domain resolver in /etc/nsswitch.conf. This won’t work with any recent version of Chrome (or Chromium) though as it completely bypasses your name service configuration. (See prax issue #117 for more info.)

Luckily Dnsmasq provides a solution. Dnsmasq acts like a local caching DNS server. It can do a lot more though; you should check it out.

sudo pacman -S dnsmasq
# and make sure it is able to start

You don’t want to enable the dnsmasq service since it will be started by NetworkManager.

In case you don’t use Networkmanager:

  • you should probably enable the service
  • Read the Arch wiki page on dsnmasq for some tricks to make sure /etc/resolv.conf keeps pointing to 127.0.0.1 even though some daemons will try to overwrite it.

To configure Dnsmasq to forward *.dev you can make a new file /etc/NetworkManager/dnsmasq.d/prax and copy the following content in there:

local=/dev/
address=/dev/127.0.0.1
address=/dev/::1

You should restart NetworkManager to

sudo systemctl restart NetworkManager.service

Step 2. Set up iptables

Look at these files: prax-iptables (in the git-repo) and prax-iptables.service.

The first file is an slightly changed version of the init script you can find in the install/debian-directory. This version doesn’t use ifconfig to find the network devices. Copy this file to /usr/local/sbin/prax-iptables.

The second file is the systemd-service that is meant to run /usr/local/sbin/prax-iptables on startup. Copy this file to /etc/systemd/system/prax-iptables.service.

You should also enable and start the service with systemctl.

Step 3. Start Prax when you log in

Option 1: Let your desktop manager start Prax. Copy prax.desktop to ~/.config/autostart/. (You can find this file in the prax source code on GitHub.) Gnome will automatically run it when you log in. This is the way ysbaddaden runs it. I don’t know what it does when you log in twice (with mutliple X-servers). However this should probably not be a real problem I guess.

Option 2: Let the per-user systemd instance handle it. Copy prax.service to ~/.config/systemd/user/prax.service and change the lines that say ExecStart and ExecStop to reflect the correct path where you installed Prax. Note that this is a per-user process, and not per-session.

Note that you should also enable and start this service with systemctl --user.