Installing Fiche as a Service

I started playing with fiche as a way to keep a personal pastebin. I like it so much I set it up as a permanent service on my Ubuntu 16.04 box. It’s pretty simple to setup, but there were enough bumps that I wanted to make sure I wrote up a howto in case I want to do this again later.

Get fiche

Get fiche from the Github page

git clone https://github.com/solusipse/fiche

Build and install fiche

There are instructions on the web site but I had issues. Once I got the repo cloned and changed to it’s directory, the Github page says to build (make) and install (sudo make install).
make went off without a hitch

make

I, however kept getting an error trying to sudo make install:

[master √] :$ sudo make install
install -m 0755 fiche
install: missing destination file operand after 'fiche'
Try 'install --help' for more information.
Makefile:12: recipe for target 'install' failed
make: *** [install] Error 1

After looking at the Makefile, it seems like all sudo make install does is copy the executable to an unspecified location

After I tried specifying a location, I just gave up and copied the file myself to /usr/local/bin

sudo cp fiche /usr/local/bin/

That seemed to do the trick.

Configuring Apache

I want my fiche snippets to be accessible via the web. Fiche stores each snippet as an index.txt file inside a randomly generated directory name. So I needed to configure fiche to send files to a directory in /var/www/html/ and make Apache serve index.txt files along with the usual suspects (index.htm, index.html…etc)

I decided to make this a subdirectory of my RootDocument rather than a virtual directory, but you can handle it either way.

First of all I made a new directory for my snippets and set the ownership to apache (www-data on Ubuntu, apache on RHEL/CentOS):

sudo mkdir /var/www/html/fiche
sudo chown www-data:www-data /var/www/html/fiche

Then I modified the dir module to accept index.txt as a valid index file:

Ubuntu:

sudo vim /etc/apache2/mods-available/dir.conf

RHEL/CentOS:

sudo vim /etc/httpd/conf/httpd.conf

Add index.txt to the DirectoryIndex stanza, so the file looks something like this:

<IfModule mod_dir.c>    DirectoryIndex index.txt index.html index.cgi index.pl index.php index.xhtml index.htm</IfModule>

Then restart apache

sudo apachectl graceful

Test fiche

Now to make sure the above worked I started fiche from the command line with the following options:

Ubuntu:

fiche -s6 -d poe.planethawleywood.com/fiche -o /var/www/html/fiche/ -u www-data:www-data -D

RHEL/CentOS:

fiche -s6 -d poe.planethawleywood.com/fiche -o /var/www/html/fiche/ -u apache

The -s specifies the slug size (default 4)

The -d specifies the URL from which I want to serve fiche.

The -o specifies the location on the file system to store snippets

The -u specifies the user to run this process as. In this case it runs as the Apache user

The -D daemonizes the process so it runs in the background.

NOTE: add -S to the command line if you want to return an HTTPS URL

Then I sent a test snippet:

echo "This is a test" | nc poe.planethawleywood.com 9999

Fiche returned a URL which I plugged into my browser and was pleased to see

This is a test

On the screen. Success!

Create a systemd service

Now I want fiche to run all the time without me having to remember to start it after reboots. Since I’m running this on an Ubuntu 16.04 box, I need to create a systemd service.

Create the file /etc/systemd/system/fiche.service

sudo vim /etc/systemd/system/fiche.service

With these contents

[Unit]
Description=fiche-server

[Service]
ExecStart=/usr/local/bin/fiche -S -d poe.planethawleywood.com/fiche -o /var/www/html/fiche/ -u www-data

[Install]
WantedBy=multi-user.target

Save and quit.

Enable the new service:

sudo systemctl enable fiche

Then start the new service:

sudo systemctl start fiche

Test by sending another snippet

echo "This is a test" | nc poe.planethawleywood.com 9999

Visit the URL that gets returned and (hopefully) you’re in business!

Cleaning up

If you use fiche a lot you are going to eventually have dozens (or hundreds? thousands?) of randomly named directories on your web server. Common sense says to clean things up after a time. I chose a cron job that purges snips older than 14 days:

# Clean up fiche pastebin at 2am daily
00    02    *    *    *    find /var/www/html/pastebin -type d -mtime +14 -exec rm -rf {} \;

References