detect unready controllers; add __init__.py for services
diff --git a/xos/synchronizers/onboarding/steps/sync_servicecontroller.py b/xos/synchronizers/onboarding/steps/sync_servicecontroller.py
index 142da97..6c7af35 100644
--- a/xos/synchronizers/onboarding/steps/sync_servicecontroller.py
+++ b/xos/synchronizers/onboarding/steps/sync_servicecontroller.py
@@ -29,6 +29,10 @@
     def sync_record(self, sc):
         logger.info("Sync'ing ServiceController %s" % sc)
 
+        unready = self.check_controller_unready(sc)
+        if unready:
+            raise Exception("Controller %s has unready resources: %s" % (str(sc), ",".join([str(x) for x in unready])))
+
         dockerfiles = [self.create_synchronizer_dockerfile(sc)]
         tenant_fields = {"dockerfiles": dockerfiles,
                          "build_dir": self.build_dir,
diff --git a/xos/synchronizers/onboarding/xosbuilder.py b/xos/synchronizers/onboarding/xosbuilder.py
index a1fccb5..7811df1 100644
--- a/xos/synchronizers/onboarding/xosbuilder.py
+++ b/xos/synchronizers/onboarding/xosbuilder.py
@@ -14,7 +14,7 @@
 logger = Logger(level=logging.INFO)
 
 class XOSBuilder(object):
-    UI_KINDS=["models", "admin", "django_library", "rest", "tosca_custom_types", "tosca_resource","public_key"]
+    UI_KINDS=["models", "admin", "django_library", "rest_service", "rest_tenant", "tosca_custom_types", "tosca_resource","public_key"]
     SYNC_CONTROLLER_KINDS=["synchronizer", "private_key", "public_key"]
     SYNC_ALLCONTROLLER_KINDS=["models", "django_library"]
 
@@ -35,7 +35,7 @@
                      "tosca_custom_types": "%s/tosca/custom_types/" % (xos_base),
                      "tosca_resource": "%s/tosca/resources/" % (xos_base),
                      "rest_service": "%s/api/service/" % (xos_base),
-                     "rest_tenant": "%s/api/service/" % (xos_base),
+                     "rest_tenant": "%s/api/tenant/" % (xos_base),
                      "private_key": "%s/services/%s/keys" % (xos_base, service_name),
                      "public_key": "%s/services/%s/keys/" % (xos_base, service_name)}
         return base_dirs[scr.kind]
@@ -99,13 +99,29 @@
             return ["ADD %s /%s" % (build_fn, build_fn)]
 
     def get_controller_docker_lines(self, controller, kinds):
+        need_service_init_py = False
         dockerfile=[]
         for scr in controller.service_controller_resources.all():
             if scr.kind in kinds:
                 lines = self.get_docker_lines(scr)
                 dockerfile = dockerfile + lines
+            if scr.kind in ["admin", "models"]:
+                need_service_init_py = True
+
+        if need_service_init_py:
+            file(os.path.join(self.build_dir, "opt/xos/empty__init__.py"),"w").write("")
+            dockerfile.append("ADD opt/xos/empty__init__.py /opt/xos/services/%s/__init__.py" % controller.name)
+
         return dockerfile
 
+    def check_controller_unready(self, controller):
+        unready_resources=[]
+        for scr in controller.service_controller_resources.all():
+            if (not scr.backend_status) or (not scr.backend_status.startswith("1")):
+                unready_resources.append(scr)
+
+        return unready_resources
+
     # stuff that has to do with building
 
     def create_xos_app_data(self, name, dockerfile, app_list, migration_list):
@@ -128,6 +144,10 @@
 
         dockerfile = ["FROM %s" % self.source_ui_image]
         for controller in ServiceController.objects.all():
+            if self.check_controller_unready(controller):
+                 logger.warning("Controller %s has unready resources" % str(controller))
+                 continue
+
             dockerfile = dockerfile + self.get_controller_docker_lines(controller, self.UI_KINDS)
             if controller.service_controller_resources.filter(kind="models").exists():
                 app_list.append("services." + controller.name)
@@ -195,8 +215,12 @@
                              "volumes": volume_list}
 
          for c in ServiceController.objects.all():
+             if self.check_controller_unready(c):
+                 logger.warning("Controller %s has unready resources" % str(c))
+                 continue
+
              containers["xos_synchronizer_%s" % c.name] = \
-                            {"image": "xosproject/xos-synchronizer-%s" % controller.name,
+                            {"image": "xosproject/xos-synchronizer-%s" % c.name,
                              "command": 'bash -c "sleep 120; bash /opt/xos/synchronizers/%s/run.sh"',
                              "links": ["xos_db"],
                              "volumes": volume_list}