Install murano-agent by cloud-init

Adding a murano-init script to install murano-agent by cloud init
in the LinuxMuranoInstance.

Change-Id: I080fe14a61b9af468ba1ae2e26dd85196a563449
Targets-blueprint: cloud-init-deployable-agent
This commit is contained in:
Henar Muñoz Frutos 2015-10-13 16:46:14 +02:00 committed by Henar Muñoz
parent b50564d65d
commit e089f7989e
8 changed files with 181 additions and 27 deletions

View File

@ -114,8 +114,6 @@ Methods:
- $.networks.customNetworks.select($this.joinNet($, $securityGroupName))
- $preparedUserData: $.prepareUserData()
- $userData: $preparedUserData.data
- $userDataFormat: $preparedUserData.format
# Create MQ queue to communicate with the VM
- $.agent.prepare()
- $template:
@ -126,8 +124,8 @@ Methods:
flavor: $.flavor
image: $.image
availability_zone: $.availabilityZone
user_data: $userData
user_data_format: $userDataFormat
user_data: $preparedUserData.data
user_data_format: $preparedUserData.format
key_name: $.keyname
outputs:
format('{0}-assigned-ips', $.name):

View File

@ -21,27 +21,68 @@ Extends:
- LinuxInstance
Methods:
prepareUserData:
prepareUserData:
Body:
- $environment: $.find(std:Environment).require()
- $resources: new(sys:Resources)
- $configFile: $resources.string('Agent-v2.template')
- $initScript: $resources.string('linux-init.sh')
- $configReplacements:
"%RABBITMQ_HOST%": config(rabbitmq, host)
"%RABBITMQ_PORT%": config(rabbitmq, port)
"%RABBITMQ_USER%": config(rabbitmq, login)
"%RABBITMQ_PASSWORD%": config(rabbitmq, password)
"%RABBITMQ_VHOST%": config(rabbitmq, virtual_host)
"%RABBITMQ_SSL%": str(config(rabbitmq, ssl)).toLower()
"%RABBITMQ_INPUT_QUEUE%": $.agent.queueName()
"%RESULT_QUEUE%": $environment.agentListener.queueName()
- $scriptReplacements:
"%AGENT_CONFIG_BASE64%": base64encode($configFile.replace($configReplacements))
"%INTERNAL_HOSTNAME%": $.name
"%MURANO_SERVER_ADDRESS%": coalesce(config(file_server), config(rabbitmq, host))
"%CA_ROOT_CERT_BASE64%": ""
- Return:
data: $initScript.replace($scriptReplacements)
format: HEAT_CFNTOOLS
- $environment: $.find(std:Environment).require()
- $resources: new(sys:Resources)
- $configFile: $resources.string('Agent-v2.template')
- $initScript: $resources.string('linux-init.sh')
- $muranoScript: $resources.string('murano-init.sh')
- $muranoAgentConf: $resources.string('murano-agent.conf')
- $muranoAgentService: $resources.string('murano-agent.service')
- $muranoAgent: $resources.string('murano-agent')
- $configReplacements:
"%RABBITMQ_HOST%": config(rabbitmq, host)
"%RABBITMQ_PORT%": config(rabbitmq, port)
"%RABBITMQ_USER%": config(rabbitmq, login)
"%RABBITMQ_PASSWORD%": config(rabbitmq, password)
"%RABBITMQ_VHOST%": config(rabbitmq, virtual_host)
"%RABBITMQ_SSL%": str(config(rabbitmq, ssl)).toLower()
"%RABBITMQ_INPUT_QUEUE%": $.agent.queueName()
"%RESULT_QUEUE%": $environment.agentListener.queueName()
- $scriptReplacements:
"%AGENT_CONFIG_BASE64%": base64encode($configFile.replace($configReplacements))
"%INTERNAL_HOSTNAME%": $.name
"%MURANO_SERVER_ADDRESS%": coalesce(config(file_server), config(rabbitmq, host))
"%CA_ROOT_CERT_BASE64%": ""
- $muranoReplacements:
"%MURANO_AGENT_CONF%": base64encode($muranoAgentConf)
"%MURANO_AGENT_SERVICE%": base64encode($muranoAgentService)
"%MURANO_AGENT%": base64encode($muranoAgent)
- $userData: $muranoScript.replace($muranoReplacements) + $initScript.replace($scriptReplacements)
- Return:
data: $._generateInstanceConfigResources($userData)
format: RAW
_generateInstanceConfigResources:
Arguments:
- userData:
Contract: $.string().notNull()
Body:
- $environment: $.find(std:Environment).require()
- $resources: new(sys:Resources)
- $muranoInitConf: $resources.yaml('murano-init.conf')
- $bootConfigResourceName: format('boot_config_{0}', $.name)
- $bootScriptResourceName: format('boot_script_{0}', $.name)
- $userDataResourceName: format('user_data-{0}', $.name)
- $template:
resources:
$bootConfigResourceName:
type: 'OS::Heat::CloudConfig'
properties:
cloud_config: $muranoInitConf
$bootScriptResourceName:
type: 'OS::Heat::SoftwareConfig'
properties:
group: ungrouped
config: $userData
$userDataResourceName:
type: 'OS::Heat::MultipartMime'
properties:
parts:
- config: {get_resource: $bootConfigResourceName}
- config: {get_resource: $bootScriptResourceName}
- $environment.stack.updateTemplate($template)
- Return: {get_resource: $userDataResourceName}

View File

@ -15,7 +15,7 @@ service murano-agent stop
AgentConfigBase64='%AGENT_CONFIG_BASE64%'
if [[ ! -d /etc/murano ]]; then
if [ ! -d /etc/murano ]; then
mkdir /etc/murano
fi
echo $AgentConfigBase64 | base64 -d > /etc/murano/agent.conf

View File

@ -0,0 +1,51 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: murano-agent
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: murano-agent service
### END INIT INFO
SCRIPT="/usr/bin/muranoagent --config-dir /etc/murano"
RUNAS=root
PIDFILE=/var/run/murano.pid
LOGFILE=/var/log/murano.log
start() {
if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > "$PIDFILE"
echo 'Service started' >&2
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|uninstall}"
esac

View File

@ -0,0 +1,14 @@
start on runlevel [2345]
stop on runlevel [016]
respawn
# the default post-start of 1 second sleep delays respawning enough to
# not hit the default of 10 times in 5 seconds. Make it 2 times in 5s.
respawn limit 2 5
# We're logging to syslog
console none
exec start-stop-daemon --start -c root --exec /usr/local/bin/muranoagent -- --config-dir /etc/murano 2>&1 | logger -t murano-agent
post-start exec sleep 1

View File

@ -0,0 +1,10 @@
[Unit]
Description=OpenStack Murano Agent
[Service]
Type=simple
ExecStart=/usr/local/bin/muranoagent --config-dir /etc/murano
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,20 @@
yum_repos:
epel-testing:
baseurl: http://download.fedoraproject.org/pub/epel/$releasever/$basearch
enabled: true
failovermethod: priority
gpgcheck: false
name: Extra Packages for Enterprise Linux - Testing
package_upgrade: true
packages:
- subversion
- git-core
- wget
- make
- gcc
- python-pip
- python-dev
- python-setuptools
- python-virtualenv

View File

@ -0,0 +1,20 @@
#!/bin/sh
ps cax | grep muranoagent > /dev/null
if [ $? -eq 0 ]; then
echo "murano-agent service exists"
else
muranoAgentConf='%MURANO_AGENT_CONF%'
echo $muranoAgentConf | base64 -d > /etc/init/murano-agent.conf
muranoAgentService='%MURANO_AGENT_SERVICE%'
echo $muranoAgentService | base64 -d > /etc/systemd/system/murano-agent.service
muranoAgent='%MURANO_AGENT%'
echo $muranoAgent | base64 -d > /etc/init.d/murano-agent
chmod +x /etc/init.d/murano-agent
pip install murano-agent
fi