devpi on Apache, with daemontools / supervise

I finally started putting my code into Python packages, and quickly found I needed a private repository. A little searching found devpi, a great caching proxy that’s also a private repository.

My problem was that the configuration presented used nginx and supervised. Nothing against nginx, but the prior install of apt-cacher used apache, so I did it in apache.

Unfortunately, I could not do it on one IP address, so I allocated a second IP address, like so, in /etc/network/interfaces:

auto eth0:0
iface eth0:0 inet static
  address 192.168.111.19
  netmask 255.255.0.0
  gateway 192.168.111.1
  broadcast 192.168.111.255
  dns-nameservers 192.168.111.2
  dns-search riceball.lo

That creates an alias address on an existing interface. I could have created another interface, as well – this is a VM.

Then I had to configure apache. The magic is in mod_proxy. You need to enable several modules:

a2enmod proxy proxy_http headers env 

And then make a virtual host. I put it in /etc/apache2/sites-enabled/devpi.conf:

<VirtualHost 192.168.111.19:80>
    ServerName gems.riceball.lo

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RequestHeader set X-outside-url "http://192.168.111.19"
    RequestHeader set X-Real-IP "192.168.111.19"
    ProxyPass / "http://localhost:4040/"
    ProxyPassReverse / "http://localhost:4040/"
    <Directory /var/www>
        Options +Includes
    </Directory>
</VirtualHost>

This isn’t as slick as the nginx config for devpi, but it works.

daemontools

Next up, I installed daemontools.

Though the devpi docs use supervised, a python process watcher, I just prefer DJB’s daemontools.

On Debian, the services are kept in /etc/service. You’ll need to follow the instructions in the program’s docs to get the service to boot. I used the /etc/rc.local method. I just added this line to the file:

/usr/bin/svscanboot &

Then you need to create the service:

cd /etc/service
mkdir devpi-server
mkdir log

Then you need run scripts to execute the service, and the logger for the service. First, /etc/service/devpi-server/run:

#! /bin/bash
exec devpi-server --port 4040 

Next, /etc/service/devpi-server/log/run:

#! /bin/bash
exec multilog t ./main

Then execute svscanboot. It should fire up the service. You can check like this:

cd /etc/service
svstat *

To bring a service up or down:

cd /etc/service
# this brings it up
svc -u devpi-server
# this takes it down
svc -d devpi-server

To read the logs you go into log/main and tail current. To make life easier, I symlink the log directories into /var/log.

cd /var/log
ln -s /etc/service/devpi-server/log/main/ devpi

That’s all there is to it.