我的轻量级 dart:io 基于web服务器看起来像这样:
import'dart:io'; void main(){ HttpServer.bind(InternetAddress.ANY_IP_V4,80).then((server){ server.listen((HttpRequest request) { // ... do stuff ... request.response.write('好吧,这是你的回应...'); request.response.close(); }); }); print(listing ....); }让我们启动它(在Ubuntu Server 1.04上) p>
$ nohup dart myServer.dart& 听音...一切都很不错。我可以退出我的壳,它继续服务。但是,如果出现了严重的错误 - 例如。抛出未处理的异常 - Dart进程关闭。
如有必要,任何建议如何监控Dart进程并重新启动它?我想我可以写一个简单的脚本,只是想知道是否有更好的/推荐的方法?
(通过 mod_dart 可能是一个选项 - 感觉像overkill虽然和当前版本不稳定。)
解决方案
/supervisord/rel =nofollow> supervisord/ Supervisor是一个客户端/服务器系统,允许其用户监视和控制类UNIX操作系统上的多个进程。
upstart.ubuntu/ Upstart是/ sbin / init守护程序的基于事件的替换,它在启动期间处理启动任务和服务,在关闭期间停止它们,并在系统运行时监视它们。
选择最符合您需求的工具,这些工具无论如何都可以在工具箱中使用。
My lightweight dart:io based web server pretty much looks like this:
import 'dart:io'; void main() { HttpServer.bind(InternetAddress.ANY_IP_V4, 80).then((server) { server.listen((HttpRequest request) { // ... do stuff... request.response.write('Alright, here is your response...'); request.response.close(); }); }); print("listing...."); }Let's launch it (on Ubuntu Server 1.04):
$ nohup dart myServer.dart & Listening...Everything looking good so far. I can exit my shell and it keeps serving. However, if something goes terribly wrong - e.g. an unhandled exception is thrown - the Dart process goes down.
Any recommendation how to monitor the Dart process and restart it if necessary? I guess I could write a simple script for that, just wondering if there's a better / recommended way?
(Hosting in Apache via mod_dart might be an option - feels like overkill though and current version is unstable.)
解决方案consider the following tools:
supervisord/ Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.
upstart.ubuntu/ Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.
choose the one that best meets your needs, these tools are great to have in your toolbox anyway
更多推荐
在服务器上监视并重新启动Dart进程
发布评论