Merge "Add Linux Apache and Telnet services"

This commit is contained in:
Jenkins 2013-11-14 13:02:13 +00:00 committed by Gerrit Code Review
commit 4c1c44f1b5
11 changed files with 826 additions and 0 deletions

View File

@ -0,0 +1,21 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy Apache
Parameters:
enablePHP: $enablePHP
Body: |
return apacheDeploy('{0}'.format(args.enablePHP)).stdout
Scripts:
apacheDeploy:
Type: Application
Version: 1.0.0
EntryPoint: Linux/runApacheDeploy.sh
Files:
- Linux/installer.sh
- Linux/common.sh
Options:
captureStdout: true
captureStderr: true

View File

@ -0,0 +1,22 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy Telnet
Parameters:
appName: $appName
Body: |
return telnetDeploy(args.appName).stdout
Scripts:
telnetDeploy:
Type: Application
Version: 1.0.0
EntryPoint: Linux/runTelnetDeploy.sh
Files:
- Linux/installer.sh
- Linux/common.sh
Options:
captureStdout: true
captureStderr: false

View File

@ -0,0 +1,29 @@
version: 0.1
service_display_name: Apache Service
description: >-
<strong> Linux Apache Service </strong>
Demonstrates a simple linux agent, which installs Apache Server
full_service_name: linuxApacheService
author: Mirantis Inc.
service_version: 1.0
enabled: True
ui:
- LinuxApache.yaml
workflows:
- Apache.xml
heat:
- Linux.template
- ApacheSecurity.template
agent:
- DeployApache.template
scripts:
- Linux/common.sh
- Linux/installer.sh
- Linux/runApacheDeploy.sh

View File

@ -0,0 +1,29 @@
{
"Resources": {
"$port-{instanceName}": {
"Properties": {
"security_groups" : [ {"Ref" : "ApacheSecurityGroup"} ]
}
},
"ApacheSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"SecurityGroupIngress": [
{
"ToPort": "80",
"IpProtocol": "tcp",
"FromPort": "80",
"CidrIp": "0.0.0.0/0"
},
{
"ToPort": "433",
"IpProtocol": "tcp",
"FromPort": "433",
"CidrIp": "0.0.0.0/0"
}
],
"GroupDescription": "Enable access to HTTP and HTTPS protocols"
}
}
}
}

View File

@ -0,0 +1,204 @@
#!/bin/bash
#
DEBUGLVL=3
LOGFILE=/tmp/muranodeployment.log
PIPAPPS="pip python-pip pip-python"
PIPCMD=""
if [ "$DEBUGLVL" -eq 4 ]; then
set -x
fi
function log {
if [ "$DEBUGLVL" -gt 0 ]; then
chars=$(echo "@$" | wc -c)
case $DEBUGLVL in
1 )
echo -e "LOG:>$@"
;;
2)
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" | tee --append $LOGFILE
;;
3)
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" >> $LOGFILE
;;
4)
echo -e "$(date +"%m-%d-%Y %H:%M") LOG:>$@" | tee --append $LOGFILE
;;
esac
fi
}
function lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}
function find_pip()
{
for cmd in $PIPAPPS
do
_cmd=$(which $cmd 2>/dev/null)
if [ $? -eq 0 ];then
break
fi
done
if [ -z $_cmd ];then
echo "Can't find \"pip\" in system, please install it first, exiting!"
exit 1
else
PIPCMD=$_cmd
fi
}
OPTIND=1 # Reset if getopts used previously
function collect_args(){
_n=$1
shift
ARGS=''
while true
do
if [[ "$_n" == -* ]] || [ -z "$_n" ]; then
OPTIND=$((OPTIND - 1))
break
fi
#echo "_n=$_n ; $OPTIND"
if [ -z "$ARGS" ]; then
ARGS=$OPTARG
else
ARGS="$ARGS $_n"
fi
eval _n=\$$OPTIND
OPTIND=$((OPTIND + 1))
#sleep 1
done
echo $ARGS
unset _n
unset ARGS
}
function get_os(){
KERNEL=$(uname -r)
MACH=$(uname -m)
OS=$(uname)
if [ "${OS}" = "Linux" ] ; then
if [ -f /etc/redhat-release ] ; then
DistroBasedOn='RedHat'
Packager='yum'
DIST=$(cat /etc/redhat-release |sed s/\ release.*//)
PSUEDONAME=$(cat /etc/redhat-release | sed s/.*\(// | sed s/\)//)
REV=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//)
elif [ -f /etc/SuSE-release ] ; then
DistroBasedOn='SuSe'
Packager='zypper'
PSUEDONAME=$(cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//)
REV=$(cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //)
elif [ -f /etc/mandrake-release ] ; then
DistroBasedOn='Mandrake'
Packager='urpmi urpme'
PSUEDONAME=$(cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//)
REV=$(cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//)
elif [ -f /etc/debian_version ] ; then
DistroBasedOn='Debian'
Packager='apt-get'
DIST=$(cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }')
PSUEDONAME=$(cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }')
REV=$(cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }')
fi
if [ -f /etc/UnitedLinux-release ] ; then
DIST="${DIST}[$(cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//)]"
fi
OS=$(lowercase $OS)
DistroBasedOn=$(lowercase $DistroBasedOn)
readonly OS
readonly DIST
readonly DistroBasedOn
readonly PSUEDONAME
readonly REV
readonly KERNEL
readonly MACH
#readonly Packager
else
OS=unknown
readonly OS
log "OS:$OS"
exit 1
fi
}
function add_fw_rule(){
_rule_string=$@
_tmp_fw_port=$(echo $_rule_string | grep -o -e "dport [0-9]*\s")
_tmp_fw_proto=$(echo $_rule_string | grep -o -e "-p \w*\s")
_fw_port=$(echo $_tmp_fw_port | awk '{print $2}')
_fw_proto=$(echo $_tmp_fw_proto |awk '{print $2}')
_fw_reload=""
#find iptables and add rule
case $DIST in
"Fedora")
_fw_cmd=$(which firewall-cmd)
_fw_port=$(echo $_rule_string | grep -o -e "dport [0-9]*\s" | awk '{print $2}')
_fw_proto=$(echo $_rule_string | grep -o -e "-p \w*\s" | awk '{print $2}')
_fw_rule="--permanent --add-port=$_fw_port/$_fw_proto"
_fw_enable_rules="$_fw_cmd --reload"
;;
*)
_fw_cmd=$(which iptables)
_fw_rule=$_rule_string
_fw_enable_rules="service $_fw_cmd save"
;;
esac
iptcmdsave=$(which iptables-save)
if [[ "$_fw_cmd" != '' ]] && [[ "$iptcmdsave" != '' ]]; then
eval "$iptcmdsave | grep -e \"$_tmp_fw_port\" | grep -e \"$_tmp_fw_proto\"" > /dev/null 2>&1
if [ $? -ne 0 ]; then
eval $_fw_cmd $_fw_rule
if [ $? -ne 0 ]; then
log "Can't set firewall rules, exiting..."
exit 1
else
if [ -n "$_fw_enable_rules" ]; then
log "Running \"$_fw_enable_rules\""
$_fw_enable_rules > /dev/null
fi
log "$_fw_cmd rule with $_fw_rule set."
fi
else
log "$_fw_cmd rule exists."
fi
else
log "There are no fw found..."
fi
}
function enable_init(){
_initctrl=""
_init_suffix=""
_service=$1
case $DistroBasedOn in
"debian")
_initctrl="update-rc.d"
_init_suffix="defaults"
;;
*)
_initctrl="chkconfig"
_init_suffix="on"
;;
esac
$_initctrl $_service $_init_suffix
if [ $? -ne 0 ]; then
log "$_initctrl $_service $_init_suffix - fails!"
exit 1
fi
}
function restart_service(){
_service=$1
service $_service restart > /dev/null 2>&1
if [ $? -ne 0 ]; then
log "Can't start $_service service!"
exit 1
fi
}
function package_renamer(){
_pkg=$1
case $DistroBasedOn in
"debian")
_pkg=$(echo $_pkg | sed 's/-devel$/-dev/')
;;
*)
_pkg=$(echo $_pkg | sed 's/-dev$/-devel/')
;;
esac
echo $_pkg
}

View File

@ -0,0 +1,142 @@
#!/bin/bash
#
INSTALLER_OPTS=""
UNINSTALLER_OPTS=""
PMGR=""
PMGR_LIST_OPTS=""
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
exit 1
fi
}
function set_install_options(){
case $1 in
apt-get )
INSTALLER_OPTS="-y -q install"
UNINSTALLER_OPTS="-y -q remove"
PMGR="dpkg"
PMGR_LIST_OPTS="-s"
;;
yum )
INSTALLER_OPTS="--assumeyes install"
UNINSTALLER_OPTS="--assumeyes erase"
PMGR="rpm"
PMGR_LIST_OPTS="-q"
;;
urpm* )
INSTALLER_OPTS="-y"
UNINSTALLER_OPTS=""
PMGR="rpm"
PMGR_LIST_OPTS="-q"
;;
zypper )
INSTALLER_OPTS="install"
UNINSTALLER_OPTS="remove --quiet"
PMGR="rpm"
PMGR_LIST_OPTS="-q"
;;
pip )
INSTALLER_OPTS="install"
UNINSTALLER_OPTS="uninstall --yes"
find_pip
PACKAGER=$PIPCMD
PMGR=$PIPCMD
PMGR_LIST_OPTS="freeze | grep"
;;
* )
exit 1
;;
esac
PACKAGER=$(which $1)
if [ $? -ne 0 ]; then
log "Can't find \"$1\", exiting!"
exit 1
fi
}
function package_install(){
PKG=$1
eval "$PMGR $PMGR_LIST_OPTS $PKG" > /dev/null 2>&1
if [ $? -eq 0 ]; then
log "\"$PKG\" already installed"
else
log "Installing \"$PKG\" ..."
$PACKAGER $INSTALLER_OPTS $PKG > /dev/null 2>&1
if [ $? -ne 0 ]; then
log "\"$PKG\" installation fails, exiting!"
exit 1
else
log "\t\t...success"
fi
fi
}
function package_uninstall(){
PKG=$1
eval "$PMGR $PMGR_LIST_OPTS $PKG" > /dev/null 2>&1
if [ $? -eq 1 ]; then
log "\"$PKG\" not installed"
else
log "Unnstalling \"$PKG\" ..."
$PACKAGER $UNINSTALLER_OPTS $PKG > /dev/null 2>&1
if [ $? -ne 0 ]; then
log "\"$PKG\" uninstallation fails, exiting!"
exit 1
else
log "\t\t...success"
fi
fi
}
function run_install(){
for PKG in $@
do
package_install $PKG
done
}
function run_uninstall(){
for PKG in $@
do
package_uninstall $PKG
done
}
# Main workflow
include "common.sh"
if [ $# -eq 0 ]; then
script=$(basename $0)
echo -e "Usage:\n\t* install packages -- ./$script -p package_manager -i package0 [packageN]\n\t* remove packages -- ./$script -p package_manager -r package0 [packageN]"
exit 1
fi
Packager=''
get_os
if [ $? -ne 0 ]; then
log "Unsupported *nix version ($DistroBasedOn - $DIST/$PSUEDONAME/$REV/$MACH)"
exit 1
fi
while getopts ":p:i:r:" opt ; do
case "$opt" in
p)
if [[ "$OPTARG" != sys ]]; then
Packager=$OPTARG
fi
set_install_options $Packager
;;
i)
n=$OPTARG
run_install $(collect_args $n $@)
break;
;;
r)
n=$OPTARG
run_uninstall $(collect_args $n $@)
break;
;;
\?)
log "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))

View File

@ -0,0 +1,37 @@
#!/bin/bash
#
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
echo -e "$inc_file_path not found!"
exit 1
fi
}
include "common.sh"
# FirewallRules
FW_RULE1='-I INPUT 1 -p tcp -m tcp --dport 443 -j ACCEPT -m comment --comment "by murano, Apache server access on HTTPS port 443"'
FW_RULE2='-I INPUT 1 -p tcp -m tcp --dport 80 -j ACCEPT -m comment --comment "by murano, Apache server access on HTTP port 80"'
APP=''
get_os
[[ $? -ne 0 ]] && exit 1
case $DistroBasedOn in
"debian")
APP="apache2"
;;
"redhat")
APP="httpd"
;;
esac
_php=""
if [[ "$1" == "True" ]]; then
_php="php"
fi
APPS_TO_INSTALL="$APP $_php $FW_BOOT_PKG"
bash installer.sh -p sys -i $APPS_TO_INSTALL
enable_init $APP
service $APP start > /dev/null 2>&1
add_fw_rule $FW_RULE1
add_fw_rule $FW_RULE2

View File

@ -0,0 +1,63 @@
#!/bin/bash
#
function include(){
curr_dir=$(cd $(dirname "$0") && pwd)
inc_file_path=$curr_dir/$1
if [ -f "$inc_file_path" ]; then
. $inc_file_path
else
echo -e "$inc_file_path not found!"
exit 1
fi
}
include "common.sh"
# FirewallRules
FW_RULE1='-I INPUT 1 -p tcp -m tcp --dport 23 -j ACCEPT -m comment --comment "by murano, Telnet server access on port 23"'
APP=''
get_os
[[ $? -ne 0 ]] && exit 1
case $DistroBasedOn in
"debian")
APP="telnetd"
;;
"redhat")
APP="telnet-server"
;;
esac
APPS_TO_INSTALL="$APP"
bash installer.sh -p sys -i $APPS_TO_INSTALL
xinetd_tlnt_cfg="/etc/xinetd.d/telnet"
if [ -f "$xinetd_tlnt_cfg" ]; then
sed -i '/disable.*=/ s/yes/no/' $xinetd_tlnt_cfg
if [ $? -ne 0 ]; then
log "can't modify $xinetd_tlnt_cfg"
exit 1
fi
else
log "$APP startup config not found under $xinetd_tlnt_cfg"
fi
#security tty for telnet
setty=/etc/securetty
lines=$(sed -ne '/^pts\/[0-9]/,/^pts\/[0-9]/ =' $setty)
if [ -z "$lines" ]; then
cat >> $setty << "EOF"
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9
EOF
if [ $? -ne 0 ]; then
log "Error occured during $setty changing..."
exit 1
fi
else
echo "$setty has pts/0-9 options..."
fi
restart_service xinetd
add_fw_rule $FW_RULE1

View File

@ -0,0 +1,28 @@
version: 0.1
service_display_name: Linux Telnet Service
description: >-
<strong> Linux Telnet Service </strong>
Demonstrates a simple linux agent, which installs Telnet if required.
full_service_name: linuxTelnetService
author: Mirantis Inc.
service_version: 1.0
enabled: True
ui:
- LinuxTelnet.yaml
workflows:
- LinuxTelnet.xml
heat:
- Linux.template
agent:
- DeployTelnet.template
scripts:
- Linux/common.sh
- Linux/installer.sh
- Linux/runTelnetDeploy.sh

View File

@ -0,0 +1,86 @@
name: Apache Service
type: linuxApacheService
description: >-
<strong> Linux Apache Service </strong>
Demonstrates a simple linux agent, which installs Apache Server
unitTemplates:
- {}
forms:
- serviceConfiguration:
fields:
- name: title
type: string
required: false
hidden: true
attributeNames: false
description: Apach service installs Apache HTTP Server
- name: name
type: string
label: Service Name
description: >-
Enter a desired name for a service. Just A-Z, a-z, 0-9, dash and
underline are allowed.
minLength: 2
maxLength: 64
regexpValidator: '^[-\w]+$'
errorMessages:
invalid: Just letters, numbers, underscores and hyphens are allowed.
helpText: Just letters, numbers, underscores and hyphens are allowed.
- name: dcInstances
type: instance
hidden: true
attributeNames: units
initial: 1
- name: deployApache
type: boolean
label: Deploy Apache
description: >-
Indicates if the target machine has to get Apache deployed
initial: true
required: false
widgetMedia:
css: {all: [muranodashboard/css/checkbox.css]}
- name: unitNamingPattern
type: string
label: Hostname
description: >-
For your convenience instance hostname can be specified.
Enter a name or leave blank for random name generation.
required: false
regexpValidator: '^(([a-zA-Z0-9#][a-zA-Z0-9-#]*[a-zA-Z0-9#])\.)*([A-Za-z0-9#]|[A-Za-z0-9#][A-Za-z0-9-#]*[A-Za-z0-9#])$'
helpText: Optional field for a machine hostname
# temporaryHack
widgetMedia:
js: [muranodashboard/js/support_placeholder.js]
css: {all: [muranodashboard/css/support_placeholder.css]}
- instanceConfiguration:
fields:
- name: title
type: string
required: false
hidden: true
attributeNames: false
descriptionTitle: Instance Configuration
description: Specify some instance parameters on which service would be created.
- name: flavor
type: flavor
label: Instance flavor
description: >-
Select registered in Openstack flavor. Consider that service performance
depends on this parameter.
required: false
- name: osImage
type: image
imageType: linux
label: Instance image
description: >-
Select valid image for a service. Image should already be prepared and
registered in glance.
- name: availabilityZone
type: azone
label: Availability zone
description: Select availability zone where service would be installed.
required: false

View File

@ -0,0 +1,165 @@
<workflow>
<!-- Provisioning rules -->
<rule match="$.services[?(@.type == 'linuxApacheService')].units[?(@.state.hostname and not @.temp.instanceName)]"
desc="Units of Linux Telnet service having hostname and image names assigned but without instances">
<report entity="unit">
<parameter name="id"><select path="id"/></parameter>
<parameter name="text">
Creating Linux instance <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
<!-- HEAT rules defenitions -->
<!-- Rule #1 -->
<update-cf-stack template="Linux" error="exception">
<parameter name="mappings">
<map>
<mapping name="instanceName">
<select path="state.hostname"/>
</mapping>
<mapping name="instancePort">
port-<select path="state.hostname"/>
</mapping>
<mapping name="networkName">
network-<select path="/id"/>
</mapping>
<mapping name="userData">
<prepare-user-data template="Linux" initFile="linux_init.sh">
<parameter name="hostname">
<select path="state.hostname"/>
</parameter>
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
</prepare-user-data>
</mapping>
<mapping name="instanceType">
<select path="::flavor" default="m1.medium"/>
</mapping>
<mapping name="imageName">
<select path="::osImage.name"/>
</mapping>
<mapping name="availabilityZone">
<select path="::availabilityZone" default="nova"/>
</mapping>
</map>
</parameter>
<success>
<set path="temp.instanceName">
<select path="name"/>
</set>
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Linux instance <select path="state.hostname"/> (<select path="name"/>) created
</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Unable to deploy Linux instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/>
</parameter>
</report>
<stop/>
</failure>
</update-cf-stack>
<!-- Rule #2 -->
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Configuring security groups on <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
<update-cf-stack template="ApacheSecurity" error="exception">
<parameter name="mappings">
<map>
<mapping name="instanceName">
<select path="state.hostname"/>
</mapping>
</map>
</parameter>
<success>
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Security groups configuration on instance <select path="state.hostname"/> (<select path="name"/>) is successful
</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Unable to configure security groups on instance <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/>
</parameter>
</report>
<stop/>
</failure>
</update-cf-stack>
</rule>
<!-- Agent rules -->
<rule match="$.services[?(@.type == 'linuxApacheService')].units[?(@.temp.instanceName and not @.state.ApacheInstalled)]"
desc="Units of Linux Apache service which have got an instance deployed but have not got Apache service installed">
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
insatalling Apache on unit <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
<!-- Commands sequence -->
<!-- Command #1-->
<send-command template="DeployApache" error='exception'>
<parameter name="unit">
<select path="id"/>
</parameter>
<parameter name="service">
<select path="::id"/>
</parameter>
<parameter name="mappings">
<map>
<mapping name="deployApachePHP">
<select path="::deployApachePHP"/>
</mapping>
</map>
</parameter>
<success>
<set path="state.ApacheInstalled"><true/></set>
<report entity="unit">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Apache deployed on <select path="state.hostname"/> (<select path="name"/>)
</parameter>
</report>
</success>
<failure>
<report entity="unit" level="error">
<parameter name="id">
<select path="id"/>
</parameter>
<parameter name="text">
Unable to deploy Apache on <select path="state.hostname"/> (<select path="name"/>) due to <format-error error="exception"/>
</parameter>
</report>
<stop/>
</failure>
</send-command>
</rule>
</workflow>