Auto-updating web service in Dart

Felix Blaschke
2 min readApr 20, 2021

Recently I did some experiments with Dart. I wanted to have a HTTP server that can provide frontend code and some simple backend logic. Everything should run on a virtual private server (v-server).

The clue is: I want it to auto-update / redeploy it automatically whenever I push something into my Git repository. And it should do the job without any complex CI pipeline. Here are my results.

My approach is writing a pure Dart application. It creates a HTTP server. For that I used Alfred because it’s so incredibly simple to use:

This will boot up a Dart-powered HTTP service providing all files in the public directory.

Then I utilized a Timer that will periodically try to git pull something. That’s quite easy to do in Dart:

Whenever it detects an update, it closes the application. Now we just need a mechanism to restart the app automatically. At this point a Linux systemd service comes handy:

It always ensures my Dart backend is running. (Keep in mind that this example service config isn’t perfect because it uses root user)

If you want to try it out yourself. Here are the steps to do:

  • Write your own HTTP service with Dart and Alfred (or any other package) and use the code above. Commit and push everything to a Git repository.
  • If you are new to v-server I recommend using Ubuntu or any Debian based Linux distributions. There is a lot of documentation for these.

Do the next steps on your virtual server:

  • Make sure to have Git installed and authed to your Git provider account
  • Install the Dart SDK
  • Clone your git repository on your v-server
  • Configure your systemd service (Tutorial)
  • Have fun :-)

This is just one approach on doing that. Maybe you know other solutions? Feel free to post it in the comments.

Until next time
— Felix —

--

--