IgorShare Thoughts and Ideas

Consulting and Training

Controlling TopShelf via REST interface + Dashboard

Posted by Igor Moochnick on 04/11/2012

My recent update for the TopShelf enables the new Nancy-based REST interface and provides improvements to the current dashboard.

The new REST interface allows you to see what are the currently running services by sending a GET request to the dashboard URL (i.e. http://dasboard_url/services).

As a reply, you’re going to get a JSON block that contains small snippets of information about each seevice and shelf that is running inside the TopShelf process.

[...
   {
      "Name":"clock",
      "ServiceType":"Shelf",
      "CurrentState":"Running",
      "Action":"stop"
   }
...]

The most important piece of the block above is the URL-encoded Name of the service. You can use this name as an ID to control the service’s lifetime via HTTP GET requests, i.e.: start, stop, unload:

  • /service/{name}/start
  • /service/{name}/stop
  • /service/{name}/unload

The latest addition to the control interface is the ability to upload shelves remotely by uploading a ZIP file with all the relevant bits of your service.

You can do the upload via the dashboard by navigating to the ZIP package or by dragging and dropping the shelf archive onto a designated area.

In addition, you can do it programmatically via file upload POST request. This sounds complicated, but, in fact, if you’re using .Net framwork, it may look as simple as this:

using (WebClient client = new WebClient())
{
     client.UploadFile("http://localhost:8087/service/upload", @"C:\Packages\clock.zip");
}

All the above functionality can be configured and fine-tuned via the new optional configuration settings that you can put in the TopShelf host configuration file:

<appsettings>
	<add key="ServicesLocation" value="Services" />
	<add key="DashboardUri" value="http://localhost:8087" />
	<add key="DashboardUploadsEnable" value="true" />
	<add key="DashboardUploadsPackageFolder" value="Packages" />
</appsettings>

Here is a short explanation of the settings:

  • Services – contains a full or relative path of the shelves folder
  • DashboardUri – defines a Uri (ip and port) that the dashboard module (and REST web service) will use to listen to the incoming requests
  • DashboardUploadsEnable – this value controls if the uploads of the shelves are enabled (both through the dashboard and the REST service)
  • DashboardUploadsPackageFolder – defines a temporary location where the ZIP archives of the shelves will be stored before unpacked into the shelves location (defined by the Services setting)
Advertisements

2 Responses to “Controlling TopShelf via REST interface + Dashboard”

  1. Jeetendra Sharma said

    Hello,

    I download the code from your fork, but when I run build, getting ILMerge fail error , can you help me out

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: