Monitor and restart Dart process on server

旧巷老猫 提交于 2019-12-09 23:17:59

问题


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.)


回答1:


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




回答2:


I use Monit on my GCE Debian instance, easy to setup and a nice little web interface for easier management.



来源:https://stackoverflow.com/questions/19896836/monitor-and-restart-dart-process-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!