Thursday, December 30, 2021

Run 2 octoprint instances on one machine (1/?)

Earlier this year I decided that the Ender3 needed a friend, and since I really liked having a larger printer in the house when I borrowed the CR-10Pro last summer, I got a Tronxy X5SA-Pro.  It's 330x330x400, Core-XY and comes with a fancy touchscreen.  It also has wretched firmware that has a hard time remembering even simple settings, like Z offset.  Next chance I get I'm going to compile Marlin, but for now I'm muddling through with what's there - thanks to Octoprint.  The Ender has been connected to a Raspi4 running Octoprint almost since I bought it, so I can't deny Tronx the same pleasure, especially since the Raspi4 has more than enough power to run both printers and multiple cameras simultaneously.  Thomas Messmer put together a VERY detailed walk-through which was a huge help for me, though it's aged a bit and some of the information is now out of date.  Well, that's where this blog comes in.  Over the next few posts I'll take you through what's different and how to use his instructions with current versions of OctoPi and OctoPrint.  

First, we'll address the migration from init.d to systemd.  Sidestepping the controversy of systemd (like how I did that?) here's my reply to the most recent question, as of the end of December, 2021:

Once you have the second instance of Octoprint running, set up the second systemd file.  I'll copy mine below for reference:

  1. Copy /etc/systemd/system/octoprint.service to /etc/systemd/system/octoprint2.service
  2. In octoprint2.service, update variables "User", "Port", and "ExecStart".  Pick any unused port and that's what you'll put into haproxy later.
  3. Tell systemd to pick up the new script: "sudo systemctl daemon-reload"
  4. Activate it: "sudo systemctl enable octoprint2"
  5. Start it: "sudo systemctl start octoprint2"
  6. Debug and find your typos. 
After that, it should just work.  Future posts will cover:
  • Creating that second instance (though I'll be making minimal additions to the standard Linux instructions.)
  • Setting up haproxy
    • Bonus: I have DNS aliases for the Raspi so I can point a browser at ender.${my_domain} and tronxy.${my_domain} without having to remember what port they're using
    • I'm also using letsencrypt wildcards for ${my_domain} so the browsers are happy.
  • Nailing down the /dev entries so that Octoprint can find the printer and camera(s) it expects to.  This caused problems for me every time I rebooted the Raspi, or even if a USB cable got jiggled, so I'd like to save you the trouble. 
  • Anything else?  Let me know!

My octoprint2 service file:

$ cat /etc/systemd/system/octoprint2.service

[Unit]

Description=The snappy web interface for your 3D printer

After=network.online.target

Wants=network.online.target


[Service]

Environment="HOST=0.0.0.0"

Environment="PORT=5002"

Type=simple

User=octo2

ExecStart=/home/octo2/oprint/bin/octoprint serve --host=${HOST} --port=${PORT}


[Install]

WantedBy=multi-user.target


No comments:

Post a Comment