如何创建一个自我更新的Node.js应用程序? [英] How to create a self-updating Node.js application?
问题描述
我想用Node.js创建一个应用程序,该应用程序会定期检查更新并安装更新(如果有的话).
I'd like to create an application with Node.js that periodically checks for updates and installs them if there are any.
基本组件对我来说很清楚:
The basic components are clear to me:
- 包含更新程序包的Web服务器(或FTP服务器,文件系统等)
- 一个版本系统(例如SemVer),以便您可以判断哪个软件包是较新的
- 用于签名更新程序包的公钥算法
然后,何时检查更新和安装更新可能有不同的策略:
Then, there may be different strategies on when to check for updates and install updates:
- 启动应用程序
- 在应用程序结束时
- 闲置时
该应用程序甚至可能被硬关闭并自动重新启动.
The application may even be shut down hard and restarted automatically.
但是还有一些问题:
- npm上是否有任何模块已经提供了这样的系统?
- 如何在文件系统中组织不同的版本?基本上,您将拥有一个主机和多个(版本化)内核.所有的文件夹都应该有一个
data
文件夹吗? - 如何处理
npm install
&公司新下载的软件包? - 如何处理损坏的更新?
- 如何实现与Heroku&兼容的东西?公司没有永久性驱动器的地方?
- Is there any module on npm available that already provides such a system?
- How to organize the different versions in the file system? Basically you'd have a host and multiple (versioned) cores. Should there be one
data
folder for all of them? - How to deal with
npm install
& co. for newly downloaded packages? - How to deal with broken updates?
- How could you implement such a thing so that it's compatible to Heroku & co. where you don't have a permanent drive that you can drive to?
通常:您将如何实现这样的系统?
In general: How would you try to achieve a system like this?
推荐答案
首先,您可以将NPM本身用于打包和应用交付.其次,您可以添加一个脚本文件,以便在package.json文件(例如"postinstall"或"update")中添加cron作业,以进行定期更新.在此脚本中,您可以检查所有需要的内容,如损坏的更新.在Heroku中,您可以使用Scheduler Worker进行更新处理.
First, you could use NPM itself for package and app delivery. Second, you could add a script file to add a cron job in the package.json file (e.g. 'postinstall' or 'update') for a periodic update process. In this script you could check all you need like broken updates. In Heroku you can use a Scheduler Worker for update processing.
这篇关于如何创建一个自我更新的Node.js应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!