back 2017-05-17 DockerLinuxPsiTransfer
  1. PsiTransfer::Installation
    1. Configuration
      1. Config file: NODE_ENV related
      2. Environment variables
    2. Layout customization
    3. Deployment
      1. Docker
      2. Manual
      3. Linux Systemd service

PsiTransfer::Installation

PsiTransfer is a simple open source self-hosted file sharing solution. In this post I’ll go through different methods how to deploy and run the application.

Configuration

First of all, I’ll give an overview about the configuration options. See the config.js for possible values. I do not recommend changing this file directly, better use one of the following options.

PsiTransfer searches for an config file with the name config.<NODE_ENV>.js in the root folder where <NODE_ENV> stands for the value of the environment parameter NODE_ENV. If you start PsiTransfer using npm start it’s production so you can create a config.production.js with your settings. For example take a look at config.dev.js. This file is used when starting the application with npm run dev.

You are completely free to introduce own configs like config.custom.js and start the app with NODE_ENV=custom node app.js.

Environment variables

Some Linux distributions have /etc/default/<daemon> or /etc/sysconfig/<daemon> files with environment configurations. Moreover, it’s common to configure the behaviour of Docker containers using environment parameters.

PsiTransfer supports overwriting every config value by environment parameters prefixed with PSITRANSFER_.

export NODE_ENV=dev
export PSITRANSFER_RETENTIONS='{"one-time":"one time","3600":"1 Hour"}'
export PSITRANSFER_PORT=8080
node app.js
  • The above example sets the NODE_ENV to dev.
    If config.dev.js exists, it is loaded and overwrites the corresponding values from config.js.
  • Then it will overwrite retentions and port with the values of the environment parameters.

Environment parameters always have the highest priority.

Layout customization

It is easy to customize the look of PsiTransfer. Almost all functional components are encapsulated in the upload- and download-app and they only need a root element where they can be mounted. This elements must have the attribute id="upload" and id="download", respectively.

PsiTransfer uses Bootstrap 3 as CSS-Framework and custom styles can be found in public/assets/styles.css.

If you want to give PsiTransfer your own custom look and feel just edit the files in public/html and/or the styles.css. If you need to deliver assets like a custom logo put it into the assets folder.

But consider: You have to adopt further changes on PsiTransfer updates. This sould not happen very often.

Deployment

Running PsiTransfer is easy since it’s just a Node.js application and Node runs on many platforms.

Docker

Using Docker is the most easy and recommended way to run PsiTransfer. There is an official Container which is updated whenever a GitHub push occurs.

docker run -d -v $PWD/data:/data -p 3000:3000 psitrax/psitransfer

The above command starts the PsiTransfer Docker container and

  • -d puts the process into background (daemon mode)
  • -v mounts the data volume into the container
  • -p forwards the traffic from port 3000 into the container

Protipp: There are several container tags if you want to use a specific version. E.g. 1 is always the latest stable 1.x.x and 1.1 correlates with 1.1.x.

If you want to customize some PsiTransfer configurations use environment parameters by adding -e flags to the docker run command.

docker run -v $PWD/data:/data -p 3000:8080 \
  -e PSITRANSFER_PORT=8080 \
  -e PSITRANSFER_DEFAULTRETENTION=3600 \
  psitrax/psitransfer

Protipp: By adding --restart always Docker will autostart the container after reboots.

Manual

You need to have Node.js version >= 7.4 and npm installed.

1.) Download and extract a prebuild PsiTransfer release from GitHub

2.) Install the dependencies: npm install --production

3.) Run the app: npm start

Linux Systemd service

You can also install PsiTransfer as (Linux) system service. Most distributions use Systemd as main init system. You should not run PsiTransfer with root privileges!

Preparation

# Create a target folder for PsiTransfer
mkdir -p /opt/psitransfer
cd /opt/psitransfer

# Download and extract a prebuild
curl -sL https://github.com/psi-4ward/psitransfer/releases/download/1.1.0-beta/psitransfer-1.1.0-beta.tar.gz | tar xz --strip 1

# Install dependencies
npm install --production

# Add a user psitransfer
sudo useradd --system psitransfer

# Make psitransfer owner of /opt/psitransfer
sudo chown -R psitransfer:psitransfer /opt/psitransfer

Systemd unit file

Grab the psitransfer.service sample file, put it in /etc/systemd/system/ and adjust to your needs.

cd /etc/systemd/system
sudo wget https://raw.githubusercontent.com/psi-4ward/psitransfer/master/docs/psitransfer.service

# Start the service
sudo systemctl start psitransfer

# Show the status
sudo systemctl status psitransfer

# Enable autostart on boot
sudo systemctl enable psitransfer

Happy sharing ;)


Interesting posts

Nginx reverse proxy setup to host multiple applications using Docker
A modern mailserver setup
Freifunk Uplink VM mit Auftrennung der Netze über VLANs