PeerTube is technically a node JS process that I have to launch in a very specific way. And I never managed to make it properly, like any other daemon with rcctl.

Until recently.

So I am now closer to having a full PeerTube instance running on OpenBSD.

Today, what’s blocking is more updates and compilations that don’t run as smoothly as I wish. And that makes me run out of disk space in the system partitions.

And the instance crashing every six months. Working on it too.

So actually, I am going to use another well-known node daemon, to make it run PeerTube : PM2.

Installation

I install Pm2 following instructions provided in the doc. Not that complicated.

doas npm install pm2 -g

Tadam.

PeerTube with Pm2

I am placing an ecosystem.config.js in /etc/pm/ (which I created). And actually, I launch pm2. Not PeerTube. Not yet.

module.exports = {
apps : [{
    name: 'peertube',
    instances : "3",
    exec_mode : "cluster",
    cwd:  '/var/www/peertube/peertube-latest/',
    "listen_timeout" : 3000,
    env: {
        "USER":         "_peertube",
        "NODE_ENV":     "production",
        "HOME":         "/var/www/peertube/",
        "NODE_CONFIG_DIR": "/var/www/peertube/config/",
    },
    script: '/var/www/peertube/peertube-latest/dist/server',

    }, ]

};

Now, if you pay attention, you may see that I use the cluster mode with 3 processes. No idea if it’s any good or useful, but let’s try. Until now, it looks no harm yet anyway.

Edit : actually it does harm. It makes tons of errors in logs. As of peertube 2.3, I advise against cluster mode.

RC

So, just need to start it at boot via rcctl, like any other daemon.

Let’s place a file /etc/rc.d/peertube, and don’t forget to activate in /etc/rc.conf.local :

#!/bin/ksh

daemon="/usr/local/bin/pm2"

daemon_user="_peertube"

. /etc/rc.d/rc.subr

pexp="node: PM2.*God Daemon.*"

rc_start() {
    ${rcexec} "${daemon} start /etc/pm/ecosystem.config.js"
}

rc_reload() {
    ${rcexec} "${daemon} reload /etc/pm/ecosystem.config.js"
}

rc_cmd $1

I launch pm2 as the _peertube directly. By the way, _peertube can come back to a rather normal $HOME repository, meaning /var/www/peertube.

Production

I can now run a rcctl check :

stephane@dina:/var/www/peertube rcctl check peertube
peertube(ok)

And, luxury, pm2 is a true NodeJS supervisor :

    stephane@dina:/var/www/peertube doas -u _peertube pm2 list
id name namespace version mode pid uptime status cpu mem user watching
0 peertube default 2.2.0 cluster 84782 5s 0 online 0% 0b _pe… disabled
1 peertube default 2.2.0 cluster 15036 5s 0 online 0% 0b _pe… disabled
2 peertube default 2.2.0 cluster 47410 5s 0 online 0% 0b _pe… disabled

One can manage application with pm2 as soon as it run in background.

stephane@dina:/var/www/peertube doas -u _peertube pm2 restart peertube
Use --update-env to update environment variables
[PM2] Applying action restartProcessId on app [peertube](ids: [ 0, 1, 2 ])
[PM2] [peertube](0) ✓
[PM2] [peertube](1) ✓
[PM2] [peertube](2) ✓
id name namespace version mode pid uptime status cpu mem user watching
0 peertube default 2.2.0 cluster 70669 0s 1 online 0% 0b _pe… disabled
1 peertube default 2.2.0 cluster 36994 0s 1 online 0% 0b _pe… disabled
2 peertube default 2.2.0 cluster 93986 0s 1 online 0% 0b _pe… disabled