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 12:51] – [Set up a Python 3.9 virtual environment (venv)] 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 418: Line 418:
 Note the last line showing our 3.9 environment to be activated. Note the last line showing our 3.9 environment to be activated.
  
-Now add pip and wheel updates.+==== Add pip and wheel updates ==== 
  
 <cli> <cli>
Line 434: Line 435:
 Successfully installed pip-23.1.2 wheel-0.40.0 Successfully installed pip-23.1.2 wheel-0.40.0
 </cli> </cli>
 +
 +==== Install Octoprint ====
  
 On successful completion, proceed to install octoprint On successful completion, proceed to install octoprint
Line 447: Line 450:
  
 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. 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. Now let us assign two more permissions to our octo user.
Line 456: Line 461:
  
 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. 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> <cli>
Line 466: Line 473:
 So we have concluded the basics to get a base install for Octoprint working. 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
 +        ca-base /etc/ssl/certs
 +        crt-base /etc/ssl/private
 +
 +        # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
 +        ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
 +        ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
 +        ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
 +
 +defaults
 +        log     global
 +        mode    http
 +        option  httplog
 +        option  dontlognull
 +        timeout connect 5000
 +        timeout client  50000
 +        timeout server  50000
 +        errorfile 400 /etc/haproxy/errors/400.http
 +        errorfile 403 /etc/haproxy/errors/403.http
 +        errorfile 408 /etc/haproxy/errors/408.http
 +        errorfile 500 /etc/haproxy/errors/500.http
 +        errorfile 502 /etc/haproxy/errors/502.http
 +        errorfile 503 /etc/haproxy/errors/503.http
 +        errorfile 504 /etc/haproxy/errors/504.http
 +
 +frontend public
 +        bind :::80 v4v6
 +        use_backend webcam if { path_beg /webcam/ }
 +        default_backend octoprint
 +
 +backend octoprint
 +        option forwardfor
 +        server octoprint1 127.0.0.1:5000
 +
 +backend webcam
 +        http-request replace-path /webcam/(.*)   /\1
 +        server webcam1  127.0.0.1:8080
 +</code>
 +
 +  * Restart the service
 +  * Check the status after the edits and restart
 +
 +<cli>
 +(venv) octo@octo:~$ sudo systemctl restart haproxy
 +(venv) octo@octo:~$ sudo systemctl status haproxy
 +● haproxy.service - HAProxy Load Balancer
 +     Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)
 +     Active: active (running) since Thu 2023-05-18 13:43:46 UTC; 7s ago
 +       Docs: man:haproxy(1)
 +             file:/usr/share/doc/haproxy/configuration.txt.gz
 +    Process: 16750 ExecStartPre=/usr/sbin/haproxy -Ws -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS)
 +   Main PID: 16752 (haproxy)
 +      Tasks: 9 (limit: 9209)
 +     Memory: 138.4M
 +        CPU: 239ms
 +     CGroup: /system.slice/haproxy.service
 +             ├─16752 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock
 +             └─16754 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock
 +
 +May 18 13:43:46 octo haproxy[10866]: [NOTICE]   (10866) : haproxy version is 2.4.22-0ubuntu0.22.04.1
 +May 18 13:43:46 octo haproxy[10866]: [NOTICE]   (10866) : path to executable is /usr/sbin/haproxy
 +May 18 13:43:46 octo haproxy[10866]: [ALERT]    (10866) : Current worker #1 (10868) exited with code 143 (Terminated)
 +May 18 13:43:46 octo haproxy[10866]: [WARNING]  (10866) : All workers exited. Exiting... (0)
 +May 18 13:43:46 octo systemd[1]: haproxy.service: Deactivated successfully.
 +May 18 13:43:46 octo systemd[1]: Stopped HAProxy Load Balancer.
 +May 18 13:43:46 octo systemd[1]: haproxy.service: Consumed 4.332s CPU time.
 +May 18 13:43:46 octo systemd[1]: Starting HAProxy Load Balancer...
 +May 18 13:43:46 octo haproxy[16752]: [NOTICE]   (16752) : New worker #1 (16754) forked
 +May 18 13:43:46 octo systemd[1]: Started HAProxy Load Balancer.
 +(venv) octo@octo:~$
 +
 +</cli>
  
 +We should now be able to access the server on the standard port 80, i.e. no port specification required.
  
 ==== Setting up SSH access to your container ==== ==== Setting up SSH access to your container ====
projects/3dprint/octoprint.1684414281.txt.gz · Last modified: 2023/05/18 12:51 by jattie