Software Link to heading

On the host Link to heading

First we create the jail:

# bastille create -V audiobookshelf 14.0-RELEASE "DHCP SLAAC" igb0

# bastille console audiobookshelf

I prefer to use VNET jails so that I can assign IP addresses later.

In the jail Link to heading

Jail dependencies Link to heading

First, we install some required dependencies:

# pkg update

# pkg install \
    ffmpeg \
    git \
    node \
    npm \
    vim

Create a folder for the audiobookshelf configuration:

# mkdir /usr/local/etc/AudioBookShelf

Next, we clone a specific tag of the audiobookshelf repository and go into that folder:

# git clone --depth 1 --branch v2.7.2 https://github.com/advplyr/audiobookshelf.git abs

# cd abs/

We need to create a js configuration file from the example given and then modify the paths:

~/abs # cp .devcontainer/dev.js .

~/abs # vim dev.js

// Using port 3333 is important when running the client web app separately
const Path = require('path')
module.exports.config = {
  Port: 3333,
  ConfigPath: '/usr/local/etc/AudioBookShelf/config',
  MetadataPath: '/usr/local/etc/AudioBookShelf/metadata',
  FFmpegPath: '/usr/local/bin/ffmpeg',
  FFProbePath: '/usr/local/bin/ffprobe'
}

Now, we’re ready to install the node.js dependencies. This is mostly taken from audiobookshelf instructions. But, since we are using version 20 of node, we will run into a ssl error. This is fixed by running npm audit fix --force in the client folder.

~/abs # npm ci

~/abs # cd client

~/abs/client # npm ci

~/abs/client # npm audit fix --force

~/abs/client # npm run generate

~/abs # cd ..

Finally, we’re ready to test:

~/abs # npm run dev                                                                                                                                   
                                                                                                                                                                          
> audiobookshelf@2.7.2 dev                                                                                                                                                
> nodemon --watch server index.js                                                                                                                                         
                                                                                                                                                                          
[nodemon] 2.0.20                                                                                                                                                          
[nodemon] to restart at any time, enter `rs`                                                                                                                              
[nodemon] watching path(s): server/**/*                                                                                                                                   
[nodemon] watching extensions: js,mjs,json                                                                                                                                
[nodemon] starting `node index.js`                                                                                                                                        
Config /usr/local/etc/AudioBookShelf/config /usr/local/etc/AudioBookShelf/metadata                                                                                        
[2024-02-19 19:20:06.726] INFO: === Starting Server ===                                                                                                                   
[2024-02-19 19:20:06.737] INFO: [Server] Init v2.7.2                                                                                                                      
[2024-02-19 19:20:06.739] INFO: [Database] Initializing db at "/usr/local/etc/AudioBookShelf/config/absdatabase.sqlite"                                                   
[2024-02-19 19:20:06.758] INFO: [Database] Db connection was successful                                                                                                   
[2024-02-19 19:20:06.813] INFO: [Database] Db initialized with models: user, library, libraryFolder, book, podcast, podcastEpisode, libraryItem, mediaProgress, series, bo
okSeries, author, bookAuthor, collection, collectionBook, playlist, playlistMediaItem, device, playbackSession, feed, feedEpisode, setting                                

          <<SOME OUTPUT REMOVED FOR CLARITY>>                                           
                                                                                
[2024-02-19 19:20:06.836] INFO: [BinaryManager] Found ffmpeg at /usr/local/bin/ffmpeg                                                                                     
[2024-02-19 19:20:06.836] INFO: [BinaryManager] Found ffprobe at /usr/local/bin/ffprobe                                                                                   
[2024-02-19 19:20:06.841] INFO: Listening on port :3333        

And going to the :3333 should show you:

AudioBookShelf Start Page

The two paths in the start page will be set to whatever you set as the ConfigPath and MetadataPath in dev.js.

Creating a rc.d script Link to heading

After a bit of trial-and-error, I was able to get audiobookshelf to start automatically with this rc.d script:

#!/bin/sh                                                                                                                                                                 
                                                                                                                                                                          
# PROVIDE: audiobookshelf
# REQUIRE: ldconfig
# This require line is needed so that audiobookshelf is started *after* the shared libraries are available                                                                                                                                                 
                                                                                                                                                                          
# Enable this script by adding:                                                                                                                                           
# audiobookshelf_enable="YES"                                                                                                                                             
# ... to /etc/rc.conf                                                                                                                                                     
                                                                                                                                                                          
. /etc/rc.subr                                                                                                                                                            
                                                                                                                                                                          
name=audiobookshelf                                                                                                                                                       
                                                                                                                                                                          
rcvar=audiobookshelf_enable                                                                                                                                               
                                                                                                                                                                          
audiobookshelf_chdir="/root/abs/"                                                                                                                                         

audiobookshelf_command="/usr/local/bin/npm"                                                                                                                               

audiobookshelf_args="run dev"

pidfile="/var/run/${name}.pid"

logfile="/var/log/${name}.log"

procname="/usr/local/bin/node"

command="/usr/sbin/daemon"

command_args="-S -f -o ${logfile} -p ${pidfile} ${audiobookshelf_command} ${audiobookshelf_args}"

PATH=/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin

load_rc_config $name
: ${audiobookshelf_enable:=no}

run_rc_command "$1"

The only problem with this script is that it can start the service, but not restart or stop it. But that’s a problem for another day.