在服务器上监视并重新启动Dart进程

编程入门 行业动态 更新时间:2024-10-23 07:16:38
本文介绍了在服务器上监视并重新启动Dart进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的轻量级 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进程

    本文发布于:2023-06-10 22:54:13,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/620821.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:重新启动   进程   器上   Dart

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!