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



RunsonComputeresourcestocheckthevirtualization  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 snmpdandsnmpdtrapservicesandrestarts 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

Recipe 5

Runs on Windows virtual servers to install Firefox web browser.

Virtual Server variable "VM_IDENTIFIER" is used in this example.

Step 1

# Silent Install Firefox 
# Download URL: https://www.mozilla.org/en-US/firefox/all/

# Path for the workdir
$workdir = "c:\installer-$env:VM_IDENTIFIER\"

# Check if work directory exists if not create it

If (Test-Path -Path $workdir -PathType Container)
{ Write-Host "$workdir already exists" -ForegroundColor Red}
ELSE
{ New-Item -Path $workdir  -ItemType directory }

# Download the installer


if ( $env:PROCESSOR_ARCHITECTURE -eq 'x86') {
	echo "Running 32-bit PowerShell"
	$source = "https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US"
}
else {
    echo "Running 64-bit PowerShell"
    $source = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-US"
}

$destination = "$workdir\firefox.exe"

# Check if Invoke-Webrequest exists otherwise execute WebClient

if (Get-Command 'Invoke-Webrequest')
{
     Invoke-WebRequest $source -OutFile $destination
}
else
{
    $WebClient = New-Object System.Net.WebClient
    $webclient.DownloadFile($source, $destination)
}

# Start the installation

Start-Process -FilePath "$workdir\firefox.exe" -ArgumentList "/S"

# Wait XX Seconds for the installation to finish

Start-Sleep -s 60

# Remove the installer

rm -Force $workdir\firefox*

Result source: Exit code

Pass values: 0

On success: Proceed

Fail values: Fail anything else

On failure: Fail