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)?“.
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.
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.
Here is a combined list of instructions how to get all this to work, according to the decisions outlined in the discussion section:
- Download the Adobe AIR SDK to your server. Download the Adobe AIR SDK manuallyand upload to your server, or better use:
- Install Xvfb. On Ubuntu systems, install the packages xvfb and xauth for that.
- 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/;
- 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].
- Upload your AIR application to your server (just the .swf and .xml file in you project’s bin/ folder).
- Launch you application with xvfb-run:
xvfb-run -e log.txt --auth-file Xauth --server-num=99 adl Application-app.xml
- 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
- 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