jansmolders86 / mediacenterjs

A HTML/CSS/Javascript (NodeJS) based Media center
http://mediacenterjs.com
1.29k stars 243 forks source link

Automatic update potentially destroys installation #124

Closed TheBenji closed 8 years ago

TheBenji commented 10 years ago

While it was updating my internet connection broke down, afterwards I couldn't start the server anymore because it threw some error.

Had to go manually for an "npm install" before I could use it again.

jansmolders86 commented 10 years ago

Hej There Benji,

What a great bugfind! That will a very hard issue to fix but I have some ideas how I could tackle this issue. when the update starts a file is created. A sort of maintenance flag. This "flag" gets deleted when the update is complete. I think I could and a check that restarts the update process if the server starts when the flag is still present.

What do you think of this approach?

Thanks again for your extensive testing!

TheBenji commented 10 years ago

That sounds like a good idea and should cover the most cases.

Another approach could be to save the current working version and just roll it back on an error. Obviously that would slow down the whole update process a little and is a bit more work but it would make sure you don't get caught in an endless "update loop" and no matter what you still have a working version at the end. Thinking about some (new) modules that throw an error just on windows 8 at midnight while full-moon or something like that.

What do you think?

jansmolders86 commented 10 years ago

Well first of all, naturally it is never a good idea to use Windows 8 during a full moon. That being said I like your approach more but it might be more complicated to catch all error events. With that I mean that if an exception is thrown, if might be difficult to recover the backup or the backup might even be corrupt.

I believe there no perfect solution. Just like you shouldn't shut down your computer when it is updating the OS. But I do think some additional error handling would do wonders. (eg, if the download fails or is corrupt, don't continue the update process, delete the downloaded file(s) and prompt the use another time to try again).

Do you agree?

TheBenji commented 10 years ago

Yeah, your suggestion sounds good, it basically does the same just better (update fails for some reason→ use old version).

But in my case it failed while downloading/updating the node_modules cause my internet connection failed (I'd guess that could be a quite common problem :D ) so I believe it's really hard (to impossible) to catch that and just delete the new downloaded files...

An easy way could be git as "backup" solution. Just commit the whole folder before you do an update and if the restart fails for any reason checkout the last commit, restart again and prompt the user like you said to just try it again.

But like you said, there is probably no perfect solution so it's at the end really up to you, especially if you consider how often that could happen (barely)...

hoffi commented 10 years ago

hm basically i like the idea of git as backup, but i think it is a bit of an overhead just for that. The simplest solution would be to create a complete copy of all files before downloading the new version or create an zip archive (that would safe some disk space requirement) of it and put it somewhere safe, when at any stage of the update process something went wrong just completely restore the backup copy.

BTW: By mentioning disk space i remembered something. When starting update do we check if the system has enough free disk space for the new version (+ backup maybe)?