instance.cfg.in 4.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#############################
#
# Deploy hello-world instance
#
#############################
[buildout]
parts =
  directory
  publish-connection-parameter

# Define egg directories to be the one from Software Release
# (/opt/slapgrid/...)
# Always the same.
14 15
eggs-directory = {{ buildout['eggs-directory'] }}
develop-eggs-directory = {{ buildout['develop-eggs-directory'] }}
16 17 18 19
offline = true


[instance-parameter]
20 21 22 23
# Fetch arbitrary parameters defined by the user in SlapOS Master for his instance.
# We use the slapconfiguration recipe with a few parameters (partition id,
# computer id, certificate, etc).
# It will then authenticate to SlapOS Master and fetch the instance parameters.
24
# The parameters are accessible from ${instance-parameter:configuration.name-of-parameter}
25
# Always the same. Just copy/paste.
26
# See docstring of slapos.cookbook:slapconfiguration for more information.
27
recipe = slapos.cookbook:slapconfiguration
28 29 30 31 32
computer = ${slap_connection:computer_id}
partition = ${slap_connection:partition_id}
url = ${slap_connection:server_url}
key = ${slap_connection:key_file}
cert = ${slap_connection:cert_file}
33 34

# Define default parameter(s) that will be used later, in case user didn't
35
# specify it.
36
# All possible parameters should have a default.
37 38 39 40 41
# In our use case, we are expecting from the user to specify one (optional) parameter: "name". We put the default value here if he doesn't specify it, so that it doesn't crash.
configuration.name = John Doe
# If our use case requires that the user can specify a mail address so that his instance can mail to him (for example), we can do:
# configuration.mail-address =
# If the user doesn't specify it, it won't break and the recipe can handle it (i.e don't send any mail for example).
42 43 44 45 46


# Create all needed directories, depending on your needs
[directory]
recipe = slapos.cookbook:mkdirectory
47 48 49
home = ${buildout:directory}
etc = ${:home}/etc
var = ${:home}/var
50
# Executables put here will be started but not monitored (for startup scripts)
51
script = ${:etc}/run/
52
# Executables put here will be started and monitored (for daemons)
53
service = ${:etc}/service
54 55
# Executables put here will be launched after buildout has completed to see
# if instance is running
56
promise = ${:etc}/promise/
57
# Path of the log directory used by our service (see [helloweb])
58
log = ${:var}/log
59

60 61

# Create a simple web server that says "hello <configuration.name>" to the web.
62
[helloweb]
63 64 65 66 67 68 69
# helloworld service is listening on:
# - global IPv6 address, and
# - fixed port
#
# NOTE because every computer partition is allocated its own global IPv6
# address, it is ok to fix the port - different hello-world instances will have
# different IPv6 addresses and they all will be accessible at the same time.
70
ipv6 = ${instance-parameter:ipv6-random}
71
# full URL - for convenience
72
url = http://[${:ipv6}]:${:port}
73 74

# the service will log here
75
logfile = ${directory:log}/helloweb-${:kind}.log
76 77

# Actual script that starts the service:
78 79
# This recipe will try to "exec" the command-line after separating parameters.
recipe = slapos.cookbook:wrapper
80
command-line =
81
    {{ buildout['bin-directory'] }}/helloweb-${:kind} --logfile ${:logfile}
82
        ${:ipv6} ${:port} ${instance-parameter:configuration.name}
83 84 85
# Put this shell script in the "etc/service" directory. Each executable of this
# repository will be started and monitored by supervisord. If a service
# exits/crashes, it will trigger a "bang" and cause a re-run of the instance.
86
wrapper-path = ${directory:service}/helloweb-${:kind}
87 88


89 90
# promise, that checks that helloweb service is alive
[helloweb-promise]
91
recipe = slapos.cookbook:check_port_listening
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
path = ${directory:promise}/helloweb-${:kind}

{# macro to instantiate service of `kind` to listen on `port` #}
{% set service_list = [] %}
{% macro hellowebsrv(kind, port) %}
{% do service_list.append(kind) %}
[helloweb-{{ kind }}]
<= helloweb
kind    = {{ kind }}
port    = {{ port }}

[helloweb-{{ kind }}-promise]
<= helloweb-promise
kind    = {{ kind }}
hostname= ${helloweb-{{ kind }}:ipv6}
port    = {{ port }}
{% endmacro %}

# services instantiation
{{ hellowebsrv('python', 7777) }}
112
{{ hellowebsrv('ruby',   7778) }}
113 114 115 116 117 118 119 120 121


# register all services/promises to buildout parts
[buildout]
parts +=
{%- for kind in service_list %}
  helloweb-{{ kind }}
  helloweb-{{ kind }}-promise
{%- endfor %}
122 123


124 125 126 127 128
# Publish all the parameters needed for the user to connect to the instance.
# It can be anything: URL(s), password(s), or arbitrary parameters.
# Here we'll just echo back the entered name as instance parameter
[publish-connection-parameter]
recipe = slapos.cookbook:publish
129
name = Hello ${instance-parameter:configuration.name}!
130 131 132
{%- for kind in service_list %}
url.{{ kind }} = ${helloweb-{{ kind }}:url}
{%- endfor %}