diff --git a/meta/io.murano/Classes/resources/Instance.yaml b/meta/io.murano/Classes/resources/Instance.yaml index 0b4bee7e..94b2f5f8 100644 --- a/meta/io.murano/Classes/resources/Instance.yaml +++ b/meta/io.murano/Classes/resources/Instance.yaml @@ -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): diff --git a/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml b/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml index 9ca66f1b..d279f733 100644 --- a/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml +++ b/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml @@ -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} diff --git a/meta/io.murano/Resources/linux-init.sh b/meta/io.murano/Resources/linux-init.sh index e4d51d9c..4032e16a 100644 --- a/meta/io.murano/Resources/linux-init.sh +++ b/meta/io.murano/Resources/linux-init.sh @@ -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 diff --git a/meta/io.murano/Resources/murano-agent b/meta/io.murano/Resources/murano-agent new file mode 100644 index 00000000..0b7fc1ac --- /dev/null +++ b/meta/io.murano/Resources/murano-agent @@ -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 diff --git a/meta/io.murano/Resources/murano-agent.conf b/meta/io.murano/Resources/murano-agent.conf new file mode 100644 index 00000000..fbd28056 --- /dev/null +++ b/meta/io.murano/Resources/murano-agent.conf @@ -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 \ No newline at end of file diff --git a/meta/io.murano/Resources/murano-agent.service b/meta/io.murano/Resources/murano-agent.service new file mode 100644 index 00000000..a04fdbb3 --- /dev/null +++ b/meta/io.murano/Resources/murano-agent.service @@ -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 \ No newline at end of file diff --git a/meta/io.murano/Resources/murano-init.conf b/meta/io.murano/Resources/murano-init.conf new file mode 100644 index 00000000..b70d3ab8 --- /dev/null +++ b/meta/io.murano/Resources/murano-init.conf @@ -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 diff --git a/meta/io.murano/Resources/murano-init.sh b/meta/io.murano/Resources/murano-init.sh new file mode 100644 index 00000000..296d2cc7 --- /dev/null +++ b/meta/io.murano/Resources/murano-init.sh @@ -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 + + + + +