Task

I had to run existing ActionScript code on a headless Linux server and decided to do it by running an AIR application with the Xvfb virtual X server, as reasoned for in my article “How to run ActionScript in headless mode (on Linux without X server)?“.

Problem

I did not think that running an AIR application on a headless server would be that large a problem. Here is why it is:

  • The normal Adobe AIR 1.5 runtime installer is a GUI-based installer, no RPM oder DEB packages are available.
  • The normal process of installing an AIR application is also a GUI-based process, so not apt for a Linux headless server.
  • AIR applications itself are GUI-based, always needing an X server. See more on that in this article already linked above.

Discussion

In theory, installing the AIR 1.5 runtime and the AIR application would be possible via VNC or some Xvfb hacking to enable a remote desktop. In practice, I searched for a better solution.

There are two options; first, the headless installation of Adobe AIR 1.5 Runtime if you grab the version you get after applying to distribute AIR. Second, Adobe AIR 2.0 (in beta as of 2010-05-10) offers installation packages for various Linux systems. You can download Adobe AIR 2 Runtime beta Linux packages from Adobe labs. This enables headless installation with ease. The exception is if you are on a 64bit Linux system, in which case you need to follow along the well-done article “Install Adobe AIR 2 on 64-bit Linux distributions” from Adobe.

However, this approach faces another problem: AIR applications normally come in .air files, and these files cannot be installed on a headless server with a AIR Runtime – normally. The only exception is when using a special installer made available by Adobe after successfully applying for a AIR Runtime redistribution licence [source]. You can apply to distribute AIR (as already linked above). The bad thing is that, at least currently (2010-05-10), a redistribution installer is not available for Linux, and it is not allowed to modify another redistribution installer for that purpose; see the Adobe AIR Runtime distribution FAQ on “Can I distribute the Adobe AIR Runtime on an operating system if a version specific to that OS is not provided?“. So the “Adobe AIR Application Installer -silent file.air” option is not possible on Linux. (If you try that with the standard AIR installer, it says “install failed (see log)”, but even after enabling AIR logging, the log stays empty.)

The solution that I found is to deploy not the .air file but the .swf file and application .xml file that are generated during development in the bin/ output folder. These can be launched with the Adobe debug launcher (the adl command). And adl comes within the Adobe AIR SDK, which is installed by just unpacking, very apt for a headless server. Note: you do not need to install the Flex SDK also if you just want to run an AIR application this way.

By deploying the compiler output directly, we also get around the process of creating and signing the .air installation file. In case you need to do that anyway:

  • First try out the FlexBuilder integrated wizard along the Adobe instructions “Creating your first Flex AIR application in Flash Builder or Flex Builder: Package, sign, and run your AIR application“.
  • If that fails and you are given a strange error code, have a look at the ADT error messages.
  • If that didn’t help either, follow instead the Adobe instructions “Creating your first AIR application with the Flex SDK: Create the AIR installation file“. That finally worked for me.

The last problem is that running an AIR application on a headless server needs an X server in any case. We want to use the Xvfb virtual X server, as already reasoned for in my article “How to run ActionScript in headless mode (on Linux without X server)?“. Brett Adam designed and shared a simple Xvfb wrapper for running an AIR application with Xvfb. It turned out however that the program xvfb-run, coming with Xvfb at least in the Ubuntu 9.10 package, does exactly the same job and offers also more options; so we stick with that.

Solution

Here is a combined list of instructions how to get all this to work, according to the decisions outlined in the discussion section:

  1. Download the Adobe AIR SDK to your server. Download the Adobe AIR SDK manuallyand upload to your server, or better use:
    wget http://airdownload.adobe.com/air/lin/download/latest/AdobeAIRSDK.tbz2;
  2. Install Xvfb. On Ubuntu systems, install the packages xvfb and xauth for that.
  3. Install the Adobe AIR SDK on your server:
    mkdir /usr/local/share/applications/air-sdk-1.5;
    cd /usr/local/share/applications/air-sdk-1.5;
    tar xjvf AdobeAIRSDK.tbz2;
    ln -s /usr/local/share/applications/adobe-air-sdk-1.5/bin/adl /usr/local/bin/;
    ln -s /usr/local/share/applications/adobe-air-sdk-1.5/bin/adt /usr/local/bin/;
  4. Convert your Flash / Flex application (running in Flash player) to an AIR application, if necessary. This is no one-way road though, as you can re-use the code of your Flex based application as an AIR application and build them both in parallel from the same codebase; see Adobe’s article “Building web and Adobe AIR applications from a shared Flex code base” on that [here on archive.org; original link is gone].
  5. Upload your AIR application to your server (just the .swf and .xml file in you project’s bin/ folder).
  6. Launch you application with xvfb-run:
    xvfb-run -e log.txt --auth-file Xauth --server-num=99 adl Application-app.xml
  7. If you need to run your applications with arguments, do it like this:
    xvfb-run -e log.txt --auth-file Xauth --server-num=99 adl Application-app.xml -- --arg val
  8. If you need to keep Xvfb running (e.g. because you need to start the AIR application many times and want to get rid of the 3s delay to start Xvfb every time to improve performance), here is a technique for that. It is re-using xvfb-run, letting it run a command that never returns, and then lets other applications connect to the started X server:
    xvfb-run -e log.txt --auth-file Xauth --server-num=99 sleep 1000d &;
    DISPLAY=:99 XAUTHORITY=Xauth adl Application-app.xml -- --arg val

 

7 thoughts on “How to deploy an AIR application on a headless Linux server?

  1. Hi Matthias,
    thanks for that perfect Post! There wasn’t any problem for me getting to Step 5, but then I get an error, what seems like coming from xvfb:
    /usr/bin/xvfb-run: line 173: adl: File or Directory not found
    But its there, I even switched directly into the bin directory and I get the same error. Are there any other dependencies adl needs to be launched?

    Regards, Daniel

  2. xvfb-run expects the supplied command to be in your path, it seems. So even changing directory does not help.

    Try supplying the full path (startig with “/”) to the command instead of just “adl”.

    If that does not help, there might be a problem because some versions of AIR install ADL as adl_lin instead of just adl. For example, the AIR version that comes for Flex 3.5.

    In that case, you will need an additional

    ln -s /usr/local/share/applications/adobe-air-sdk-1.5/bin/adl_lin /usr/local/bin/;

    and then using adl_lin instead of just adl in the xvfb-run command.

  3. Dude. Holy shit. You’re the fucking MAN. Thank you for figuring this out, but even more so for posting it.

  4. Fantastic, thank you very much for this valuable info. Saved me a lot of trouble. Thank you! However, the symlink won’t be able to create the certificate, you have to specify the path to the adt binary!

  5. @aditya: Yes, redtamarin looks promising. Back then, I did an analysis of other options of running ActionScript serverside and passed Tamarin itself because fuctionality needed from libraries like Flash, Flex and AIR was not accessible. redtamarin does away with that restriction now it seems – thanks for the hint. However it seems (could not find out withcertainty at first glance) that redtamarin re-implements functionality equivalent to the Adobe libs but not necessarily completely compatible, so if your app depends on Flex / AIR libraries you’d have to adapt it.

  6. Correct. redtamarin does look promising, however at present, it lacks support for many flash player specific lib, which i also believe is a hard thing to implement entirely. i think at present, its taking most of it using avmglue. nonetheless, a very good initiative 🙂

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>