From ab32dccc8b23702bf701f04d015b45d3f2daf829 Mon Sep 17 00:00:00 2001
From: Nicolas Wavrant <nicolas.wavrant@tiolive.com>
Date: Fri, 21 Feb 2014 11:28:51 +0100
Subject: [PATCH] slaprunner: can now auto-deploy an instance

Conflicts:
	software/slaprunner/instance-runner.cfg
---
 software/slaprunner/README.txt                    |  2 ++
 software/slaprunner/instance-runner-export.cfg.in |  3 ++-
 software/slaprunner/instance-runner-import.cfg.in |  3 ++-
 software/slaprunner/instance-runner.cfg           | 15 ++++++++++++---
 software/slaprunner/template/slapos.cfg.in        |  1 +
 5 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/software/slaprunner/README.txt b/software/slaprunner/README.txt
index 0ef0f3dea..d15dc98b1 100644
--- a/software/slaprunner/README.txt
+++ b/software/slaprunner/README.txt
@@ -51,6 +51,8 @@ for instance
 
 The parameter "auto-deploy-instance" can be explicitly set to allow or prevent the runner to deploy the instance at START TIME (if you manually restart the runner, or if the server reboots). Values : "true" or "false". Default value is "true", except for the instances of import (while type is resilient or test) which is "false"
 
+There also exists the parameter "autorun", which will build&run your software if set to true. For this, you need "auto_deploy" to true, and set the parameter "slapos-software" to the software you want to deploy. Do not hesitate to clone a different repo than "slapos", or to change the tag/branch to use your custom Software Release. (see "slapos-repository" and "slapos-reference" in previous section).
+
 Resilience :
 ------------
 
diff --git a/software/slaprunner/instance-runner-export.cfg.in b/software/slaprunner/instance-runner-export.cfg.in
index 832ae00db..27b0c7895 100644
--- a/software/slaprunner/instance-runner-export.cfg.in
+++ b/software/slaprunner/instance-runner-export.cfg.in
@@ -18,13 +18,14 @@ parts +=
   slaprunner-promise
   slaprunner-frontend-promise
   dropbear-promise
+  private
   shellinabox-promise
   symlinks
   shellinabox
   slapos-cfg
   slapos-repo-config
-  prepare-software
   cron-entry-backup
+  cron-entry-prepare-software
 ###Parts to add for monitoring
   slap-parameters
   certificate-authority
diff --git a/software/slaprunner/instance-runner-import.cfg.in b/software/slaprunner/instance-runner-import.cfg.in
index fe8e48065..c668e79b0 100644
--- a/software/slaprunner/instance-runner-import.cfg.in
+++ b/software/slaprunner/instance-runner-import.cfg.in
@@ -16,12 +16,13 @@ parts +=
   sshkeys-authority
   slaprunner-promise
   dropbear-promise
+  private
   shellinabox-promise
   shellinabox
   symlinks
   slapos-cfg
   slapos-repo-config
-  prepare-software
+  cron-entry-prepare-software
 # have to repeat the next one, as it's not inherited from pbsready-import
   import-on-notification
 ###Parts to add for monitoring
diff --git a/software/slaprunner/instance-runner.cfg b/software/slaprunner/instance-runner.cfg
index baa930be3..78cb05e88 100644
--- a/software/slaprunner/instance-runner.cfg
+++ b/software/slaprunner/instance-runner.cfg
@@ -20,7 +20,7 @@ parts =
   shellinabox
   slapos-cfg
   slapos-repo-config
-  prepare-software
+  cron-entry-prepare-software
 {% if slapparameter_dict.get('custom-frontend-backend-url') %}
   custom-frontend-promise
 {% endif %}
@@ -447,6 +447,7 @@ slapos-software =
 slapos-reference = master
 auto-deploy = true
 auto-deploy-instance = true
+autorun = true
 
 [slapos-cfg]
 recipe = slapos.recipe.template:jinja2
@@ -456,6 +457,9 @@ mode = 700
 context =
   key software_root runnerdirectory:software-root
   key instance_root runnerdirectory:instance-root
+  key auto_deploy slap-parameter:auto-deploy
+  key auto_deploy_instance slap-parameter:auto-deploy-instance
+  key autorun slap-parameter:autorun
   key console slaprunner:console
   key debug slaprunner:debug
   key etc_dir slaprunner:etc_dir
@@ -479,8 +483,6 @@ context =
   key supervisor slaprunner:supervisor
   key supervisord_config slaprunner:supd-temp-var
   key verbose slaprunner:verbose
-  key auto_deploy slap-parameter:auto-deploy
-  key auto_deploy_instance slap-parameter:auto-deploy-instance
 
 [shellinabox]
 recipe = slapos.cookbook:shellinabox
@@ -531,6 +533,13 @@ recipe = slapos.cookbook:wrapper
 command-line = ${curl:location}/bin/curl -g https://[$${slaprunner:ipv6}]:$${slaprunner:runner_port}/isSRReady --max-time 1 --insecure
 wrapper-path = $${directory:scripts}/prepareSoftware
 
+[cron-entry-prepare-software]
+<= cron
+recipe = slapos.cookbook:cron.d
+name = prepare-software
+frequency = */2 * * * *
+command = $${prepare-software:wrapper-path}
+
 [public]
 recovery-code = $${recovery-code:passwd}
 shell-password = $${shellinabox-code:passwd}
diff --git a/software/slaprunner/template/slapos.cfg.in b/software/slaprunner/template/slapos.cfg.in
index 6cc246e8f..6d3d8ce32 100644
--- a/software/slaprunner/template/slapos.cfg.in
+++ b/software/slaprunner/template/slapos.cfg.in
@@ -27,6 +27,7 @@ verbose = {{ verbose }}
 debug = {{ debug }}
 auto_deploy = {{ auto_deploy }}
 auto_deploy_instance = {{ auto_deploy_instance }}
+autorun = {{ autorun }}
 
 [slapproxy]
 host = {{ proxy_host }}
-- 
2.30.9