chiark / gitweb /
sysv-generator: Skip init scripts for existing native services
authorMartin Pitt <martin.pitt@ubuntu.com>
Wed, 2 Jul 2014 20:00:00 +0000 (22:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Feb 2015 12:02:01 +0000 (13:02 +0100)
This avoids taking the SysV init script enablement state into account if we
have native units. Otherwise systemctl disable on native unit would not
be respected in the presence of an enabled SysV script.

Also, there's no need to do all the parsing and creation of service files if we
already have a native systemd unit for the processed SysV init script.

src/sysv-generator/sysv-generator.c
test/sysv-generator-test.py

index 673f04dc27a6a317332f5ba70c8a22608738b7b0..6e39b449eb7902e7de97da8d94beec2ef9f06f89 100644 (file)
@@ -768,6 +768,11 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
                         if (!fpath)
                                 return log_oom();
 
+                        if (unit_file_get_state(UNIT_FILE_SYSTEM, NULL, name) >= 0) {
+                                log_debug("Native unit for %s already exists, skipping", name);
+                                continue;
+                        }
+
                         service = new0(SysvStub, 1);
                         if (!service)
                                 return log_oom();
@@ -852,7 +857,8 @@ static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
 
                                 service = hashmap_get(all_services, name);
                                 if (!service){
-                                        log_warning("Could not find init script for %s", name);
+                                        log_debug("Ignoring %s symlink in %s, not generating %s.",
+                                                  de->d_name, rcnd_table[i].path, name);
                                         continue;
                                 }
 
index 5098519073fe461e75a6e17fff669c570cdd7b72..09f5c0176296310d27df3855cc2a44089e6b9e60 100644 (file)
@@ -367,6 +367,18 @@ class SysvGeneratorTest(unittest.TestCase):
         self.assert_enabled('foo.bak.service', [])
         self.assert_enabled('foo.old.service', [])
 
+    def test_existing_native_unit(self):
+        '''existing native unit'''
+
+        with open(os.path.join(self.unit_dir, 'foo.service'), 'w') as f:
+            f.write('[Unit]\n')
+
+        self.add_sysv('foo.sh', {'Provides': 'foo bar'}, enable=True)
+        err, results = self.run_generator()
+        self.assertEqual(list(results), [])
+        # no enablement or alias links, as native unit is disabled
+        self.assertEqual(os.listdir(self.out_dir), [])
+
 
 if __name__ == '__main__':
     unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))