Merge lp:~larryprice/libertine/libertined-systemd into lp:libertine

Proposed by Larry Price
Status: Merged
Approved by: Christopher Townsend
Approved revision: 420
Merged at revision: 456
Proposed branch: lp:~larryprice/libertine/libertined-systemd
Merge into: lp:libertine
Diff against target: 220 lines (+40/-102)
7 files modified
data/CMakeLists.txt (+5/-0)
data/com.canonical.libertine.Service.service (+2/-1)
data/libertine.service (+7/-0)
debian/libertined.install (+1/-0)
tests/integration/test_libertine_service.py (+1/-1)
tests/integration/test_liblibertine.cpp (+0/-1)
tools/libertined (+24/-99)
To merge this branch: bzr merge lp:~larryprice/libertine/libertined-systemd
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
Libertine CI Bot continuous-integration Approve
Review via email: mp+321780@code.launchpad.net

Commit message

Install libertined as systemd unit.

Description of the change

Install libertined as systemd unit.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:417
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/506/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/911
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/747
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/747
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/747
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/747
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/922
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/911
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/911/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/911
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/911/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/911
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/911/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/911
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/911/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/506/rebuild

review: Approve (continuous-integration)
418. By Larry Price

attempt on dealing with systemd install/remove

419. By Larry Price

merge

420. By Larry Price

minor change

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:420
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/508/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/913
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/749
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/749
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/749
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/749
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/924
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/913
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/913/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/913
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/913/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/913
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/913/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/913
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/913/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/508/rebuild

review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

lgtm, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/CMakeLists.txt'
--- data/CMakeLists.txt 2017-01-31 16:28:31 +0000
+++ data/CMakeLists.txt 2017-04-04 18:44:41 +0000
@@ -8,5 +8,10 @@
8 DESTINATION ${CMAKE_INSTALL_DATADIR}/upstart/sessions)8 DESTINATION ${CMAKE_INSTALL_DATADIR}/upstart/sessions)
9install(FILES libertine-lxc-sudo libertine-lxd-sudo9install(FILES libertine-lxc-sudo libertine-lxd-sudo
10 DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sudoers.d)10 DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sudoers.d)
11
12# libertined
11install(FILES com.canonical.libertine.Service.service13install(FILES com.canonical.libertine.Service.service
12 DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services)14 DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services)
15pkg_get_variable(SYSTEMD_USER_DIR systemd systemduserunitdir)
16install(FILES libertine.service
17 DESTINATION ${SYSTEMD_USER_DIR}/)
1318
=== modified file 'data/com.canonical.libertine.Service.service'
--- data/com.canonical.libertine.Service.service 2017-01-20 20:37:02 +0000
+++ data/com.canonical.libertine.Service.service 2017-04-04 18:44:41 +0000
@@ -1,3 +1,4 @@
1[D-BUS Service]1[D-BUS Service]
2Name=com.canonical.libertine.Service2Name=com.canonical.libertine.Service
3Exec=/usr/bin/libertined --cache-output3Exec=/usr/bin/libertined
4SystemdService=libertine.service
45
=== added file 'data/libertine.service'
--- data/libertine.service 1970-01-01 00:00:00 +0000
+++ data/libertine.service 2017-04-04 18:44:41 +0000
@@ -0,0 +1,7 @@
1[Unit]
2Description=Libertine Service
3
4[Service]
5Type=dbus
6BusName=com.canonical.libertine.Service
7ExecStart=/usr/bin/libertined
08
=== modified file 'debian/libertined.install'
--- debian/libertined.install 2017-01-20 18:43:08 +0000
+++ debian/libertined.install 2017-04-04 18:44:41 +0000
@@ -1,3 +1,4 @@
1usr/bin/libertined1usr/bin/libertined
2usr/lib/python*/*/libertine/service2usr/lib/python*/*/libertine/service
3usr/share/dbus-1/services/com.canonical.libertine.Service.service3usr/share/dbus-1/services/com.canonical.libertine.Service.service
4usr/lib/systemd/user
45
=== modified file 'tests/integration/test_libertine_service.py'
--- tests/integration/test_libertine_service.py 2017-03-27 20:51:17 +0000
+++ tests/integration/test_libertine_service.py 2017-04-04 18:44:41 +0000
@@ -43,7 +43,7 @@
43 cls._tempdir = tempfile.TemporaryDirectory()43 cls._tempdir = tempfile.TemporaryDirectory()
4444
45 os.environ['XDG_DATA_HOME'] = cls._tempdir.name45 os.environ['XDG_DATA_HOME'] = cls._tempdir.name
46 cls._process = pexpect.spawnu('libertined --debug', env=os.environ.copy())46 cls._process = pexpect.spawnu('libertined', env=os.environ.copy())
47 cls._process.logfile = sys.stdout47 cls._process.logfile = sys.stdout
4848
49 # give libertined enough time to start the whole process49 # give libertined enough time to start the whole process
5050
=== modified file 'tests/integration/test_liblibertine.cpp'
--- tests/integration/test_liblibertine.cpp 2017-03-07 18:38:05 +0000
+++ tests/integration/test_liblibertine.cpp 2017-04-04 18:44:41 +0000
@@ -30,7 +30,6 @@
30 static void SetUpTestCase()30 static void SetUpTestCase()
31 {31 {
32 process = dbus_test_process_new("libertined");32 process = dbus_test_process_new("libertined");
33 dbus_test_process_append_param(process, "--debug");
3433
35 dbus_test_task_set_bus(DBUS_TEST_TASK(process), DBUS_TEST_SERVICE_BUS_SESSION);34 dbus_test_task_set_bus(DBUS_TEST_TASK(process), DBUS_TEST_SERVICE_BUS_SESSION);
36 dbus_test_task_set_name(DBUS_TEST_TASK(process), "libertine");35 dbus_test_task_set_name(DBUS_TEST_TASK(process), "libertine");
3736
=== modified file 'tools/libertined'
--- tools/libertined 2017-03-27 20:06:39 +0000
+++ tools/libertined 2017-04-04 18:44:41 +0000
@@ -28,89 +28,15 @@
28from libertine.service import constants, operations, container_control, container_control_client28from libertine.service import constants, operations, container_control, container_control_client
2929
3030
31class OutputRedirector(object):
32 def __init__(self, config):
33 self.config = config
34 if utils.is_snap_environment():
35 self.cache_path = '%s/.cache/libertined' % os.environ['SNAP_USER_COMMON']
36 else:
37 self.cache_path = '%s/.cache/libertined' % os.environ['HOME']
38 self.cache_file = '%s/libertined.log' % self.cache_path
39 self.output_file = None
40 self.copied_stdout = None
41 self.copied_stderr = None
42
43 def _fileno(self, file_or_fd):
44 return getattr(file_or_fd, 'fileno', lambda: file_or_fd)()
45
46 def _do_redirect(self, stream):
47 fd = self._fileno(stream)
48 copied_stream = os.fdopen(os.dup(fd), 'wb')
49 stream.flush()
50 os.dup2(self._fileno(self.output_file), fd)
51 return copied_stream, fd
52
53 def _undo_redirect(self, stream, stream_fd, copied_stream):
54 stream.flush()
55 os.dup2(copied_stream.fileno(), stream_fd)
56 copied_stream.close()
57
58 def _rotate_logs(self):
59 os.makedirs(self.cache_path, exist_ok=True)
60 num_backups = 3
61 for i in range(num_backups, 0, -1):
62 filename = '%s.%i' % (self.cache_file, i)
63 if os.path.exists(filename):
64 if i == num_backups:
65 os.remove(filename)
66 else:
67 os.rename(filename, '%s.%i' % (self.cache_file, i+1))
68 if os.path.exists(self.cache_file):
69 os.rename(self.cache_file, '%s.1' % self.cache_file)
70
71 def __enter__(self):
72 utils.set_environmental_verbosity(self.config.verbosity)
73
74 if not self.config.debug:
75 if self.config.cache_output:
76 self._rotate_logs()
77 self.output_file = open(self.cache_file, 'w')
78 else:
79 self.output_file = open(os.devnull, 'w')
80
81 self.copied_stdout, self.stdout_fd = self._do_redirect(sys.stdout)
82 self.copied_stderr, self.stderr_fd = self._do_redirect(sys.stderr)
83
84 def __exit__(self, type, value, tb):
85 if self.copied_stdout and self.stdout_fd:
86 self._undo_redirect(sys.stdout, self.stdout_fd, self.copied_stdout)
87 if self.copied_stderr and self.stderr_fd:
88 self._undo_redirect(sys.stderr, self.stderr_fd, self.copied_stderr)
89 if self.output_file:
90 self.output_file.close()
91
92
93class Config(object):31class Config(object):
94 def __init__(self):32 def __init__(self):
95 self._arg_parser = argparse.ArgumentParser(description=u'Libertine Store service')33 self._arg_parser = argparse.ArgumentParser(description=u'Libertine Store service')
96 self._arg_parser.add_argument(u'-l', u"--use-local-cache",
97 action='store_true',
98 default=False,
99 help=u"use local cache instead of system cache")
100 self._arg_parser.add_argument(u'-d', u"--debug",
101 action='store_true',
102 default=False,
103 help=u"print output to stdout")
104 self._arg_parser.add_argument('-q', '--quiet', action='store_const',34 self._arg_parser.add_argument('-q', '--quiet', action='store_const',
105 dest='verbosity', const=0,35 dest='verbosity', const=0,
106 help=('disables all non-vital output'))36 help=('disables all non-vital output'))
107 self._arg_parser.add_argument('-v', '--verbosity', action='store_const',37 self._arg_parser.add_argument('-v', '--verbosity', action='store_const',
108 dest='verbosity', const=2,38 dest='verbosity', const=2,
109 help=('enables debug output'))39 help=('enables debug output'))
110 self._arg_parser.add_argument(u'-c', u"--cache-output",
111 action='store_true',
112 default=False,
113 help=u"Log to $HOME/.cache/libertined/ instead of stdout")
114 args = self._arg_parser.parse_args(namespace=Config)40 args = self._arg_parser.parse_args(namespace=Config)
11541
11642
@@ -139,31 +65,30 @@
139def main():65def main():
140 config = Config()66 config = Config()
14167
142 with OutputRedirector(config):68 utils.get_logger().info("Initializing libertined...")
143 utils.get_logger().info("Initializing libertined...")69 loop = Loop()
144 loop = Loop()70
14571 try:
146 try:72 bus_name = dbus.service.BusName(constants.SERVICE_NAME,
147 bus_name = dbus.service.BusName(constants.SERVICE_NAME,73 bus=dbus.SessionBus(),
148 bus=dbus.SessionBus(),74 do_not_queue=True)
149 do_not_queue=True)75 except dbus.exceptions.NameExistsException:
150 except dbus.exceptions.NameExistsException:76 utils.get_logger().warning("service is already running")
151 utils.get_logger().warning("service is already running")77 raise
152 raise78
15379 client = container_control_client.ContainerControlClient()
154 client = container_control_client.ContainerControlClient()80 manager = operations.Operations(bus_name, client)
155 manager = operations.Operations(bus_name, client)81 container_control.ContainerControl(manager.connection, client)
156 container_control.ContainerControl(manager.connection, client)82
15783 try:
158 try:84 utils.get_logger().info("libertined ready")
159 utils.get_logger().info("libertined ready")85 loop.run()
160 loop.run()86 except KeyboardInterrupt:
161 except KeyboardInterrupt:87 utils.get_logger().debug("keyboard interrupt received")
162 utils.get_logger().debug("keyboard interrupt received")88 except Exception as e:
163 except Exception as e:89 utils.get_logger().error("Unexpected exception occurred: '{}'".format(str(e)))
164 utils.get_logger().error("Unexpected exception occurred: '{}'".format(str(e)))90 finally:
165 finally:91 loop.shutdown()
166 loop.shutdown()
16792
16893
169if __name__ == '__main__':94if __name__ == '__main__':

Subscribers

People subscribed via source and target branches