Question

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

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top