How to restart a Linux Service (Daemon) with System Center 2012 Orchestrator

System Center 2012 Orchestrator provides strong support for the heterogeneous enterprise, as evidenced by one of the more common questions I have received lately:

Can I manage Linux / UNIX systems with Orchestrator?

The answer is definitely yes! The Run SSH Command activity in the System category supports automating a wide variety of administrative tasks on Linux and UNIX systems and makes parsing command output a very simple task (output is stored in a published data property called Execution Result). In this example, we will look at a sample runbook that will check the status of a Linux / UNIX service (daemon) and start the service if it is not already running.

Sample Runbook

The sample runbook we will walk through through is pictured here.

image

This could very easily be adapted to function as a recovery task for System Center 2012 Operations Manager by creating a monitoring runbook using the Monitor Alert activity that then calls this runbook.

Accepting Input

First, create two variables to hold the Username and Password provided by your Linux / UNIX administrator. Notice I selected the option to encrypt the password. This allows our Linux / UNIX administrator to supply an audited account with the necessary permissions so we do not even need to know what it is. Never created a variable? Find step-by-step help HERE.

image

The Initialize Data activity accepts three input parameters:

  • Service – The name of the linux / UNIX server (aka daemon). We are using the HTTP daemon in this example, which is httpd.
  • ComputerName – the name or IP address of the target Linux system
  • SSHPort – The listening port of the SSH daemon on the target system

image

Checking Service Status

To start the service, the Check Service Status activity is a renamed Run SSH Command activity from the System category in the Runbook Designer. The command to start a service in CentOS is “service <servicename> status”. For example, to start the httpd service, the command would be “service httpd status”.

The parameters of this activity are :

On the Details tab are the inputs to accept the desired computer, SSH listening port and service for which we want to check status (httpd in our example):

  • Computer: Published data {ComputerName from “Initialize Data”}
  • Port: Published data {SSHPort from “Initialize Data”}
  • Run Command: service {Service from “Initialize Data”} status

image

On the Advanced tab are the variables created containing the username and password for the target Linux / UNIX system:

  • Username: Variable {LinuxUser}
  • Password: Variable {LinuxPassword}

image

Branching Logic (Parsing Command Output)

The Run SSH Command activity includes a piece of published data named Execution Result, which contains the output of the command executed. In the case of the httpd service, a check of service status will return something like: “httpd service is running” or “httpd service is stopped”, depending on the current status of the service.

In this runbook, there are two branches which determine next step based on the results of the service status check.

The Service not running branch is triggered if the httpd service is not running

image

The Service already running branch is triggered if the httpd service is running

image

Starting the Service

To start the service, the Start Service activity is a renamed Run SSH Command activity from the System category in the Runbook Designer. The command to start a service in CentOS is “service <servicename> start”. For example, to start the httpd service, the command would be “service httpd start”.

The parameters of this activity are :

On the Details tab:

  • Computer: Published data {ComputerName from “Initialize Data”}
  • Port: Published data {SSHPort from “Initialize Data”}
  • Run Command: service {Service from “Initialize Data”} start

On the Advanced tab:

  • Username: Variable {LinuxUser}
  • Password: Variable {LinuxPassword}

You may notice the only difference between this and the Check Service Status activity above is the command we are running.

Event Logging

Log False Alarm is a renamed Send Event Log Message activity

image

Additional Reading

A more robust version of this runbook is available in our upcoming book, System Center 2012 Orchestrator Unleashed, due out in May 2013 from Sams Publishing. Order your advance copy at http://www.amazon.com/System-Center-2012-Orchestrator-Unleashed/dp/0672336103/ref=sr_1_1?ie=UTF8&qid=1364902553&sr=8-1&keywords=Orchestrator+Unleashed

2 thoughts on “How to restart a Linux Service (Daemon) with System Center 2012 Orchestrator

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.