Recipe Use Examples

The set of examples aimed to illustrate the recipe utilization.

Recipe 1

Runs on VSs for Apache server installation and default web page configuration.

Can be used for the following events:

  • VS provisioning (starts Apache server during the VS creation)
  • Network rebuild
  • Network interface added

Consists of 5 steps. Each step depends on the previous step result.

Step 1

#if echo $OPERATING_SYSTEM_DISTRO |grep rhel ; then
  if rpm -qa |grep httpd |grep -v grep ; then
    yum -y update httpd
  else
    yum -y install httpd
  fi
#else
 # exit 1
#fi

Result source: Exit code

Pass values: 0

On success: Proceed

Fail values: Fail anything else

On failure: Fail

Step 2

 echo "<p><a href=http://$CP_ADDRESS>OnApp Cloud</a></p>" > /var/www/html/index.html

Result source: Exit code

Pass values: 0

On success: Go to step 5

Fail values: Fail anything else

On failure: Go to step 4

Step 3

 service httpd restart

Result source: Exit code

Pass values: 0

On success: Stop

Fail values: Fail anything else

On failure: Fail

Step 4

 echo "Can not write to file" > /var/log/recipes.log

Result source: Exit code

Pass values: 0

On success: Stop

Fail values: Fail anything else

On failure: Fail

Step 5

echo "<p><a href=http://$IP_ADDRESS>$HOSTNAME</a></p>" >> /var/www/html/index.html

Result source: Exit code

Pass values: 0

On success: Go to step 3

Fail values: Fail anything else

On failure: Go to step 4

Recipe 2

Runs on compute resources to check the virtualization  type.

Can be used for the following events:

  • When Xen/KVM compute resource goes online

Step 1

if rpm -qa |grep -q $qayd ; then
  ps aux |grep -q xend || exit 1
else
  ps aux |grep libvirtd || exit 1
fi

Result source: Exit code

Pass values: 0

On success: Proceed

Fail values: Fail anything else

On failure: Fail

Recipe 3

Runs on compute resources to check the snmpd and snmpdtrap services and restarts them.

Can be used for compute resource and control panel server events.

Step 1

service snmpd restart && service snmptrapd restart

Result source: Exit code

Pass values: 0

On success: Proceed

Fail values: Fail anything else

On failure: Fail

Recipe 4

Runs on Windows virtual servers to check if the Apache folder is present and deletes it, otherwise installs Apache.

Can be used for Windows virtual server events.

Step 1

$files = dir 'C:\Program Files (x86)\Apache*'
$process = "ApacheMonitor*"

if ($files -ne $null)
{
 "there's installed apache. Removing apache ..."
$installer = dir 'c:\apache.msi'
Stop-Process -Name $process
Start-Sleep -Second 5
Remove-Item $files -Force -Recurse
Remove-Item $installer -Force -Recurse
$files = dir 'C:\Program Files (x86)\Apache*'
 if ($files -ne $null)
  {
     "Failed to remove apache"
      return 1
   }  
  else 
   {
      "apache has  been removed"
       return 0
    }

}
else
{
"Apache has not been installed."
"Downloading installer.."

$client=New-Object System.Net.WebClient
$client.DownloadFile("http://mirrors.besplatnyeprogrammy.ru/apache//httpd/binaries/win32/httpd-2.0.64-win32-x86-no_ssl.msi", "c:\apache.msi")

"silence apache installation.."
 c:\apache.msi /quiet 

return 0
}

Result source: Exit code

Pass values: 0

On success: Proceed

Fail values: Fail anything else

On failure: Fail