1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

sysv-generator: Skip init scripts for existing native services

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.
This commit is contained in:
Martin Pitt 2014-07-02 22:00:00 +02:00 committed by Lennart Poettering
parent f93b36affa
commit f4f01ec146
2 changed files with 19 additions and 1 deletions

View 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;
}

View 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))