How to restart octoprint in Windows cleanly

What is the problem?
Safe mode when I start octoprint after an update, for example.

What did you already try to solve it?
I dont have a clue.

Logs (octoprint.log, serial.log or output on terminal tab at a minimum, browser error console if UI issue ... no logs, no support!)
I dont think the problem is so extensive that this needs to be provided.

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible)
win7
just upgraded from 1.3.12 to 1.4

Now what happens is I get SAFE mode, when I shutdown octoprint, and start it again.

As a result of above message I think my procedure for this is wrong, and need guidance on correct procedure.

Currently, I have no idea how to do a clean shutdown.
What I have been doing for all the years I have been using Octoprint in this win7 box, is to just kill the cmd box(big X), leaving the browser windows at 127.0.0.1:5000 open.
It usually moans that the server is offline

Double clicking the shortcut to start octoprint now causes the SAFE mode message.
127.0.0.1:5000 asks to RELOAD at this point.

What am I doing wrong.?

The Safe mode message does not happen every time I do the "restart" of octoprint, so
somewhat confused.

Please straighten me out.

If you please share logs, they come quite handy...

octoprint.log (202.3 KB)

All I am asking is how to RESTART octoprint in windows without SAFE mode appearing.

There is a reason it always starts in safe mode. It is to find out what it is and the logs can help.

So here is a error:

2020-04-02 09:07:55,654 - websocket - ERROR - error from callback <bound method TheSpaghettiDetectivePlugin.process_server_msg of <octoprint_thespaghettidetective_beta.TheSpaghettiDetectivePlugin object at 0x0406E170>>: process_server_msg() takes exactly 3 arguments (2 given)
2020-04-02 09:07:55,661 - websocket - ERROR - error from callback <bound method TheSpaghettiDetectivePlugin.process_server_msg of <octoprint_thespaghettidetective_beta.TheSpaghettiDetectivePlugin object at 0x0406E170>>: process_server_msg() takes exactly 3 arguments (2 given)

You may deactivate the spaghetti detective.

Also, clicking the close button is an effective approach to shutting down the OctoPrint instance. I personally use a batch script in the \OctoPrint\venv\Scripts\ folder named restart.bat with the following contents in it.

@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 in octoprint settings in the server section add the path to your batch file.

.

Ewald_Ikemann

You have put me in my place.
I bow to your correct analysis.

Issue is now gone.
And so is Spaghetti Detective.

1 Like

jneilliii

Thanks for the script.

This really completes things.

Nice and neat.

I can't take credit for this one. I found it somewhere here on the forum.

No worries. I had to learn it too.

Does that script work with multiple instances of Octoprint? I have 2 instances setup and when i try to restart the 2nd, it closes it and reopens the 1st, which doesn't help at all

Unfortunately, I don't think it will because the taskkill command does not know which exe it's killing. You can path the @start octoprint.exe serve >nul line to run the appropriate one, but still doesn't help with the stopping part.

So, I did some tinkering and I think I figured out how to get it to work with multiple instances. You have to full qualify the @start octoprint.exe serve >nul command. IDK if you set up your Windows Octoprint yourself, but if you didn't and you instead followed Chris Rileys youtube video like I did, then what I'm trying to say is, when he duplicated the original Octoprint instance and he modified the desktop shortcuts, you have to add all that info (so file location, ip & port, etc.) after the serve part of the command and it will make sure to start the correct instance. You may have to do the same thing (or something similar) for the "stop" portion as well

So, for me it looks like this:

@echo off
cls
if octoprint.==. goto error
taskkill /f /im octoprint.exe   > nul
timeout /t 3 /nobreak           > nul
start octoprint.exe serve --basedir "C:\Users\natha\AppData\Roaming\octoprint2" --host=192.168.1.22 --port=5001      > nul
echo restart complete
goto exit

:error
echo Oops... something went wrong!

:exit

Update: So, you definitely need to add some type of modifier to the taskkill command, as currently, if you have 2 instances running and you hit restart it shuts down both but only restarts the one that you chose to restart. I'm not entirely sure how to do it, as the modifier that I used for start did not work, it just gave me an error.

Alright, so I found something that works. Probably not the correct or most optimized, but it works.

So, for multiple instance you'll need to make a copy of the octoprint.exe file (I named it octoprint2.exe). You will also have to make sure you update the original instance file to point to this new file. Then, you have to update the taskkill command to match the correct instance. Finally, because starting octoprint.exe (or octoprint2.exe or whatever instance you are restarting) with the base directory, host, and port spelled out still wasn't loading things correctly, I instead rerouted it to just open up my shortcut links to my instances on the desktop, and that seems to work. I know that may be confusing as I I don't really know the correct lingo for this stuff, but this is what my 2 restart batch files look like.

Restart1.bat:

@echo off
cls
if octoprint.==. goto error
taskkill /f /im octoprint.exe   > nul
timeout /t 3 /nobreak           > nul
start C:\Users\natha\Desktop\octoprint1.lnk
echo restart complete
goto exit

:error
echo Oops... something went wrong!

:exit

Restart2.bat:

@echo off
cls
if octoprint.==. goto error
taskkill /f /im octoprint2.exe   > nul
timeout /t 3 /nobreak           > nul
start C:\Users\natha\Desktop\octoprint2.lnk
echo restart complete
goto exit

:error
echo Oops... something went wrong!

:exit

I hope this helps. Also, since I'm sure this isn't the most optimized of "clean" way to do this, I will try to revise it in the future, but it works for now and I have a few other things I'm still trying to figure out, so I'm gonna leave it here for now.

Also, I've been updating 2 different threads with this info (they're asking the same questions), and it's kinda getting old, so I'm only going to update the other thread which you can find here