Skip to content

Instantly share code, notes, and snippets.

@lbrooney
Last active September 18, 2023 03:52
Show Gist options
  • Save lbrooney/cc11cce1a81592f7bdf8292d19f0e40e to your computer and use it in GitHub Desktop.
Save lbrooney/cc11cce1a81592f7bdf8292d19f0e40e to your computer and use it in GitHub Desktop.
TrueNAS Audiobookshelf Install Guide
# I will be writing this from the perspective of a TrueNAS user, but should be somewhat applicable for users of FreeBSD
# AT THE TIME OF WRITING, tone (https://github.com/sandreas/tone) is not ported to FreeBSD, so you'll miss out on it's
# capabilities which I think is getting metadata from files, the app SEEMS to run fine without it but YMMV
# READ THE README(and the Dockerfile) OF THE PROJECT, REQUIREMENTS MAY CHANGE BETWEEN WHEN YOU READ THIS AND WHEN I WROTE IT
# At the time of writing, based off the Dockerfile on the repository these are the packages you need explicitly for Audiobookshelf are:
"curl", "ffmpeg", "node16"
# You can choose between your preferred package manager, if you don't know, just go with "npm-node16"
# Here's all the packages you'll need, with nano for text editing, this will just tell iocage what packages we want installed by default
echo '{"pkgs":["curl","ffmpeg","node16","npm-node16","nano"]}' > /tmp/pkg.json
# next create the iocage !!! CHANGE <IPADDR> TO WHAT YOU WANT, CHANGE <ROUTER> TO YOUR DEFAULT ROUTER !!!
sudo iocage create -n "audiobookshelf" -p /tmp/pkg.json -r 13.2-RELEASE ip4_addr="vnet0|<IPADDR>/24" defaultrouter="<ROUTER>" vnet="on" allow_raw_sockets="1" boot="on"
# remove the tmp pkg
rm /tmp/pkg.json
# next create a place for audiobookshelf settings to go
sudo iocage exec audiobookshelf mkdir -p /config/audiobookshelf/config
sudo iocage exec audiobookshelf mkdir -p /config/audiobookshelf/metadata
# create a folder outside your jail so your metadata/settings are safe if ever need to migrate/delete the jail
# personally I store them in folder called apps which stores configs for all my services
mkdir -p /mnt/<NAME_OF_POOL>/apps/audiobookshelf
# mount the folder
sudo iocage fstab -a audiobookshelf /mnt/<NAME_OF_POOL>/apps/audiobookshelf /config/audiobookshelf nullfs rw 0 0
# next I'm going to console into the iocage, but you can continue to use exec
sudo iocage console audiobookshelf
# next we are going to download audiobookshelf, you have to options
# bleeding edge: clone the repository, you'll need git, updates easy as you can just git pull, probably unstable or broken
# release: stable, what the rest of guide will assume is being used
## INSTALL
# go to https://github.com/advplyr/audiobookshelf/releases/latest, scroll to assets right click your preferred archive format and click copy link
# you can cd to your preferred install directory, I'm going to stick with ~
# !!! FOR THE FOLLOWING SECTION I USE <VERSION_NUM> TO BE AGNOSTIC, CHANGE COMMANDS TO YOUR VERSION !!!
# I'm going with zip
fetch https://github.com/advplyr/audiobookshelf/archive/refs/tags/v<VERSION_NUM>.zip
unzip audiobookshelf-<VERSION_NUM>.zip
# It will extract to a folder whose name is the audiobookshelf-number version
# next will install the package requirements and compile the app
cd audiobookshelf-<VERSION_NUM>
npm run client
npm ci --omit=dev
# next if we really wanted to, we can run the app and see that it's only accessible from that jail(local host)
node prod
# we can fix that by doing
node prod --host 0.0.0.0
# now we can access it at <IP_ADDR>:3333, it works!! Anybody on the local network can access it!
# but now we'll have to pass in command line args for each thing, it just becomes a mess, I guess we could make an bash script
# HOWEVER there's a better way, PM2, a process manager for Node apps, bonus points is that it'll autorestart our app if it every crashes
npm install -g pm2
mkdir -p /usr/local/etc/rc.d/
pm2 startup
# PM2 has a nice little config we can setup that will set all the environment variables for us
nano /config/audiobookshelf/ecosystem.config.js
# Adjust the script path and any other settings you'd like
# notice I use index.js for this, so the port will now be 80, but if you want 3333 you can swap back to prod.js or uncomment port
module.exports = {
apps : [{
name : "audiobookshelf",
script : "/root/audiobookshelf-<VERSION_NUM>/index.js",
env: {
"NODE_ENV": "production",
"HOST": "0.0.0.0",
//"PORT": "3333",
"CONFIG_PATH": "/config/audiobookshelf/config",
"METADATA_PATH": "/config/audiobookshelf/metadata",
//"AUDIOBOOKSHELF_UID": "0", // ROOT
//"AUDIOBOOKSHELF_GID": "0", // WHEEL
"SOURCE": "FreeBSD",
//"ROUTER_BASE_PATH": "",
}
}]
}
# Now save and exit nano and run the app
pm2 start /config/audiobookshelf/ecosystem.config.js
pm2 save
# you can the app's status with
pm2 status
# you can see the app's node output with(you can get <PM2_ID> from status, it's on the left side)
pm2 logs <PM2_ID>
# CTRL+C to get out of logs, your app will stay running
# Now it should work, mount your audiobook or ebook folders, then add them as libaries
# Helpful(?) note: When creating library don't use the Browse for Folder button, just manually type in the folder path
# now if you want to make this work outside of your network, use a reverse proxy
# they have some sample configs: https://github.com/advplyr/audiobookshelf#reverse-proxy-set-up
## UPDATING
# Back up your settings/metadata
# Read the patch notes to see if there's any breaking changes
# Follow the above install notes and update the path in the ecosystem.config.js
# Then run the following commands
pm2 stop audiobookshelf
pm2 delete audiobookshelf
pm2 start /config/audiobookshelf/ecosystem.config.js
pm2 save
I HOPE THIS WAS HELPFUL AND WILL SURE YOU WELL!!! Apologies if the formatting is bad.
Also thank you to SleepingPanda(github.com/SleepingPanda) his guides inspired this one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment