Setting up OctoPrint on TrueNAS 13 server inside iocage Jails

I want to add a usb webcam, to watch the print and make timelapse. I saw that it needed to decomment some lines in this file to do that.
Sorry, I'm not an expert in FreeNAS and even less in Octoprint^^.
And sorry if my english is not so good, I'm french speaker ;).

Thank you very much for the great tutorial!
Unfortunately I fail at one point. When I run "pip install pip -upgrade" I get the following error message:


DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
ERROR: Invalid requirement: '\xe2\x80\x93upgrade'

Maybe you have an idea how to troubleshoot this, google wasnt really helpfull for me.
Best regards
Mjeni

EDIT:
Ok never mind, i just solved the problem by myself, i had to update to the newer python version.

pkg install pkg nano python py37-virtualenv py37-pip git bash

python3.7 -m virtualenv venv

Someone achieved to use camera for timelapse with Octoprint installed in a jail ?

Thanks for a great guide, I managed to install it on TrueNAS 12 Core Beta1 fine, and octoprint is up and running and the services start fine on boot.

However, I am not able to open the serial port, has anyone else had issues with this ?

Connecting to: /dev/ugen3.3
Changing monitoring state from "Offline" to "Error: Connection error, see Terminal tab"
Unexpected error while connecting to serial port: /dev/ugen3.3 SerialException: 'Could not configure port: (25, 'Inappropriate ioctl for device')' @ comm.py:_openSerial:2691 (hook default)
ugen3.3: <vendor 0x1a86 USB Serial> at usbus3, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (98mA)

root@octoprint:~ # ls -la /dev/ugen3.3
lrwxr-xr-x  1 root  wheel  9 Jul 29 10:39 /dev/ugen3.3 -> usb/3.3.0

ugen3.3: <vendor 0x1a86 USB Serial> at usbus3
uchcom0 on uhub1
uchcom0: <vendor 0x1a86 USB Serial, rev 1.10/2.64, addr 3> on usbus3
uchcom0: CH340 detected

Edit : well this is awkward, just letting it do auto worked fine :wink:

Hi,

Not sure what is happening, but I followed the guide for my Truenas setup. I can manually start the server, but it wont auto start the server.

I did have to install python3.8, but just unsure if its something I've missed or what it is. Any advice would be helpful thank you.

HI @victor76,

I'm running octoprint in a Truenas Jail - I used this script as a reference to have it start as a service at startup.

FreeBSD 12.1 Guide with rc.d script to start OctoPrint Automatically and as a Service

Cheers @jemison I’ll give that a try.

Edit: Nope, still not working on auto startup. Would be handy to have an up to date guide for TrueNas, but guess I’ll just stick with the Ubuntu VM.

Did you try service octoprint start ? And what do the octoprint logs say?

This is what my octoprint.sh script looks like, although I'm running it as root:

!/bin/sh

# PROVIDE: octoprint
# REQUIRE: NETWORKING
# KEYWORD: shutdown

# *******DESCRIPTION: FreeBSD 12.1 - rc.d script for the 3D Printer Software OctoPrint. This script takes advantage of FreeBSD's rc.subr framework to start OctoPrint automatically at startup and to allow it to be controlled as a FreeBSD service (eg. service octoprint start). This script assumes you are running OctoPrint as a virtual python environment (py27-virtualenv), but it can easily be changed if you want.

# *******HELP:
# 1. To increase security we want to avoid running it as root so create a user named "octoprint" (or any name you want but then change the script to reflect the change) and add the user to the "dialer" group so it can access the USB serial port that connects to the 3D Printer.
# 2. Add the line "octoprint_enable=yes" to the end of "etc/rc.conf" this will enable and start OctoPrint at boot time.
# 3. Place this rc.d script file in "usr/local/etc/rc.d/" (make sure this file is executable, if not run: "chmod +x /usr/local/etc/rc.d/octoprint")
# 4. Make sure the variables below such as, "command", "octoprint_basedir", "command_interpreter", etc..., reflect the correct paths to your octoprint executable, base directory, and virtual python executable (if you are using a virtual python environment like this script does).
# 5. After startup the service can be controlled like any other service "service octoprint {start,status,reset,stop,start}"

. /etc/rc.subr

name=octoprint
rcvar="octoprint_enable"

: ${octoprint_enable:=no}

octoprint_user=root
octoprint_group=operator
octoprint_user_path="/mypathtooctoprintinstall"

octoprint_basedir="${octoprint_user_path}/octoprint/.octoprint"
command_interpreter="${octoprint_user_path}/octoprint/venv/bin/python3.8"
command="${octoprint_user_path}/octoprint/venv/bin/${name}"

command_args="serve --basedir ${octoprint_basedir} > /dev/null 2>&1 &"
load_rc_config $name
run_rc_command "$1"

Ok, I'm getting somewhere. Seems as soon as I logged into the jail it wasn't putting me into the correct folder. I've got it all installed but it still wont start up automatically or via the octoprint menu.

When I try service octoprint start or service octoprint status its stating:

root@OctoPrint:/ # service octoprint status
/etc/rc.d/octoprint: WARNING: $command_interpreter /root/OctoPrint/venv/bin/python2.7 != /root/OctoPrint/venv/bin/python3.8
/etc/rc.d/octoprint: WARNING: $octoprint_enable is not set properly - see rc.conf(5).
Cannot 'status' octoprint. Set octoprint_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'.
root@OctoPrint:/ #

I have added the line octoprint_enable="YES" to the /etc/rc.conf and also made the script (octoprint) executable. I also noticed the usbconfig also gives an error: no device match or lack of permissions But this maybe because I'm putting the usb ports to my VM, but not sure on that.

Hi @victor76,

I've never been able to get the octoprint menu start/restart to work - but I rarely use it - so I just accepted the limitation of my skills :rofl:. Once you get the jail to autostart it - you should be good.

Based on the first warning - I'm guessing you have python 3.8 installed, but there's a mismatch to python2.7

The second warning should have been addressed by your edit to rc.conf.

IIRC, if you've defined allow_mount_devfs in your jail definition - you should be okay regarding the USB ports. But this will be pretty obvious if you're able/not able to connect to your printer.

Yes I have 3.8 installed as 2.7 command was giving me errors when I tried to install it where as 3.8 went straight through.

The edit is whats confusing me lol as its showing the line there but then states its not there.

Yes I followed the guide for rule set 3 and allow_mount_devfs

Is this what you have in your octoprint rc script? And does it exist?

lol oops forgot to alter that line, thats now fixed :wink: Just refuses to say rc.conf has been changed

What does service octoprint status output now?

Also, if you're running the service as root, octoprint won't run unless you have the command line argument "iknowwhatimdoing":

command_args="serve --iknowwhatimdoing --basedir ${octoprint_basedir} > /dev/null 2>&1 &"

Show this:

root@OctoPrint:/usr/local/etc # service octoprint status
/etc/rc.d/octoprint: WARNING: $octoprint_enable is not set properly - see rc.conf(5).
Cannot 'status' octoprint. Set octoprint_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'.
root@OctoPrint:/usr/local/etc #

Yep I have the 'iknowwhatimdoing' in the server command

If you type:

sysrc octoprint_enable

You should see the current value of octoprint_enable. And to set it, you can type:

sysrc octoprint_enable=YES

lol as soon as I tried those commands it showed:

octoprint_enable: YES

I thought I would give the enable command ago and it stated it changed it from YES -> YES but now shows that theres no octoprint in the directory or not executable:

service ocotoprint start
ocotoprint does not exist in /etc/rc.d or the local startup
directories (/usr/local/etc/rc.d), or is not executable

Where is the file you've been editing?

Mine is in /usr/local/etc/rc.d and has the following permissions:

[root@octoprint /usr/local/etc/rc.d]$ ls -l octoprint
-rwxr-xr-x  1 root  wheel  1955 Dec 18 18:38 octoprint

lol, its in the folder its stating it isnt, I've just copied the file from where it says it isn't into /usr/local/etc/rc.d/ folder and its gone back to the message:

root@OctoPrint:/usr/local/etc/rc.d # service octoprint restart
/etc/rc.d/octoprint: WARNING: $octoprint_enable is not set properly - see rc.conf(5).
Cannot 'restart' octoprint. Set octoprint_enable to YES in /etc/rc.conf or use 'onerestart' instead of 'restart'.
root@OctoPrint:/usr/local/etc/rc.d #

Dont you just linux lol

What happens if you do as it suggests:

service octoprint onestart

And can you show the output of ls -l in the /usr/local/etc/rc.d folder?