Articles

Running the Android Emulator as System Services with Daemontools


Daemontools is a great set of utilities designed to run your services supervised, and we learned how to install them in the previous article "Installing DaemonTools in Amazon Linux (or CentOS like OS)".

Today we are going to see how to use daemontools to run the official Google Android Emulator. This is really useful if you're setting up a development box for your "android devs", they can later on access one or more of these emulators via a VNC client, if you want to leave a VNC server running like X11VNC.

Each one of these android emulator instances will be run as a system service and will be monitored so they will be started at boot and restarted if they happen to crash.

First of all, we need to create the basic service structure for daemontools, like shown in the script below:

Then we fill in the contents for the file log/run. Notice that for running this emulator we created a special user named myemuuser, you can create one user per emulator instance, or perhaps just one to run all of them.

Now we are going to create the file run that will be used to start your emulator instance. You have to know the name of the AVD in advance, of course. Note how we add permissions on certain devices like /dev/dri, the /dev/kvm device, and the /dev/video0 device.

That's it! After you're done, you can move this directory to /service and daemontools will start everything for you.

Enjoy!