Jattie van der Linde

Shoe string engineering

User Tools

Site Tools


projects:3dprint:octoprint

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projects:3dprint:octoprint [2023/05/18 13:45] – [Make everything accessible on port 80] s to edit configurations and view logs, you need to get this set up. SSH comes bundled with Linux and is already set up and installed, we just need some minor edits to allow users to log in using password authentic jattieprojects:3dprint:octoprint [2023/05/18 19:26] (current) – ↷ Links adapted because of a move operation jattie
Line 2: Line 2:
  
 <WRAP center round info 60%> <WRAP center round info 60%>
-The long way is for if you care about the technical steps and want to reproduce it yourself. See the [[projects:3dprint:octoprint_image|short way to just get the LXC Octoprint image]] and get up and running as easy as possible.+The long way is for if you care about the technical steps and want to reproduce it yourself. See the [[projects:3dprint:octoprint_short|short way to just get the LXC Octoprint image]] and get up and running as easy as possible.
 </WRAP> </WRAP>
  
Line 303: Line 303:
 ==== Initialise LXD ==== ==== Initialise LXD ====
  
-The next step is to i      daemon+The next step is to is to edit configurations and view logs, you need to get this set up. 
 + 
 +SSH comes bundled with Linux and is already set up and installed, we just need some minor edits to allow users to log in using password authentication. The linux preferred way is to create RSA tokens and it's a great idea, just beyond the scope if this document. ((https://www.ibm.com/docs/en/sia?topic=kbaula-enabling-rsa-key-based-authentication-unix-linux-operating-systems-3))  
 + 
 +We are just going to allow a password authentication for now: 
 + 
 +We need to:  
 + 
 +  * edit the ssh daemon configuration first 
 +  * restart the service 
 + 
 +We can do it from our host Linux server OS directly on the container like this: 
 + 
 +<cli> 
 +dev@hp-linux:~$ lxc exec octo -- bash -c "nano /etc/ssh/sshd_config" 
 +</cli> 
 + 
 +That opens the sshd_config file on ythe container and allows us to edit it locally. 
 + 
 +  * find and uncomment/edit ''PasswordAuthentication no'' to ''yes'' 
 + 
 +<code powershell> 
 +# To disable tunneled clear text passwords, change to no here! 
 +#PasswordAuthentication no 
 +#PermitEmptyPasswords no 
 +</code> 
 + 
 +<code powershell> 
 +# To disable tunneled clear text passwords, change to no here! 
 +#PasswordAuthentication no 
 +PasswordAuthentication yes 
 +#PermitEmptyPasswords no 
 +</code> 
 + 
 +<WRAP center round important 60%> 
 +Then remember to restart sshd 
 +</WRAP> 
 + 
 + 
 +<cli> 
 +dev@hp-linux:~$ lxc exec octo -- bash -c "systemctl restart sshd" 
 +</cli> 
 + 
 +Now test ssh connectivity 
 + 
 +<cli> 
 +dev@hp-linux:~$ ssh octo@octo 
 +octo@cr6's password: 
 +Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-71-generic x86_64) 
 + 
 + * Documentation:  https://help.ubuntu.com 
 + * Management:     https://landscape.canonical.com 
 + * Support:        https://ubuntu.com/advantage 
 + 
 +  System information as of Thu May 18 09:37:40 UTC 2023 
 + 
 + 
 + 
 + * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s 
 +   just raised the bar for easy, resilient and secure K8s cluster deployment. 
 + 
 +   https://ubuntu.com/engage/secure-kubernetes-at-the-edge 
 + 
 +Expanded Security Maintenance for Applications is not enabled. 
 + 
 +13 updates can be applied immediately. 
 +5 of these updates are standard security updates. 
 +To see these additional updates run: apt list --upgradable 
 + 
 +9 additional security updates can be applied with ESM Apps. 
 +Learn more about enabling ESM Apps service at https://ubuntu.com/esm 
 + 
 + 
 +Last login: Thu May 18 09:34:52 2023 from 192.168.0.32 
 +octo@octo:~$ 
 + 
 +</cli> 
 + 
 +We are now connected as the octo user on the oct instance of lxc. I use PuTTY((https://www.putty.org/)) to connect from my Windows PC into a Linux shell session to work on the backends of the Linux headless systems. 
 + 
 + 
 + 
 + 
 +===== Start up and set up Octprint in the container ===== 
 + 
 +The last section follows the instruction from the Octoprint community forum for [[https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspberry-pi-os-debian/2337|published here]] ((https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspberry-pi-os-debian/2337))  
 + 
 +There is a current issue with some of the key plugins I need to work, i.e. Filament manager and Spool manager that causes failures running under Python 3.10 on the Linux setup. Forcing the install to Python 3.9 in the virtual environment creation, resolves the issues.  
 + 
 +==== Set up a Python 3.9 virtual environment (venv) ==== 
 + 
 +  * add repositories to get access to 3.9 
 +  * install 3.9 
 + 
 +<cli> 
 +octo@octo:~# sudo add-apt-repository universe            #add universe as a repo option 
 +octo@octo:~# sudo apt update                             #and update the repo source list on the instance 
 +octo@octo:~# sudo apt install python3.9                  #try to install 3.9, stop here on success 
 +octo@octo:~# sudo add-apt-repository ppa:deadsnakes/ppa  #on fail add deadsnakes 
 +octo@octo:~# sudo apt install python3.9                  #now 3.9 should install 
 +</cli> 
 + 
 +  * Create and change into the OctoPrint folder 
 +  * Create a 3.9 venv(Virtual Environment) 
 +  * Activate the new environment for further steps to follow 
 + 
 +<cli> 
 +octo@octo:~$ mkdir OctoPrint && cd OctoPrint 
 +octo@octo:~/OctoPrint$ python3.9 -m venv venv 
 +octo@octo:~/OctoPrint$ source venv/bin/activate 
 +(venv) octo@octo:~/OctoPrint$ 
 +</cli> 
 + 
 +Note the last line showing our 3.9 environment to be activated. 
 + 
 +==== Add pip and wheel updates ==== 
 + 
 + 
 +<cli> 
 +(venv) octo@octo:~/OctoPrint$ pip install --upgrade pip wheel 
 +Requirement already satisfied: pip in ./venv/lib/python3.9/site-packages (22.0.4) 
 +Collecting pip 
 +  Using cached pip-23.1.2-py3-none-any.whl (2.1 MB) 
 +Collecting wheel 
 +  Using cached wheel-0.40.0-py3-none-any.whl (64 kB) 
 +Installing collected packages: wheel, pip 
 +  Attempting uninstall: pip 
 +    Found existing installation: pip 22.0.4 
 +    Uninstalling pip-22.0.4: 
 +      Successfully uninstalled pip-22.0.4 
 +Successfully installed pip-23.1.2 wheel-0.40.0 
 +</cli> 
 + 
 +==== Install Octoprint ==== 
 + 
 +On successful completion, proceed to install octoprint 
 + 
 +<cli> 
 +(venv) octo@octo:~/OctoPrint$ pip install octoprint 
 +Collecting octoprint 
 +  Using cached OctoPrint-1.8.7-py2.py3-none-any.whl (3.9 MB) 
 +Collecting OctoPrint-FileCheck>=2021.2.23 (from octoprint) 
 +  Using cached OctoPrint_FileCheck-2021.2.23-py2.py3-none-any.whl (19 kB) 
 + 
 +</cli> 
 + 
 +Wait for it to run to completion and address any errors that might show up. Hopefully no issues will arise, mine ran through without failures here. 
 + 
 +==== Assign octo user run permissions ==== 
 + 
 +Now let us assign two more permissions to our octo user. 
 + 
 +<cli> 
 +(venv) octo@octo:~/OctoPrint$ sudo usermod -aG tty octo 
 +(venv) octo@octo:~/OctoPrint$ sudo usermod -aG dialout octo 
 +</cli> 
 + 
 +The commands above add octo to the tty and dialout groups, so octo can run terminal session and connect to our devices like the prinyter port and camera ports. 
 + 
 +==== Do a test run ==== 
 + 
 +<cli> 
 +(venv) octo@octo:~/OctoPrint$ ~/OctoPrint/venv/bin/octoprint serve 
 +2023-05-18 12:49:46,585 - octoprint.startup - INFO - ****************************************************************************** 
 +2023-05-18 12:49:46,586 - octoprint.startup - INFO - Starting OctoPrint 1.8.7 
 +2023-05-18 12:49:46,586 - octoprint.startup - INFO - ****************************************************************************** 
 +</cli> 
 + 
 +So we have concluded the basics to get a base install for Octoprint working. 
 + 
 +{{:projects:3dprint:opsetupwizard.jpg?nolink&600|}} 
 + 
 +==== Autostart Octoprint as a Linux Service ==== 
 + 
 +Run the automated script here: 
 + 
 +<cli> 
 +(venv) octo@octo:~$ wget https://github.com/OctoPrint/OctoPrint/raw/master/scripts/octoprint.service && sudo mv octoprint.service /etc/systemd/system/octoprint.service 
 +</cli> 
 + 
 +Or copy from here: 
 + 
 +<code ini octoprint.service> 
 +[Unit] 
 +Description=Octoprint Web Service 
 +After=network-online.target 
 +Wants=network-online.target 
 + 
 +[Service] 
 +Environment="LC_ALL=C.UTF-8" 
 +Environment="LANG=C.UTF-8" 
 +Type=exec 
 +User=octo 
 +ExecStart=/home/octo/OctoPrint/venv/bin/octoprint 
 + 
 +[Install] 
 +WantedBy=multi-user.target 
 +</code> 
 + 
 +I use nano: 
 + 
 +<cli> 
 +(venv) octo@octo:~$ nano /etc/systemd/system/octoprint.service 
 +</cli> 
 + 
 +Once the edits are completed and matching our setup, enable and start the service. 
 + 
 + 
 +<cli> 
 +(venv) octo@octo:~$ sudo systemctl enable octoprint 
 +Created symlink /etc/systemd/system/multi-user.target.wants/octoprint.service → /etc/systemd/system/octoprint.service. 
 +(venv) octo@octo:~$ sudo systemctl start octoprint 
 +(venv) octo@octo:~$ sudo systemctl status octoprint 
 +● octoprint.service - Octoprint Web Service 
 +     Loaded: loaded (/etc/systemd/system/octoprint.service; enabled; vendor preset: enabled) 
 +     Active: active (running) since Thu 2023-05-18 13:25:25 UTC; 6s ago 
 +   Main PID: 16533 (octoprint) 
 +      Tasks: 12 (limit: 9209) 
 +     Memory: 79.0M 
 +        CPU: 4.457s 
 +     CGroup: /system.slice/octoprint.service 
 +             └─16533 /home/octo/OctoPrint/venv/bin/python3.9 /home/octo/OctoPrint/venv/bin/octoprint 
 + 
 +May 18 13:25:28 octo octoprint[16533]: 2023-05-18 13:25:28,904 - octoprint.server - INFO - Listening on http://0.0.0.0:5000 and http://[::]:5000 
 +May 18 13:25:28 octo octoprint[16533]: 2023-05-18 13:25:28,935 - octoprint.plugins.pluginmanager - INFO - Loaded plugin repository data from dis> 
 +May 18 13:25:29 octo octoprint[16533]: 2023-05-18 13:25:29,274 - octoprint.util.pip - INFO - Using "/home/octo/OctoPrint/venv/bin/python3.9 -m p> 
 +May 18 13:25:29 octo octoprint[16533]: 2023-05-18 13:25:29,279 - octoprint.util.pip - INFO - pip installs to /home/octo/OctoPrint/venv/lib/pytho> 
 +May 18 13:25:29 octo octoprint[16533]: 2023-05-18 13:25:29,279 - octoprint.util.pip - INFO - ==> pip ok -> yes 
 +May 18 13:25:29 octo octoprint[16533]: 2023-05-18 13:25:29,287 - octoprint.plugins.pluginmanager - INFO - Loaded notice data from disk, was stil> 
 +May 18 13:25:29 octo octoprint[16533]: 2023-05-18 13:25:29,291 - octoprint.plugins.softwareupdate - INFO - Minimum free storage across all updat> 
 +May 18 13:25:29 octo octoprint[16533]: 2023-05-18 13:25:29,291 - octoprint.plugins.softwareupdate - INFO - Fetching check overlays from https://> 
 +May 18 13:25:29 octo octoprint[16533]: 2023-05-18 13:25:29,670 - octoprint.server.preemptive_cache - INFO - Preemptively caching / (ui _default)> 
 +May 18 13:25:31 octo octoprint[16533]: 2023-05-18 13:25:31,095 - octoprint.server.preemptive_cache - INFO - ... done in 1.42s 
 +lines 1-20/20 (END) 
 + 
 +</cli> 
 + 
 +===== Advanced Features ===== 
 + 
 +==== Enable .local network access ==== 
 + 
 +to resolve the machine name with octo.local we need the avahi service. 
 + 
 +  * sudo apt install avahi-daemon 
 +  * systemctl restart avahi-daemon 
 +  * systemctl status avahi-daemon 
 + 
 + 
 + 
 +==== Make everything accessible on port 80 ==== 
 + 
 +  * install haproxy 
 +  * configure haproxy 
 +  * restart the service 
 + 
 +=== Install === 
 + 
 +<cli> 
 +(venv) octo@octo:~$ sudo apt install haproxy 
 +Reading package lists... Done 
 +Building dependency tree... Done 
 +Reading state information... Done 
 +</cli> 
 + 
 +=== Config === 
 + 
 +<cli> 
 +(venv) octo@octo:~$ sudo nano /etc/haproxy/haproxy.cfg 
 +</cli> 
 + 
 +<code apache haproxy.cfg> 
 +global 
 +        log /dev/log    local0 
 +        log /dev/log    local1 notice 
 +        chroot /var/lib/haproxy 
 +        stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 
 +        stats timeout 30s 
 +        user haproxy 
 +        group haproxy 
 +        daemon
  
         # Default SSL material locations         # Default SSL material locations
Line 342: Line 621:
         http-request replace-path /webcam/(.*)   /\1         http-request replace-path /webcam/(.*)   /\1
         server webcam1  127.0.0.1:8080         server webcam1  127.0.0.1:8080
- 
 </code> </code>
  
-  * restart the haproxy service +  * Restart the service 
-  * check the status of the service for any error messages after the edits +  * Check the status after the edits and restart
  
 <cli> <cli>
Line 378: Line 655:
 (venv) octo@octo:~$ (venv) octo@octo:~$
  
-</cli 
-==== Make everything accessible on port 80 ==== 
- 
-  * install haproxy 
-  * configure haproxy 
-  * restart the service 
- 
-=== Install === 
- 
-<cli> 
-(venv) octo@octo:~$ sudo apt install haproxy 
-Reading package lists... Done 
-Building dependency tree... Done 
-Reading state information... Done 
 </cli> </cli>
  
-=== Config ===+We should now be able to access the server on the standard port 80, i.e. no port specification required.
  
-<cli> 
-(venv) octo@octo:~$ sudo nano /etc/haproxy/haproxy.cfg 
-</cli> 
- 
-<code apache haproxy.cfg> 
-global 
-        log /dev/log    local0 
-        log /dev/log    local1 notice 
-        chroot /var/lib/haproxy 
-        stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 
-        stats timeout 30s 
-        user haproxy 
-        group haproxy 
-   
 ==== Setting up SSH access to your container ==== ==== Setting up SSH access to your container ====
  
projects/3dprint/octoprint.1684417504.txt.gz · Last modified: 2023/05/18 13:45 by jattie