← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~rjschwei/cloud-init:systemdGenTmpl into cloud-init:master

 

Robert Schweikert has proposed merging ~rjschwei/cloud-init:systemdGenTmpl into cloud-init:master.

Commit message:
The systemd generator used to generate the target file has a hard
coded path for the location of systemd. This path does not apply to all
distributions. Make the generator and template to have the path set
during build time.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~rjschwei/cloud-init/+git/cloud-init/+merge/356098
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~rjschwei/cloud-init:systemdGenTmpl into cloud-init:master.
diff --git a/setup.py b/setup.py
index 5ed8eae..90b897d 100755
--- a/setup.py
+++ b/setup.py
@@ -138,8 +138,10 @@ INITSYS_FILES = {
     'systemd': [render_tmpl(f)
                 for f in (glob('systemd/*.tmpl') +
                           glob('systemd/*.service') +
-                          glob('systemd/*.target')) if is_f(f)],
-    'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
+                          glob('systemd/*.target'))
+                if (is_f(f) and 'generator' not in f)],
+    'systemd.generators': [render_tmpl(f)
+                           for f in glob('systemd/*-generator*') if is_f(f)],
     'upstart': [f for f in glob('upstart/*') if is_f(f)],
 }
 INITSYS_ROOTS = {
@@ -225,6 +227,10 @@ class InitsysInstallData(install):
                     continue
                 self.distribution.data_files.append(
                     (INITSYS_ROOTS[k], INITSYS_FILES[k]))
+                #if 'generator' in k:
+                #    for generator in INITSYS_FILES[k]:
+                #        tiny_p(['chmod', '+x', generator])
+                    
         # Force that command to reinitalize (with new file list)
         self.distribution.reinitialize_command('install_data', True)
 
diff --git a/systemd/cloud-init-generator b/systemd/cloud-init-generator.tmpl
index bd9f267..cfa5eb5 100755
--- a/systemd/cloud-init-generator
+++ b/systemd/cloud-init-generator.tmpl
@@ -1,3 +1,4 @@
+## template:jinja
 #!/bin/sh
 set -f
 
@@ -9,7 +10,11 @@ DISABLE="disabled"
 FOUND="found"
 NOTFOUND="notfound"
 RUN_ENABLED_FILE="$LOG_D/$ENABLE"
+{% if variant in ["suse"] %}
+CLOUD_SYSTEM_TARGET="/usr/lib/systemd/system/cloud-init.target"
+{% else %}
 CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"
+{% endif %}
 CLOUD_TARGET_NAME="cloud-init.target"
 # lxc sets 'container', but lets make that explicitly a global
 CONTAINER="${container}"
diff --git a/tools/render-cloudcfg b/tools/render-cloudcfg
index 8b7cb87..8c7d8b7 100755
--- a/tools/render-cloudcfg
+++ b/tools/render-cloudcfg
@@ -2,6 +2,7 @@
 
 import argparse
 import os
+import stat
 import sys
 
 VARIANTS = ["bsd", "centos", "fedora", "rhel", "suse", "ubuntu", "unknown"]
@@ -30,6 +31,9 @@ def main():
 
     args = parser.parse_args()
 
+    file_info = os.stat(args.template)
+    mode = file_info.st_mode
+    
     with open(args.template, 'r') as fh:
         contents = fh.read()
     tpl_params = {'variant': args.variant}
@@ -38,7 +42,7 @@ def main():
     if args.output == "-":
         sys.stdout.write(contents)
     else:
-        write_file(args.output, contents, omode="w")
+        write_file(args.output, contents, mode=mode, omode="w")
 
 if __name__ == '__main__':
     main()

Follow ups