Octoprint Windows Restart


#1

Hi all,

First time posting, so hopefully this is in the right place!

Wasn't sure where to post this, but thought it might be useful to someone! I've recently moved from my underpowered RPi B+ to an intel nuc running windows instead, but couldn't find an easy way to issue a "Reset command" soooo... incase anyone in the same situ as I was, please see my solution below;

Create a .bat file inside of the octoprint server folder - mine's located at "C:\OctoPrint\venv\Scripts"

I called the file "Reset.bat" open it and enter the code below;

@if octoprint.==. (goto error) ELSE (goto restart)

:restart
@taskkill /f /im octoprint.exe >nul
@timeout /t 3 /nobreak >nul
@start octoprint.exe serve >nul
@echo restart complete
@goto exit

:error
@echo Oops... something went wrong!
@goto exit

:exit

Then hit save.

Then on octoprint settings, go to "Server" and paste the location of the reset file into the restart octoprint box - mine was " "C:\OctoPrint\venv\Scripts\Restart.bat" " (I'm not sure if the " " around the command is needed, but it seems to work with it there... sooo i've left it.)

Sidenote, my script may be wrong in places, i'm not versed in bat script, just something that I found on the internet and adapted for this. Any potential fixes or something similar, please post below and i'll update the code accodingly. :slight_smile:

Hope this helps someone!


#2

Why all the @ symbols?

I think I'd just do an @echo off at the beginning if you don't want command echoing.

Secondly, the ELSE (goto restart) and the parentheses to its left are unnecessary. Program flow should just go to the next line and continue.

@echo off
cls
if octoprint.==. goto error
taskkill /f /im octoprint.exe   > nul
timeout /t 3 /nobreak           > nul
start octoprint.exe serve       > nul
echo restart complete
goto exit

:error
echo Oops... something went wrong!

:exit