在服务器上监视并重新启动Dart进程 [英] Monitor and restart Dart process on server

查看:279
本文介绍了在服务器上监视并重新启动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.org/rel =nofollow> http://supervisord.org/ Supervisor是一个客户端/服务器系统,允许其用户监视和控制类UNIX操作系统上的多个进程。


  • http://upstart.ubuntu.com/ 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:

    1. http://supervisord.org/ Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.

    2. http://upstart.ubuntu.com/ 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进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆