Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
module Agama
module DBus
# Represents the Agama bus, a distinct one from the system and session buses.
class Bus < ::DBus::Connection
class Bus < ::DBus::BusConnection
class << self
# Returns the current D-Bus connection
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@

require "dbus"
require "agama/dbus/bus"
require "agama/dbus/users"
require "agama/users"
require "agama/dbus/language"
require "agama/language"

module Agama
module DBus
# D-Bus service (org.opensuse.Agama.Users1)
# D-Bus service (org.opensuse.Agama.Language1)
#
# It connects to the system D-Bus and answers requests on objects below
# `/org/opensuse/Agama/Users1`.
class UsersService
# `/org/opensuse/Agama/Language1`.
class LanguageService
# Service name
#
# @return [String]
SERVICE_NAME = "org.opensuse.Agama.Users1"
SERVICE_NAME = "org.opensuse.Agama.Language1"
private_constant :SERVICE_NAME

# System D-Bus
# Agama D-Bus
#
# @return [::DBus::Connection]
# @return [::DBus::BusConnection]
attr_reader :bus

# @param _config [Config] Configuration object
Expand Down Expand Up @@ -75,18 +75,18 @@ def service
# @return [Array<::DBus::Object>]
def dbus_objects
@dbus_objects ||= [
users_dbus
language_dbus
]
end

# @return [Agama::DBus::Users]
def users_dbus
@users_dbus ||= Agama::DBus::Users.new(users_backend(logger), logger)
# @return [Agama::DBus::Language]
def language_dbus
@language_dbus ||= Agama::DBus::Language.new(language_backend(logger), logger)
end

# @return [Agama::Users]
def users_backend(logger)
@users_backend ||= Agama::Users.new(logger)
# @return [Agama::Language]
def language_backend(logger)
@language_backend ||= Agama::Language.new(logger).tap(&:probe)
end
end
end
Expand Down
47 changes: 38 additions & 9 deletions service/lib/agama/dbus/manager_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

require "dbus"
require "agama/manager"
require "agama/users"
require "agama/cockpit_manager"
require "agama/dbus/bus"
require "agama/dbus/manager"
require "agama/dbus/users"
require "agama/dbus/storage/proposal"

module Agama
Expand All @@ -33,27 +35,38 @@ module DBus
# It connects to the system D-Bus and answers requests on objects below
# `/org/opensuse/Agama1`.
class ManagerService
# Service name
# List of D-Bus services exposed by this class
#
# @return [String]
SERVICE_NAME = "org.opensuse.Agama1"
private_constant :SERVICE_NAME
# This basically allows to define "aliases" - all exposed services holds the same objects
# but under different names
#
# @return [Array<String>]
MANAGER_SERVICE = "org.opensuse.Agama1"
USERS_SERVICE = "org.opensuse.Agama.Users1"
private_constant :MANAGER_SERVICE
private_constant :USERS_SERVICE

# System D-Bus
# Agama D-Bus
#
# @return [::DBus::Connection]
# @return [::DBus::BusConnection]
attr_reader :bus

# Installation manager
#
# @return [Agama::Manager]
attr_reader :manager

# Users manager
#
# @return [Agama::Users]
attr_reader :users

# @param config [Config] Configuration
# @param logger [Logger]
def initialize(config, logger = nil)
@config = config
@manager = Agama::Manager.new(config, logger)
@users = Agama::Users.new(logger)
@logger = logger || Logger.new($stdout)
@bus = Bus.current
end
Expand All @@ -70,10 +83,14 @@ def start

# Exports the installer object through the D-Bus service
def export
# manager service initialization
dbus_objects.each { |o| service.export(o) }

paths = dbus_objects.map(&:path).join(", ")
logger.info "Exported #{paths} objects"

# Request our service names only when we're ready to serve the objects
service_aliases.each { |s| bus.request_name(s) }
end

# Call this from some main loop to dispatch the D-Bus messages
Expand All @@ -94,21 +111,33 @@ def setup_cockpit
cockpit.setup(config.data["web"])
end

# @return [::DBus::Service]
def service_aliases
@service_aliases ||= [
MANAGER_SERVICE,
USERS_SERVICE
]
end

# @return [::DBus::ObjectServer]
def service
@service ||= bus.request_service(SERVICE_NAME)
@service ||= bus.object_server
end

# @return [Array<::DBus::Object>]
def dbus_objects
@dbus_objects ||= [
manager_dbus
manager_dbus,
users_dbus
]
end

def manager_dbus
@manager_dbus ||= Agama::DBus::Manager.new(manager, logger)
end

def users_dbus
@users_dbus ||= Agama::DBus::Users.new(users, logger)
end
end
end
end
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/questions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class QuestionsService

# D-Bus connection
#
# @return [::DBus::Connection]
# @return [::DBus::BusConnection]
attr_reader :bus

# Constructor
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/software_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SoftwareService

# D-Bus connection
#
# @return [::DBus::Connection]
# @return [::DBus::BusConnection]
attr_reader :bus

# @param config [Config] Configuration object
Expand Down
6 changes: 6 additions & 0 deletions service/package/rubygem-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jun 7 08:54:58 UTC 2023 - Michal Filka <mfilka@suse.com>

- Merge the users D-Bus service into the main one to save some resources
(gh#openSUSE/agama#596).

-------------------------------------------------------------------
Wed Jun 7 05:33:27 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion service/share/org.opensuse.Agama.Users1.service
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[D-BUS Service]
Name=org.opensuse.Agama.Users1
Exec=/usr/bin/agamactl users
Exec=/usr/bin/agamactl manager
User=root
4 changes: 2 additions & 2 deletions service/test/agama/dbus/manager_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
let(:config) { Agama::Config.new }
let(:logger) { Logger.new($stdout, level: :warn) }
let(:manager) { Agama::Manager.new(config, logger) }
let(:bus) { instance_double(Agama::DBus::Bus) }
let(:bus) { instance_double(Agama::DBus::Bus, request_name: nil) }
let(:bus_service) do
instance_double(::DBus::ObjectServer, export: nil)
end
Expand All @@ -40,7 +40,7 @@

before do
allow(Agama::DBus::Bus).to receive(:current).and_return(bus)
allow(bus).to receive(:request_service).and_return(bus_service)
allow(bus).to receive(:object_server).and_return(bus_service)
allow(Agama::Manager).to receive(:new).with(config, logger).and_return(manager)
allow(Agama::CockpitManager).to receive(:new).and_return(cockpit)
allow(manager).to receive(:software).and_return(software_client)
Expand Down
5 changes: 5 additions & 0 deletions setup-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ $SUDO cp -v $MYDIR/service/share/dbus.conf /usr/share/dbus-1/agama.conf
(
cd $MYDIR/service/share
DBUSDIR=/usr/share/dbus-1/agama-services

# cleanup previous installation
[[ -d $DBUSDIR ]] && $SUDO rm -r $DBUSDIR

# create services
$SUDO mkdir -p $DBUSDIR
for SVC in org.opensuse.Agama*.service; do
sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC
Expand Down
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ $SUDO ln -snf `pwd`/web/dist /usr/share/cockpit/agama
echo
echo "D-Bus will start the services, see journalctl for their logs."
echo "To start the services manually, logging to the terminal:"
echo " cd service; $SUDO bundle exec bin/agamactl"
echo " $SUDO systemctl start agama.service"
echo
echo "Visit http://localhost:9090/cockpit/@localhost/agama/index.html"