HiddenParrot
Cadet
- Joined
- Sep 22, 2023
- Messages
- 1
Introduction
A guide to install a popular organizer for your, ehrm, alternative media content, in a jail on TrueNAS Core 13.0.
Resources
Caveats, assumptions and a warning
In order for the
Install ffmpeg
ffmpeg/ffprobe is a dependency for stashapp, and needs to be installed manually in your iocage jail:
Create user and group
To avoid stashapp running as root, you can set up a user/group that stash runs as. You can create new ones, or use existing one. Whatever fits into your system. For this guide it is assumed that you create a user/group named stash. If you use a different user/group, you need to fix ownership for all relevant files/directories.
Download stash-linux
Download the latest version of the
Create configuration directory
Stashapp needs a directory for its config file, database and more. Remember to change ownership and permission for the folder you select. The script we will look at in the next step has this path as the default:
rc.d startup script
In order for stashapp to run as a daemon in the background, and also start at boot, you need a rc.d script.
In the editor, paste in the following without making changes:
To save, press
Enable the service at boot
If you want Stash to run when you start the jail, run the following command:
And to start the service, reboot the jail or run this command:
Stop and status should also work:
When Stash is running, it should be available at http://jail-IP:9999/
During setup you can leave all the paths for config, database, etc empty to use the default. They will then be stored in the config-folder we created earlier so you can easily backup the folder. Only add your media content.
Optional steps
You can change the location where stash stores the configuration files and database. Please note that the path needs to end with `config.yml` even if it does not exist yet. Stash will create it for you. Remember to fix ownership and permissions of the location you choose.
You can change the user and group that Stash runs as. Remember that the config_dir needs to be owned by the user that Stash runs as, aswell as the stash-linux binary
Its also possible to change the location of the stash-linux binary
Conclusion
That is about it! This was a fun little project, and a great entrance for me to learn more about rc.d scripting. I am sure the script is very crude and has room for improvement though. I am happy to take feedback to improve this guide, and curious to see if this is helpful to anyone.
Good luck!
A guide to install a popular organizer for your, ehrm, alternative media content, in a jail on TrueNAS Core 13.0.
Resources
- Official GitHub repo: https://github.com/stashapp/stash
- Official TrueNAS install docs: https://docs.stashapp.cc/getting-started/installation/freenas-truenas/
Caveats, assumptions and a warning
- The method documented here has only been given cursory testing, so there may be compatibility problems
- This method assumes that stash will be run within a previously created iocage jail - the process to create and configure the jail is not included here
- This is my first guide and my first rc.d script. Unintended consequences may occur, and it is essential that you have backups/snapshots of any media that you mount into the jail.
In order for the
stash-linux
binary to work in a FreeBSD system, Linux compatibility must be enabled both in the system and the jail. To enable Linux compatibility:- Navigate to
System -> Tunables
in the TrueNAS Web UI - Click
Add
and enter the following:- Variable:
linux_enable
- Value:
YES
- Type:
rc.conf
- Variable:
- Click submit.
- In a shell in your iocage jail, edit
/etc/rc.conf
to add:enable_linux="YES"
- Reboot the system.
Install ffmpeg
ffmpeg/ffprobe is a dependency for stashapp, and needs to be installed manually in your iocage jail:
Code:
pkg install ffmpeg
Create user and group
To avoid stashapp running as root, you can set up a user/group that stash runs as. You can create new ones, or use existing one. Whatever fits into your system. For this guide it is assumed that you create a user/group named stash. If you use a different user/group, you need to fix ownership for all relevant files/directories.
Code:
pw useradd -n stash -u 1069 -d /nonexistent -s /usr/sbin/nologin
Download stash-linux
Download the latest version of the
stash-linux
binaries from the github-release pages. For this guide it is assumed that you put it in /usr/local/bin
, as stashapp needs the ffmpeg binaries to be in the same location. If you want to put the binary in a different location, you would need to ln the ffmpeg and ffprobe binaries there. Remember to change ownership of the binary to the user/group that should run it, and also make it executable.Code:
cd /usr/local/bin fetch https://github.com/stashapp/stash/releases/download/v0.22.1/stash-linux chown stash:stash stash-linux chmod +x stash-linux
Create configuration directory
Stashapp needs a directory for its config file, database and more. Remember to change ownership and permission for the folder you select. The script we will look at in the next step has this path as the default:
Code:
mkdir /usr/local/etc/stash chown stash:stash /usr/local/etc/stash
rc.d startup script
In order for stashapp to run as a daemon in the background, and also start at boot, you need a rc.d script.
Code:
mkdir /usr/local/etc/rc.d ee /usr/local/etc/rc.d/stash
In the editor, paste in the following without making changes:
Code:
#!/bin/sh # PROVIDE: stash # REQUIRE: DAEMON # KEYWORD: shutdown . /etc/rc.subr name=stash rcvar=stash_enable load_rc_config $name : ${stash_enable:="NO"} : ${stash_user:="stash"} : ${stash_group:="stash"} : ${stash_config_dir:="/usr/local/etc/stash/config.yml"} : ${stash_exec_bin:="/usr/local/bin/stash-linux"} #daemon pidfile="/var/run/${name}.pid" command="/usr/sbin/daemon" command_args="-f -P ${pidfile} ${stash_exec_bin} --config ${stash_config_dir}" start_precmd="stash_precmd" stash_precmd() { install -o ${stash_user} -g ${stash_group} /dev/null ${pidfile} } run_rc_command $1
To save, press
ESC + Enter
and confirm with a
and make it executable with chmod +x /usr/local/etc/rc.d/stash
Enable the service at boot
If you want Stash to run when you start the jail, run the following command:
Code:
sysrc "stash_enable=YES"
And to start the service, reboot the jail or run this command:
Code:
service stash start
Stop and status should also work:
Code:
service stash status service stash stop
When Stash is running, it should be available at http://jail-IP:9999/
During setup you can leave all the paths for config, database, etc empty to use the default. They will then be stored in the config-folder we created earlier so you can easily backup the folder. Only add your media content.
Optional steps
You can change the location where stash stores the configuration files and database. Please note that the path needs to end with `config.yml` even if it does not exist yet. Stash will create it for you. Remember to fix ownership and permissions of the location you choose.
Code:
sysrc "stash_config_dir=path/to/location/config.yml"
You can change the user and group that Stash runs as. Remember that the config_dir needs to be owned by the user that Stash runs as, aswell as the stash-linux binary
Code:
sysrc "stash_user=usernamegoeshere" sysrc "stash_group=groupnamegoeshere"
Its also possible to change the location of the stash-linux binary
Code:
sysrc "stash_exec_bin=/path/to/stash-linux"
Conclusion
That is about it! This was a fun little project, and a great entrance for me to learn more about rc.d scripting. I am sure the script is very crude and has room for improvement though. I am happy to take feedback to improve this guide, and curious to see if this is helpful to anyone.
Good luck!