packages: systemd/systemd.spec, systemd/systemd-sysv-convert (NEW) - rel 0....

cactus cactus at pld-linux.org
Tue Nov 29 17:11:49 CET 2011


Author: cactus                       Date: Tue Nov 29 16:11:49 2011 GMT
Module: packages                      Tag: HEAD
---- Log message:
- rel 0.7; with systemd-sysv-convert tool for saving runlevel configuration of services

---- Files affected:
packages/systemd:
   systemd.spec (1.51 -> 1.52) , systemd-sysv-convert (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: packages/systemd/systemd.spec
diff -u packages/systemd/systemd.spec:1.51 packages/systemd/systemd.spec:1.52
--- packages/systemd/systemd.spec:1.51	Tue Nov 29 00:34:34 2011
+++ packages/systemd/systemd.spec	Tue Nov 29 17:11:43 2011
@@ -25,11 +25,12 @@
 Summary(pl.UTF-8):	systemd - zarządca systemu i usług dla Linuksa
 Name:		systemd
 Version:	37
-Release:	0.6
+Release:	0.7
 License:	GPL v2+
 Group:		Base
 Source0:	http://www.freedesktop.org/software/systemd/%{name}-%{version}.tar.bz2
 # Source0-md5:	1435f23be79c8c38d1121c6b150510f3
+Source1:	systemd-sysv-convert
 Patch0:		target-pld.patch
 URL:		http://www.freedesktop.org/wiki/Software/systemd
 %{?with_audit:BuildRequires:	audit-libs-devel}
@@ -214,6 +215,10 @@
 # Create new-style configuration files so that we can ghost-own them
 touch $RPM_BUILD_ROOT%{_sysconfdir}/{hostname,locale.conf,machine-id,machine-info,os-release,timezone,vconsole.conf}
 
+# Install SysV conversion tool for systemd
+install -m 0755 %{SOURCE1} $RPM_BUILD_ROOT/%{_bindir}/
+
+install -d $RPM_BUILD_ROOT/var/log
 > $RPM_BUILD_ROOT/var/log/btmp
 > $RPM_BUILD_ROOT/var/log/wtmp
 
@@ -301,6 +306,7 @@
 %attr(755,root,root) %{_bindir}/systemd-analyze
 %attr(755,root,root) %{_bindir}/systemd-cgls
 %attr(755,root,root) %{_bindir}/systemd-nspawn
+%attr(755,root,root) %{_bindir}/systemd-sysv-convert
 %attr(755,root,root) %{_bindir}/systemd-stdio-bridge
 %attr(755,root,root) /sbin/halt
 %attr(755,root,root) /sbin/init
@@ -438,6 +444,9 @@
 All persons listed below can be reached at <cvs_login>@pld-linux.org
 
 $Log$
+Revision 1.52  2011/11/29 16:11:43  cactus
+- rel 0.7; with systemd-sysv-convert tool for saving runlevel configuration of services
+
 Revision 1.51  2011/11/28 23:34:34  gotar
 - packaged /var/log/[bw]tmp
 

================================================================
Index: packages/systemd/systemd-sysv-convert
diff -u /dev/null packages/systemd/systemd-sysv-convert:1.1
--- /dev/null	Tue Nov 29 17:11:49 2011
+++ packages/systemd/systemd-sysv-convert	Tue Nov 29 17:11:43 2011
@@ -0,0 +1,148 @@
+#!/usr/bin/python
+# -*- Mode: Python; python-indent: 8; indent-tabs-mode: t -*-
+
+import sys, os, argparse, errno
+
+def find_service(service, runlevel):
+	priority = -1
+
+	for l in os.listdir("/etc/rc%i.d" % runlevel):
+		if len(l) < 4:
+			continue
+
+		if l[0] != 'S' or l[3:] != service:
+			continue
+
+		p = int(l[1:3])
+
+		if p >= 0 and p <= 99 and p >= priority:
+			priority = p;
+
+	return priority
+
+def lookup_database(services):
+	try:
+		database = open("/var/lib/systemd/sysv-convert/database", "r")
+	except IOError, e:
+		if e.errno != errno.ENOENT:
+			raise e
+
+		return {}
+
+	found = {}
+	k = 0
+
+	for line in database:
+		service, r, p = line.strip().split("\t", 3)
+		k += 1
+
+		try:
+			runlevel = int(r)
+			priority = int(p)
+		except ValueError, e:
+			sys.stderr.write("Failed to parse database line %i. Ignoring." % k)
+			continue
+
+		if runlevel not in (2, 3, 4, 5):
+			sys.stderr.write("Runlevel out of bounds in database line %i. Ignoring." % k)
+			continue
+
+		if priority < 0 or priority > 99:
+			sys.stderr.write("Priority out of bounds in database line %i. Ignoring." % k)
+			continue
+
+		if service not in services:
+			continue
+
+		if service not in found:
+			found[service] = {}
+
+		if runlevel not in found[service] or found[service][runlevel] < priority:
+			found[service][runlevel] = priority
+
+	return found
+
+def mkdir_p(path):
+	try:
+		os.makedirs(path, 0755)
+	except OSError, e:
+		if e.errno != errno.EEXIST:
+			raise e
+
+if os.geteuid() != 0:
+	sys.stderr.write("Need to be root.\n")
+	sys.exit(1)
+
+parser = argparse.ArgumentParser(description='Save and Restore SysV Service Runlevel Information')
+
+parser.add_argument('services', metavar='SERVICE', type=str, nargs='+',
+		    help='Service names')
+
+parser.add_argument('--save', dest='save', action='store_const',
+		    const=True, default=False,
+		    help='Save SysV runlevel information for one or more services')
+
+parser.add_argument('--show', dest='show', action='store_const',
+		    const=True, default=False,
+		    help='Show saved SysV runlevel information for one or more services')
+
+parser.add_argument('--apply', dest='apply', action='store_const',
+		    const=True, default=False,
+		    help='Apply saved SysV runlevel information for one or more services to systemd counterparts')
+
+a = parser.parse_args()
+
+if a.save:
+	for service in a.services:
+		if not os.access("/etc/rc.d/init.d/%s" % service, os.F_OK):
+			sys.stderr.write("SysV service %s does not exist.\n" % service)
+			sys.exit(1)
+
+	mkdir_p("/var/lib/systemd/sysv-convert")
+	database = open("/var/lib/systemd/sysv-convert/database", "a")
+
+	for runlevel in (2, 3, 4, 5):
+		priority = find_service(service, runlevel)
+
+		if priority >= 0:
+			database.write("%s\t%s\t%s\n" % (service, runlevel, priority))
+
+elif a.show:
+	found = lookup_database(a.services)
+
+	if len(found) <= 0:
+		sys.stderr.write("No information about passed services found.\n")
+		sys.exit(1)
+
+	for service, data in found.iteritems():
+		for runlevel, priority in data.iteritems():
+			sys.stdout.write("SysV service %s enabled in runlevel %s at priority %s\n" % (service, runlevel, priority))
+
+elif a.apply:
+	for service in a.services:
+		if not os.access("/lib/systemd/system/%s.service" % service, os.F_OK):
+			sys.stderr.write("systemd service %s.service does not exist.\n" % service)
+			sys.exit(1)
+
+	found = lookup_database(a.services)
+
+	if len(found) <= 0:
+		sys.stderr.write("No information about passed services found.\n")
+		sys.exit(1)
+
+	for service, data in found.iteritems():
+		for runlevel in data.iterkeys():
+
+			sys.stderr.write("ln -sf /lib/systemd/system/%s.service /etc/systemd/system/runlevel%i.target.wants/%s.service\n" % (service, runlevel, service))
+
+			mkdir_p("/etc/systemd/system/runlevel%i.target.wants" % runlevel)
+
+			try:
+				os.symlink("/lib/systemd/system/%s.service" % service,
+					   "/etc/systemd/system/runlevel%i.target.wants/%s.service" % (runlevel, service))
+			except OSError, e:
+				if e.errno != errno.EEXIST:
+					raise e
+
+else:
+	parser.print_help()
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/systemd/systemd.spec?r1=1.51&r2=1.52&f=u



More information about the pld-cvs-commit mailing list