Wednesday, August 11, 2010

Hudson, SmartFoxServer, Plink, and Running Command as Local System Account

SmartFoxServer is a platform for developing massively multi-user applications. SmartFoxServer is a Java application and supports calling extensions in Java, Action Script, and Python. As a Java application, SmartFoxServer runs well on Windows or Linux.

Ryzing tested running SmartFoxServer on Windows and Linux. We ended up using an Amazon EC2 instance running Ubuntu Linux to host the SmartFoxServer. SmartFoxServer interprets the Action Script extensions. You cannot compile the extensions. SmartFoxServer caches all the Action Script extensions. The server will not reload the extensions if they change. SmartFox developed an admin Flash client application to manage the SmartFoxServer. You can use the Flash admin client to force extensions to reload.

I designed the Hudson build process at Ryzing to push the SmartFoxServer extensions to the Linux server. Fortunately, SmartFox implemented a set of command line tools in addition to the Flash client. The process of pushing the extensions to the server is a simple task in Hudson.

  1. Extract the source from SVN
  2. Rename some files to match the destination server
  3. Push the sources to the server using PSCP
  4. Reset the SmartFoxServer

Pscp is an implementation of scp or secure copy that runs on Windows. Pscp is one of the tools included with Putty. The process should be simple. However, there is a problem. The first time Putty, Pscp, or Plink connects to a server, they cache the host key in the registry. You get something like the following.

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 hh:hh:hh:hh:hh:hh:hh:hh:hh:hh:hh:hh:hh:hh:hh:hh
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)

Putty, Pscp, and Plink support a batch option. With the batch option, if the host key is not in the registry cache Putty, Pscp, and Plink automatically exit. The problem is the registry cache is user specific. This causes a problem with Hudson installed as a service running on Windows. When installed as a service, Hudson runs as the Local System Account. Running Pscp as a task in a Hudson project will lock up waiting for the user to press "Y" or "N". If you add the option to run as batch, the command will always fail.

How do you install the host key in the registry for the Local System Account? I am sure there are other solutions. The one I found was to open a command prompt as the Local System Account. Unfortunately, this is not as simple as it sounds. I finally found the solution here: http://johnnycoder.com/blog/2008/11/10/run-cmdexe-as-local-system-account/.

The solution is to use psexec.exe, which is part of PsTools from SysInternals. Microsoft acquired Sysinternals in July 2006. The following opens a command prompt as the Local System Account.

psexec -i -s cmd.exe

After the command window opens, attempt to connect via Pscp or Plink. Answer "Y" to "Store key in cache?"

Now Hudson can copy the files from SVN to the Linux server and restart SmartFoxServer.

8 comments:

江仁趙雲虹昆 said...

上來打聲招呼,祝你一切平安!............................................................

佳張張張張燕張張張張張 said...

男女互悅,未必廝守終生,相愛就是美的。.................................................................

佳張張張張燕張張張張張 said...

做些小善事,說些愛的字句,世界更快樂。..................................................

靜蔡蔡蔡蔡怡 said...

培養健全孩子最好的方法是父母先成為健全的人。......................................................................

佳張張張張燕張張張張張 said...

好的部落格就要和好朋友分享--感謝分享..................................................

孫邦柔 said...

喜歡看大家的文章,祝你順心~^^

Steve said...

the other solution is to place the SSH fingerprint directly into the registry: [HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY\SshHostKeys]

Zazou said...

Just run psftp.exe in the Putty install directory.
Connect to the server, and answer Y to the question.
After this, the question is never ask again.