helloworld: logrotate and cron added
[slapos.git] / software / helloworld / instance.cfg.in
1 #############################
2 #
3 # Deploy hello-world instance
4 #
5 #############################
6 #
7 # Adding a binary to this software : logrotate
8 #
9 #############################
10 [buildout]
11 parts =
12   directory
13   hello-world
14   publish-connection-parameter
15 # Don't forget to include the new part ! It will also call [template-get] in software.cfg
16   template-creation
17   cron
18   cron-entry-logrotate
19   logrotate
20   logrotate-entry
21
22 # Define egg directories to be the one from Software Release
23 # (/opt/slapgrid/...)
24 # Always the same.
25 eggs-directory = ${buildout:eggs-directory}
26 develop-eggs-directory = ${buildout:develop-eggs-directory}
27 offline = true
28
29
30 [instance-parameter]
31 # Fetch arbitrary parameters defined by the user in SlapOS Master for his instance.
32 # We use the slapconfiguration recipe with a few parameters (partition id,
33 # computer id, certificate, etc).
34 # It will then authenticate to SlapOS Master and fetch the instance parameters.
35 # The parameters are accessible from $${instance-parameter:configuration.name-of-parameter}
36 # Always the same. Just copy/paste.
37 # See docstring of slapos.cookbook:slapconfiguration for more informations.
38 recipe = slapos.cookbook:slapconfiguration
39 computer = $${slap_connection:computer_id}
40 partition = $${slap_connection:partition_id}
41 url = $${slap_connection:server_url}
42 key = $${slap_connection:key_file}
43 cert = $${slap_connection:cert_file}
44
45 # Define default parameter(s) that will be used later, in case user didn't
46 # specify it.
47 # All possible parameters should have a default.
48 # 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.
49 configuration.name = John Doe
50 # Here is the declaration of the default value for the parameter title (actually, it is void). If commented, the recipe will crash.
51 # The first part of the name paramater ("configuration.") means that the value can be manually defined thanks to the parameters of the instance
52 configuration.title = 
53 # 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:
54 # configuration.mail-address =
55 # 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).
56
57
58 # Create all needed directories, depending on your needs
59 [directory]
60 recipe = slapos.cookbook:mkdirectory
61 home = $${buildout:directory}
62 etc = $${:home}/etc
63 bin = $${:home}/bin
64 var = $${:home}/var
65 srv = $${:home}/srv
66 # Creation of the folder wich will contain the jinja template
67 data-fold = $${:srv}/data
68 # Executables put here will be started but not monitored (for startup scripts)
69 script = $${:etc}/run/
70 # Executables put here will be started and monitored (for daemons)
71 service = $${:etc}/service
72 # Executables put here will be launched after buildout has completed to see
73 # if instance is running
74 promise = $${:etc}/promise/
75 # Path of the log directory used by our service (see [hello-world])
76 log = $${:var}/log
77 # Cron directories
78 cron-entries = $${:etc}/cron.d
79 crontabs = $${:etc}/crontabs
80 cronstamps = $${:etc}/cronstamps
81 # Logrotate directories
82 backup = $${:srv}/backup
83 logrotate-backup = $${:backup}/logrotate
84 logrotate-entries = $${:etc}/logrotate.d
85
86
87 # Deploy cron
88 [cron]
89 recipe = slapos.cookbook:cron
90 dcrond-binary = ${dcron:location}/sbin/crond
91 cron-entries = $${directory:cron-entries}
92 crontabs = $${directory:crontabs}
93 cronstamps = $${directory:cronstamps}
94 catcher = $${cron-simplelogger:wrapper}
95 binary = $${directory:service}/crond
96
97 [cron-simplelogger]
98 recipe = slapos.cookbook:simplelogger
99 wrapper = $${directory:bin}/cron_simplelogger
100 log = $${directory:log}/cron.log
101
102 [cron-entry-logrotate]
103 <= cron
104 recipe = slapos.cookbook:cron.d
105 name = logrotate
106 frequency = 0 * * * *
107 # Now that the cron is set up, we can define
108 # the command to launch every XX
109 command = $${logrotate:wrapper}
110
111 # Deploy Logrotate
112 # To know more about which arguments are necessary,
113 # and why they are used for, you should read the recipe,
114 # in ../../slapos/recipe/logrogate.py
115 [logrotate]
116 recipe = slapos.cookbook:logrotate
117 # Binaries
118 logrotate-binary = ${logrotate:location}/usr/sbin/logrotate
119 gzip-binary = ${gzip:location}/bin/gzip
120 gunzip-binary = ${gzip:location}/bin/gunzip
121 # Directories
122 wrapper = $${directory:bin}/logrotate
123 conf = $${directory:etc}/logrotate.conf
124 # in this folder will be defined tho files to save, and how to save them
125 logrotate-entries = $${directory:logrotate-entries}
126 # in this folder the logs will be compressed then saved
127 backup = $${directory:logrotate-backup}
128 state-file = $${directory:srv}/logrotate.status
129
130 [logrotate-entry]
131 <= logrotate
132 recipe = slapos.cookbook:logrotate.d
133 name = helloworld-logrotate
134 log = $${directory:log}/log.log
135 frequency = daily
136 rotatep-num = 30
137 sharedscripts = true
138 notifempty = true
139 create = true
140
141
142 # It is now time for Jinja !
143 [template-creation]
144 recipe = slapos.recipe.template:jinja2
145 # We could also define the template inline.
146 #template = inline:
147 #  ----------------------------------
148 #  Title : {{title}}
149 #  ----------------------------------
150 #  Hello {{name}}
151 # the value of template will be replaced thanks to the information given in software.cfg, during its own buildout
152 template = ${template-get:location}/${template-get:filename}
153 # Here we can declare where we want to get the new file rendered by Jinja
154 rendered = $${directory:data-fold}/data1.txt
155 mode = 700
156 # In the context we can define the specific values wich will be substituted in the template
157 # key mean that the value is to get in another section of this buildout config file. Go to http://git.erp5.org/gitweb/slapos.recipe.template.git/blob/HEAD:/slapos/recipe/template/README.jinja2.txt?js=1 for more information
158 context =
159   key name instance-parameter:configuration.name
160   key title instance-parameter:configuration.title
161
162
163 # Create a simple shell script that will only output your name if you
164 # specified it as instance parameter.
165 # Usually, of course, we use more useful commands, like web servers.
166 [hello-world]
167 # This recipe will try to "exec" the command-line after separating parameters.
168 recipe = slapos.cookbook:wrapper
169 # Notice that there is only one $ at ${dash:location}, it is because it comes from the Software Release buildout profile.
170 command-line = ${dash:location}/bin/dash -c 'echo "Hello $${instance-parameter:configuration.name}, it is $(date)." > $${directory:log}/log.log; sleep 1000000;'
171 # Put this shell script in the "etc/service" directory. Every executable of this
172 # repository will be started and monitored by supervisord. If one service
173 # exits/crashes, it will trigger a "bang" and cause run of slapgrid for the
174 # instance.
175 wrapper-path = $${directory:service}/hello-world
176
177
178 # Publish all the parameters needed for the user to connect to the instance.
179 # It can be anything: URL(s), password(s), or arbitrary parameters.
180 # Here we'll just echo back the entered name as instance parameter
181 [publish-connection-parameter]
182 recipe = slapos.cookbook:publish
183 name = Hello $${instance-parameter:configuration.name}!
184 # Adds the published parameter "title". 
185 title = $${instance-parameter:configuration.title}
186 path = $${template-creation:rendered}