diff --git a/muranorepository/Services/agent_templates/DeployApache.template b/muranorepository/Services/agent_templates/DeployApache.template new file mode 100644 index 0000000..bf55e5c --- /dev/null +++ b/muranorepository/Services/agent_templates/DeployApache.template @@ -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 diff --git a/muranorepository/Services/agent_templates/DeployTelnet.template b/muranorepository/Services/agent_templates/DeployTelnet.template new file mode 100644 index 0000000..1a4b014 --- /dev/null +++ b/muranorepository/Services/agent_templates/DeployTelnet.template @@ -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 diff --git a/muranorepository/Services/apache-manifest.yaml b/muranorepository/Services/apache-manifest.yaml new file mode 100644 index 0000000..00ddfe7 --- /dev/null +++ b/muranorepository/Services/apache-manifest.yaml @@ -0,0 +1,29 @@ +version: 0.1 +service_display_name: Apache Service + +description: >- + Linux Apache Service + 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 diff --git a/muranorepository/Services/heat_templates/ApacheSecurity.template b/muranorepository/Services/heat_templates/ApacheSecurity.template new file mode 100644 index 0000000..7a35b2d --- /dev/null +++ b/muranorepository/Services/heat_templates/ApacheSecurity.template @@ -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" + } + } + } +} \ No newline at end of file diff --git a/muranorepository/Services/scripts/Linux/common.sh b/muranorepository/Services/scripts/Linux/common.sh new file mode 100644 index 0000000..f7b7ac3 --- /dev/null +++ b/muranorepository/Services/scripts/Linux/common.sh @@ -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 +} \ No newline at end of file diff --git a/muranorepository/Services/scripts/Linux/installer.sh b/muranorepository/Services/scripts/Linux/installer.sh new file mode 100644 index 0000000..9d4baa5 --- /dev/null +++ b/muranorepository/Services/scripts/Linux/installer.sh @@ -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)) \ No newline at end of file diff --git a/muranorepository/Services/scripts/Linux/runApacheDeploy.sh b/muranorepository/Services/scripts/Linux/runApacheDeploy.sh new file mode 100644 index 0000000..0ae1036 --- /dev/null +++ b/muranorepository/Services/scripts/Linux/runApacheDeploy.sh @@ -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 diff --git a/muranorepository/Services/scripts/Linux/runTelnetDeploy.sh b/muranorepository/Services/scripts/Linux/runTelnetDeploy.sh new file mode 100644 index 0000000..df5dd7b --- /dev/null +++ b/muranorepository/Services/scripts/Linux/runTelnetDeploy.sh @@ -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 diff --git a/muranorepository/Services/telnet-manifest.yaml b/muranorepository/Services/telnet-manifest.yaml new file mode 100644 index 0000000..b925e2d --- /dev/null +++ b/muranorepository/Services/telnet-manifest.yaml @@ -0,0 +1,28 @@ +version: 0.1 +service_display_name: Linux Telnet Service + +description: >- + Linux Telnet Service + 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 diff --git a/muranorepository/Services/ui_forms/LinuxApache.yaml b/muranorepository/Services/ui_forms/LinuxApache.yaml new file mode 100644 index 0000000..e6f3d39 --- /dev/null +++ b/muranorepository/Services/ui_forms/LinuxApache.yaml @@ -0,0 +1,86 @@ +name: Apache Service +type: linuxApacheService + +description: >- + Linux Apache Service + 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 diff --git a/muranorepository/Services/workflows/Apache.xml b/muranorepository/Services/workflows/Apache.xml new file mode 100644 index 0000000..e94749c --- /dev/null +++ b/muranorepository/Services/workflows/Apache.xml @@ -0,0 +1,165 @@ + + + + + ( + + + port- + + + + + + + + + + + + + + + + + + + + Linux instance ) created + + + + + + + ( + + + Configuring security groups on ) + + + + + + + + + + Security groups configuration on instance ) is successful + + + + + + + ( + + + insatalling Apache on unit ) + + + + + + + + + + + + + + + Apache deployed on ) + + + + + + + (