[PATCH] Build: Add 'make install' target
by Zane Bitter
Try again, and now make sure that the spec file explicitly references the
cmake-generated Makefile rather than the default GNUMakefile.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
GNUmakefile | 5 ++++-
matahari.spec.in | 4 ++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index d27cc58..22d6af1 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -51,6 +51,9 @@ tests: linux.build
cd linux.build/src/unittests && ctest -V; \
fi
+install: linux.build
+ $(MAKE) --no-print-dir -C $< install
+
windows.build:
@echo "=::=::=::= Setting up for Windows =::=::=::= "
mkdir -p $@
@@ -182,4 +185,4 @@ endif
@sed -i -e 's/###MATAHARI_VERSION###/$(VERSION)/' doc/Doxyfile
@doxygen doc/Doxyfile
-.PHONY: check linux.build windows.build clean doxygen tags www-doxygen coverity $(VARIANT)$(PACKAGE).spec
+.PHONY: check linux.build windows.build install clean doxygen tags www-doxygen coverity $(VARIANT)$(PACKAGE).spec
diff --git a/matahari.spec.in b/matahari.spec.in
index 8f105f4..3bfd509 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -242,14 +242,14 @@ QMF console for monitoring various agents
%build
%{cmake} -DCMAKE_BUILD_TYPE=RelWithDebInfo %{!?with_qmf: -DWITH-QMF:BOOL=OFF} %{!?with_dbus: -DWITH-DBUS:BOOL=OFF} -Dinitdir=%{_initddir} -Dsysconfdir=%{_sysconfdir} .
-make %{?_smp_mflags}
+make -f Makefile %{?_smp_mflags}
%if %{defined run_unit_tests}
cd src/tests && ctest -V
%endif
%install
rm -rf %{buildroot}
-make DESTDIR=%{buildroot} install
+make DESTDIR=%{buildroot} -f Makefile install
%if %{systemd}
rm -f $RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d/matahari-service
12 years, 6 months
[PATCH] Build: Move system config files to a subdirectory
by Zane Bitter
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
.gitignore | 22 ++----
99-matahari-guest-agent.rules | 2 -
CMakeLists.txt | 63 ----------------
matahari-broker.conf.in | 25 ------
matahari-broker.init.in | 120 ------------------------------
matahari-broker.service.in | 23 ------
matahari-broker.sysconf.in | 21 -----
matahari-vios-proxy-guest.init.in | 96 ------------------------
matahari-vios-proxy-guest.service.in | 12 ---
matahari-vios-proxy-host.init.in | 96 ------------------------
matahari-vios-proxy-host.service.in | 21 -----
matahari-vios-proxy.sysconf.in | 7 --
matahari.init.in | 117 -----------------------------
matahari.service.in | 18 -----
matahari.sysconf.in | 24 ------
src/broker/CMakeLists.txt | 15 ++++
src/cmake/modules/MatahariMacros.cmake | 4 +
src/unittests/.gitignore | 3 +
sys/.gitignore | 5 +
sys/CMakeLists.txt | 71 ++++++++++++++++++
sys/matahari-broker.conf.in | 25 ++++++
sys/matahari-broker.init.in | 120 ++++++++++++++++++++++++++++++
sys/matahari-broker.service.in | 23 ++++++
sys/matahari-broker.sysconf.in | 21 +++++
sys/matahari-guest-agent.rules | 2 +
sys/matahari-vios-proxy-guest.init.in | 96 ++++++++++++++++++++++++
sys/matahari-vios-proxy-guest.service.in | 12 +++
sys/matahari-vios-proxy-host.init.in | 96 ++++++++++++++++++++++++
sys/matahari-vios-proxy-host.service.in | 21 +++++
sys/matahari-vios-proxy.sysconf.in | 7 ++
sys/matahari.init.in | 117 +++++++++++++++++++++++++++++
sys/matahari.service.in | 18 +++++
sys/matahari.sysconf.in | 24 ++++++
33 files changed, 686 insertions(+), 661 deletions(-)
delete mode 100644 99-matahari-guest-agent.rules
delete mode 100644 matahari-broker.conf.in
delete mode 100755 matahari-broker.init.in
delete mode 100644 matahari-broker.service.in
delete mode 100644 matahari-broker.sysconf.in
delete mode 100644 matahari-vios-proxy-guest.init.in
delete mode 100644 matahari-vios-proxy-guest.service.in
delete mode 100644 matahari-vios-proxy-host.init.in
delete mode 100644 matahari-vios-proxy-host.service.in
delete mode 100644 matahari-vios-proxy.sysconf.in
delete mode 100644 matahari.init.in
delete mode 100644 matahari.service.in
delete mode 100644 matahari.sysconf.in
create mode 100644 sys/.gitignore
create mode 100644 sys/CMakeLists.txt
create mode 100644 sys/matahari-broker.conf.in
create mode 100755 sys/matahari-broker.init.in
create mode 100644 sys/matahari-broker.service.in
create mode 100644 sys/matahari-broker.sysconf.in
create mode 100644 sys/matahari-guest-agent.rules
create mode 100644 sys/matahari-vios-proxy-guest.init.in
create mode 100644 sys/matahari-vios-proxy-guest.service.in
create mode 100644 sys/matahari-vios-proxy-host.init.in
create mode 100644 sys/matahari-vios-proxy-host.service.in
create mode 100644 sys/matahari-vios-proxy.sysconf.in
create mode 100644 sys/matahari.init.in
create mode 100644 sys/matahari.service.in
create mode 100644 sys/matahari.sysconf.in
diff --git a/.gitignore b/.gitignore
index 4ba3e43..33b2db7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,3 @@
-*.patch
-*.orig
-*.rej
-*.rpm
-*~
*.cmake
Makefile
build.counter
@@ -11,19 +6,16 @@ matahari*.tgz
matahari-matahari-*
CMakeFiles
CMakeCache.txt
+install_manifest.txt
mock
-matahari.init
-matahari.sysconf
-matahari-brokerd
-matahari-broker
-matahari-broker.conf
-matahari-broker.sysconf
-matahari-broker.service
*.build
*.check
+*.spec
*.spec.sed
+*~
+*.patch
+*.orig
+*.rej
+*.rpm
tags
TAGS
-install_manifest.txt
-matahari.spec
-mingw32-matahari.spec
diff --git a/99-matahari-guest-agent.rules b/99-matahari-guest-agent.rules
deleted file mode 100644
index 8cfacee..0000000
--- a/99-matahari-guest-agent.rules
+++ /dev/null
@@ -1,2 +0,0 @@
-SUBSYSTEM=="virtio-ports", ATTR{name}}=="org.matahariproject.vios_proxy.0", \
- TAG+="systemd" ENV{SYSTEMD_WANTS}="matahari-vios-proxy-guest.service"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 077687d..256ceba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,12 +41,6 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Matahari QMF Agent")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "matahari-${CPACK_PACKAGE_VERSION}")
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari.sysconf.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari.sysconf)
-
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-broker.conf.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.conf)
-
if(WIN32)
set (CPACK_GENERATOR "NSIS")
@@ -114,62 +108,7 @@ else(WIN32)
set (CPACK_GENERATOR "TGZ")
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari.init.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari.init)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-broker.init.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker @ONLY)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-broker.sysconf.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.sysconf @ONLY)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-host.init.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-host.init @ONLY)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-guest.init.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-guest.init @ONLY)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy.sysconf.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy.sysconf @ONLY)
-
- install(DIRECTORY DESTINATION ${localstatedir}/lib/matahari
- DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
- GROUP_READ GROUP_WRITE GROUP_EXECUTE)
-
-
- install(CODE "execute_process(COMMAND chown root:qpidd ${localstatedir}/lib/matahari)")
-
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker DESTINATION ${initdir})
-
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari.sysconf DESTINATION ${sysconfdir}/sysconfig RENAME matahari)
-
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.sysconf DESTINATION ${sysconfdir}/sysconfig RENAME matahari-broker)
-
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.conf DESTINATION ${sysconfdir})
-
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy.sysconf DESTINATION ${sysconfdir}/sysconfig RENAME matahari-vios-proxy)
-
- # Check for systemd
- include(FindPkgConfig)
- pkg_check_modules(systemd systemd)
-
- if(systemd_FOUND)
- set(systemdunitdir "/lib/systemd/system")
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-broker.service.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.service)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-host.service.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-host.service)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-guest.service.in
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-guest.service)
-
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.service DESTINATION ${systemdunitdir})
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-host.service DESTINATION ${systemdunitdir})
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-guest.service DESTINATION ${systemdunitdir})
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/99-matahari-guest-agent.rules DESTINATION ${sysconfdir}/udev/rules.d)
- endif(systemd_FOUND)
+ add_subdirectory(sys)
endif(WIN32)
diff --git a/matahari-broker.conf.in b/matahari-broker.conf.in
deleted file mode 100644
index 8aeec38..0000000
--- a/matahari-broker.conf.in
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-# Configuration file for qpidd. Entries are of the form:
-# name=value
-#
-# (Note: no spaces on either side of '='). Using default settings:
-# "qpidd --help" or "man qpidd" for more details.
-cluster-mechanism=ANONYMOUS
-auth=no
diff --git a/matahari-broker.init.in b/matahari-broker.init.in
deleted file mode 100755
index 0f03b44..0000000
--- a/matahari-broker.init.in
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/bin/bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-#
-# matahari-broker Startup script for the Qpid messaging daemon.
-#
-
-### BEGIN INIT INFO
-# Provides: matahari-broker
-# Required-Start: $local_fs
-# Required-Stop: $local_fs
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Should-Start: matahari-vios-proxy-guest
-# Short-Description: start or stop matahari broker
-# Description: Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
-### END INIT INFO
-
-# chkconfig: - 85 15
-# description: Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
-# processname: qpidd
-
-prog="matahari-brokerd --pid-dir @localstatedir@/run/matahari"
-proc=qpidd
-lockfile=@localstatedir@/lock/subsys/matahari-broker
-pidfile=@localstatedir(a)/run/matahari-broker.pid
-
-# Turn off automatic systemd redirects
-#SYSTEMCTL_SKIP_REDIRECT=1
-
-# Source function library.
-. @sysconfdir(a)/rc.d/init.d/functions
-
-if [ -f @sysconfdir@/sysconfig/matahari ]; then
- . @sysconfdir@/sysconfig/matahari
-fi
-if [ -f @sysconfdir@/sysconfig/matahari-broker ]; then
- . @sysconfdir@/sysconfig/matahari-broker
-fi
-
-if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
- . @sysconfdir@/sysconfig/matahari-vios-proxy
-fi
-
-RETVAL=0
-
-start() {
- echo -n $"Starting Matahari broker daemon: "
- install -o root -g qpidd -m 775 -d @localstatedir@/run/matahari
- daemon --pidfile $pidfile --check $proc --user qpidd /usr/sbin/$prog $QPIDD_OPTIONS --daemon
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && touch $lockfile
- if [ $RETVAL = 0 ]; then
- touch $pidfile
- chown qpidd.qpidd $pidfile
- [ -x /sbin/restorecon ] && /sbin/restorecon $pidfile
- runuser -s /bin/sh qpidd -c "/usr/sbin/$prog --check > $pidfile"
- fi
- return $RETVAL
-}
-
-stop() {
- echo -n $"Stopping Matahari broker daemon: "
- killproc -p $pidfile $proc
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && rm -f $lockfile $pidfile
-}
-
-reload() {
- echo 1>&2 $"$0: reload not supported"
- exit 3
-}
-
-restart() {
- stop
- start
-}
-
-# See how we were called.
-case "$1" in
- start)
- status -p $pidfile -l $lockfile $proc >/dev/null || $1
- ;;
- stop|restart|reload)
- $1
- ;;
- status)
- status -p $pidfile -l $lockfile $proc
- RETVAL=$?
- ;;
- force-reload)
- restart
- ;;
- try-restart|condrestart)
- [ -e $lockfile ] && restart || :
- ;;
- *)
- echo 1>&2 $"Usage: $0 {start|stop|restart|condrestart|status}"
- exit 1
-esac
-
-exit $RETVAL
diff --git a/matahari-broker.service.in b/matahari-broker.service.in
deleted file mode 100644
index 5f28f48..0000000
--- a/matahari-broker.service.in
+++ /dev/null
@@ -1,23 +0,0 @@
-[Unit]
-Description=Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
-After=syslog.target network.target matahari-vios-proxy-guest.service
-Requires=syslog.target network.target
-
-[Install]
-WantedBy=multi-user.target
-
-[Service]
-Type=simple
-NotifyAccess=all
-SysVStartPriority=85
-User=qpidd
-Group=qpidd
-
-EnvironmentFile=-@sysconfdir@/sysconfig/matahari
-EnvironmentFile=-@sysconfdir@/sysconfig/matahari-broker
-EnvironmentFile=-@sysconfdir@/sysconfig/matahari-vios-proxy
-
-ExecStart=/usr/sbin/matahari-brokerd $QPIDD_OPTIONS
-
-# Restart options include: no, on-success, on-failure, on-abort or always
-Restart=on-failure
diff --git a/matahari-broker.sysconf.in b/matahari-broker.sysconf.in
deleted file mode 100644
index cd3d942..0000000
--- a/matahari-broker.sysconf.in
+++ /dev/null
@@ -1,21 +0,0 @@
-# Override the broker port set in @sysconfdir@/sysconfig/matahari
-#MATAHARI_PORT=@MATAHARI_PORT@
-
-QPIDD_OPTIONS="--config @sysconfdir(a)/matahari-broker.conf"
-
-# Federated Broker configuration - list the brokers to federate with
-# The following formats are allowed:
-# Hostname and port
-# <fqdn>:<port>
-# amqp:tcp:<fqdn>:<port>
-# amqp:ssl:<fqdn>:<port>
-# DNS SRV query format ("_matahari._<protocol>" is REQUIRED)
-# _matahari._tcp.<fqdn>
-# _matahari._tls.<fqdn>
-#
-# Note that only the first (highest priority) SRV record returned by the DNS
-# for each given query will be used.
-#
-# Addresses need not all be in the same format.
-#FEDERATED_BROKERS="broker1.example.com:49000, _matahari._tcp.example.com"
-
diff --git a/matahari-vios-proxy-guest.init.in b/matahari-vios-proxy-guest.init.in
deleted file mode 100644
index c85f712..0000000
--- a/matahari-vios-proxy-guest.init.in
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/bin/sh
-
-# the following is chkconfig init header
-# matahari-vios-proxy-guest: Initscript for Matahari specific vios-proxy
-### BEGIN INIT INFO
-# Provides:
-# Required-Start: $local_fs matahari-broker
-# Required-Stop: $local_fs matahari-broker
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: Starts and stops vios proxy guest daemon
-# Description: Matahari initscript for Vios Proxy Guest
-### END INIT INFO
-
-# chkconfig: - 99 01
-# description: Matahari initscript for Vios Proxy Guest
-# processname: matahari-vios-proxy-guest
-# pidfile: @localstatedir(a)/run/matahari-vios-proxy-guest.pid
-#
-
-# Turn off automatic systemd redirects
-#SYSTEMCTL_SKIP_REDIRECT=1
-
-# Source function library.
-. @sysconfdir(a)/rc.d/init.d/functions
-
-PROCESS=vios-proxy-guest
-
-RETVAL=0
-
-# Source function library.
-. @sysconfdir(a)/rc.d/init.d/functions
-
-if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
- . @sysconfdir@/sysconfig/matahari
-fi
-
-start() {
- echo -n $"Starting the $PROCESS daemon: "
-
- daemon $PROCESS $VP_H_GUEST_DIR $VP_H_SERVICE_DIR
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$PROCESS
-}
-
-stop() {
- echo -n $"Stopping the $PROCESS daemon: "
-
- killproc $PROCESS
- RETVAL=$?
- echo
- if [ $RETVAL -eq 0 ]; then
- rm -f @localstatedir@/lock/subsys/$PROCESS
- rm -f @localstatedir(a)/run/$PROCESS.pid
- fi
-}
-
-restart() {
- stop
- start
-}
-
-reload() {
- echo -n $"Reloading the $PROCESS configuration: "
-
- killproc $PROCESS -HUP
- RETVAL=$?
- echo
- return $RETVAL
-}
-
-# See how we were called.
-case "$1" in
- start)
- status $PROCESS >/dev/null || $1
- ;;
- stop|restart|reload)
- $1
- ;;
- status)
- status $PROCESS
- RETVAL=$?
- ;;
- force-reload)
- reload
- ;;
- condrestart|try-restart)
- [ -f @localstatedir@/lock/subsys/$PROCESS ] && restart || :
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
- exit 1
- ;;
-esac
-exit $RETVAL
diff --git a/matahari-vios-proxy-guest.service.in b/matahari-vios-proxy-guest.service.in
deleted file mode 100644
index b1ec32d..0000000
--- a/matahari-vios-proxy-guest.service.in
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Matahari Vios Proxy Guest
-BindTo=dev-virtio\x2dports-org.matahariproject.vios_proxy.0.device
-After=dev-virtio\x2dports-org.matahariproject.vios_proxy.0.device
-
-[Service]
-EnvironmentFile=@sysconfdir@/sysconfig/matahari-vios-proxy
-ExecStart=-/usr/bin/vios-proxy-guest $VP_G_HOST_DIR $VP_G_SERVICE_PORT
-Restart=always
-RestartSec=0
-
-[Install]
diff --git a/matahari-vios-proxy-host.init.in b/matahari-vios-proxy-host.init.in
deleted file mode 100644
index 098b9bd..0000000
--- a/matahari-vios-proxy-host.init.in
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/bin/sh
-
-# the following is chkconfig init header
-# matahari-vios-proxy-host: Initscript for Matahari specific vios-proxy
-### BEGIN INIT INFO
-# Provides:
-# Required-Start: $local_fs matahari-broker
-# Required-Stop: $local_fs matahari-broker
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: Starts and stops vios proxy host daemon
-# Description: Matahari initscript for Vios Proxy Host
-### END INIT INFO
-
-# chkconfig: - 99 01
-# description: Matahari initscript for Vios Proxy Host
-# processname: matahari-vios-proxy-host
-# pidfile: @localstatedir(a)/run/matahari-vios-proxy-host.pid
-#
-
-# Turn off automatic systemd redirects
-#SYSTEMCTL_SKIP_REDIRECT=1
-
-# Source function library.
-. @sysconfdir(a)/rc.d/init.d/functions
-
-PROCESS=vios-proxy-host
-
-RETVAL=0
-
-# Source function library.
-. @sysconfdir(a)/rc.d/init.d/functions
-
-if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
- . @sysconfdir@/sysconfig/matahari
-fi
-
-start() {
- echo -n $"Starting the $PROCESS daemon: "
-
- daemon $PROCESS $VP_H_GUEST_DIR $VP_H_SERVICE_DIR
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$PROCESS
-}
-
-stop() {
- echo -n $"Stopping the $PROCESS daemon: "
-
- killproc $PROCESS
- RETVAL=$?
- echo
- if [ $RETVAL -eq 0 ]; then
- rm -f @localstatedir@/lock/subsys/$PROCESS
- rm -f @localstatedir(a)/run/$PROCESS.pid
- fi
-}
-
-restart() {
- stop
- start
-}
-
-reload() {
- echo -n $"Reloading the $PROCESS configuration: "
-
- killproc $PROCESS -HUP
- RETVAL=$?
- echo
- return $RETVAL
-}
-
-# See how we were called.
-case "$1" in
- start)
- status $PROCESS >/dev/null || $1
- ;;
- stop|restart|reload)
- $1
- ;;
- status)
- status $PROCESS
- RETVAL=$?
- ;;
- force-reload)
- reload
- ;;
- condrestart|try-restart)
- [ -f @localstatedir@/lock/subsys/$PROCESS ] && restart || :
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
- exit 1
- ;;
-esac
-exit $RETVAL
diff --git a/matahari-vios-proxy-host.service.in b/matahari-vios-proxy-host.service.in
deleted file mode 100644
index aa4a77d..0000000
--- a/matahari-vios-proxy-host.service.in
+++ /dev/null
@@ -1,21 +0,0 @@
-[Unit]
-Description=Matahari specific requirements for a Vios proxy host
-After=syslog.target
-Requires=syslog.target
-
-[Install]
-WantedBy=multi-user.target
-
-[Service]
-Type=simple
-NotifyAccess=all
-SysVStartPriority=85
-User=root
-Group=root
-
-EnvironmentFile=@sysconfdir@/sysconfig/matahari-vios-proxy
-
-ExecStart=/usr/bin/vios-proxy-host $VP_H_GUEST_DIR $VP_H_SERVICE_PORT
-
-# Restart options include: no, on-success, on-failure, on-abort or always
-Restart=on-failure
diff --git a/matahari-vios-proxy.sysconf.in b/matahari-vios-proxy.sysconf.in
deleted file mode 100644
index abe83c0..0000000
--- a/matahari-vios-proxy.sysconf.in
+++ /dev/null
@@ -1,7 +0,0 @@
-# VIOS Proxy Host configuration
-VP_H_GUEST_DIR=/var/lib/libvirt
-VP_H_SERVICE_PORT=49000
-
-# VIOS Proxy Guest configuration
-VP_G_HOST_DIR=/dev/virtio-ports
-VP_G_SERVICE_PORT=48999
diff --git a/matahari.init.in b/matahari.init.in
deleted file mode 100644
index 18bd572..0000000
--- a/matahari.init.in
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/bin/sh
-
-# the following is chkconfig init header
-# matahari-@BASE@@BASE_SUB@: Matahari QMF @BASE@@BASE_SUB@ daemon
-### BEGIN INIT INFO
-# Provides: matahari-@BASE@@BASE_SUB@
-# Required-Start: $local_fs
-# Required-Stop: $local_fs
-# Should-Start: matahari-broker
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: Starts and stops the @BASE@@BASE_SUB@ matahari daemon
-# Description: Matahari @BASE@@BASE_SUB@ daemon using the AMQP protocol.
-### END INIT INFO
-
-# chkconfig: - 99 01
-# description: Matahari @BASE@@BASE_SUB@ daemon using the AMQP protocol.
-# processname: matahari-@BASE@@BASE_SUB@d
-# pidfile: @localstatedir@/run/matahari-@BASE@@BASE_SUB@.pid
-#
-
-# Turn off automatic systemd redirects
-#SYSTEMCTL_SKIP_REDIRECT=1
-
-# Source function library.
-. @sysconfdir(a)/rc.d/init.d/functions
-
-SERVICE=matahari-@BASE@@BASE_SUB@
-PROCESS=matahari-qmf-@BASE@@BASE_SUB@d
-# Old process naming convention, this is here
-# for compability sake when starting/stopping the
-# service from an upgrade of 0.4.0 > 0.4.2
-OLDPROCESS=matahari-@BASE@@BASE_SUB@d
-
-RETVAL=0
-
-test -f @sysconfdir@/sysconfig/matahari && . @sysconfdir@/sysconfig/matahari
-
-start() {
- echo -n $"Starting the $SERVICE daemon: "
-
- MATAHARI_ARGS="$MATAHARI_@DAEMON_TYPE@_ARGS $@BASE@_@DAEMON_TYPE@_ARGS"
- if [ -n "$MATAHARI_PORT" ]; then
- MATAHARI_ARGS="--port $MATAHARI_PORT $MATAHARI_ARGS"
- fi
- if [ -n "$MATAHARI_BROKER" ]; then
- MATAHARI_ARGS="--broker $MATAHARI_BROKER $MATAHARI_ARGS"
- fi
-
-
- export QPID_SSL_CERT_DB
- export QPID_SSL_CERT_PASSWORD_FILE
-
- daemon $PROCESS $MATAHARI_ARGS --daemon
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$SERVICE
-}
-
-stop() {
- echo -n $"Stopping the $SERVICE daemon: "
-
- # Check for OLDPROCESS for pre 0.4.2 compat
- pidofproc $OLDPROCESS >/dev/null
- RETVAL=$?
- if [ $RETVAL -lt 3 ]; then
- killproc $OLDPROCESS
- RETVAL=$?
- else
- killproc $PROCESS
- RETVAL=$?
- fi
- echo
- if [ $RETVAL -eq 0 ]; then
- rm -f @localstatedir@/lock/subsys/$SERVICE
- rm -f @localstatedir(a)/run/$SERVICE.pid
- fi
-}
-
-restart() {
- stop
- start
-}
-
-reload() {
- echo -n $"Reloading the $SERVICE configuration: "
-
- killproc $PROCESS -HUP
- RETVAL=$?
- echo
- return $RETVAL
-}
-
-# See how we were called.
-case "$1" in
- start)
- status $PROCESS >/dev/null || $1
- ;;
- stop|restart|reload)
- $1
- ;;
- status)
- status $PROCESS
- RETVAL=$?
- ;;
- force-reload)
- reload
- ;;
- condrestart|try-restart)
- [ -f @localstatedir@/lock/subsys/$SERVICE ] && restart || :
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
- exit 1
- ;;
-esac
-exit $RETVAL
diff --git a/matahari.service.in b/matahari.service.in
deleted file mode 100644
index 2a7a741..0000000
--- a/matahari.service.in
+++ /dev/null
@@ -1,18 +0,0 @@
-[Unit]
-Description=Matahari @BASE@@BASE_SUB@ daemon using the AMQP protocol.
-After=syslog.target network.target matahari-broker.service
-Requires=syslog.target network.target
-
-[Install]
-WantedBy=multi-user.target
-
-[Service]
-Type=simple
-NotifyAccess=main
-SysVStartPriority=99
-
-EnvironmentFile=-@sysconfdir@/sysconfig/matahari
-ExecStart=/usr/sbin/matahari-qmf-@BASE@@BASE_SUB@d $MATAHARI_@DAEMON_TYPE@_ARGS $@BASE@_@DAEMON_TYPE@_ARGS
-
-# Restart options include: no, on-success, on-failure, on-abort or always
-Restart=on-failure
diff --git a/matahari.sysconf.in b/matahari.sysconf.in
deleted file mode 100644
index e84e0cc..0000000
--- a/matahari.sysconf.in
+++ /dev/null
@@ -1,24 +0,0 @@
-# Connect to a broker on the named host
-# If this is not defined, agents will attempt to connect to the server specified
-# by the _matahari._tcp SRV record in DNS if that exists, otherwise to localhost
-MATAHARI_BROKER=@MATAHARI_BROKER@
-
-# Connect to a broker on a non-standard port
-#MATAHARI_PORT=@MATAHARI_PORT@
-
-# Other options that all agents should observe
-MATAHARI_AGENT_ARGS="--reconnect=yes"
-
-# SSL client options
-#QPID_SSL_CERT_DB=
-#QPID_SSL_CERT_PASSWORD_FILE=
-
-# Other options that all consoles should observe
-#MATAHARI_CONSOLE_ARGS=
-
-# Per agent options
-#host_AGENT_ARGS=
-#network_AGENT_ARGS=
-
-# Per console options
-#sysconfig_CONSOLE_ARGS=
diff --git a/src/broker/CMakeLists.txt b/src/broker/CMakeLists.txt
index d6e4728..07ddbef 100644
--- a/src/broker/CMakeLists.txt
+++ b/src/broker/CMakeLists.txt
@@ -19,6 +19,21 @@ if(NOT WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE}.gz
DESTINATION share/man/man${AGENT_MAN_SECTION})
+ configure_file(${CMAKE_SOURCE_DIR}/sys/matahari-broker.init.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.init @ONLY)
+
+ install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.init
+ DESTINATION ${initdir} RENAME matahari-broker)
+
+ pkg_check_modules(systemd systemd)
+
+ if(systemd_FOUND)
+ configure_file(${CMAKE_SOURCE_DIR}/sys/matahari-broker.service.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.service)
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.service DESTINATION ${systemdunitdir})
+ endif(systemd_FOUND)
+
endif(NOT WIN32)
endif(WITH-QMF)
diff --git a/src/cmake/modules/MatahariMacros.cmake b/src/cmake/modules/MatahariMacros.cmake
index 232799f..d0b5af4 100644
--- a/src/cmake/modules/MatahariMacros.cmake
+++ b/src/cmake/modules/MatahariMacros.cmake
@@ -121,12 +121,12 @@ endmacro(create_manpage)
macro(create_service_scripts BASE)
if(NOT WIN32)
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
+ configure_file(${CMAKE_SOURCE_DIR}/sys/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
endif(NOT WIN32)
if(systemd_FOUND)
- configure_file(${CMAKE_SOURCE_DIR}/matahari.service.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE}.service)
+ configure_file(${CMAKE_SOURCE_DIR}/sys/matahari.service.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE}.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE}.service DESTINATION ${systemdunitdir})
endif(systemd_FOUND)
endmacro(create_service_scripts)
diff --git a/src/unittests/.gitignore b/src/unittests/.gitignore
index ef1880e..dac5325 100644
--- a/src/unittests/.gitignore
+++ b/src/unittests/.gitignore
@@ -1,2 +1,5 @@
# Note that directives from the parent .gitignore files will be inherited
testhostapis
+libmh_tester.so
+*_unittest.cpp
+*_unittest
diff --git a/sys/.gitignore b/sys/.gitignore
new file mode 100644
index 0000000..29916b3
--- /dev/null
+++ b/sys/.gitignore
@@ -0,0 +1,5 @@
+# Note that directives from the root .gitignore file will be inherited
+*.sysconf
+*.conf
+*.init
+*.service
diff --git a/sys/CMakeLists.txt b/sys/CMakeLists.txt
new file mode 100644
index 0000000..babd6e4
--- /dev/null
+++ b/sys/CMakeLists.txt
@@ -0,0 +1,71 @@
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-broker.conf.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.conf @ONLY)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-broker.sysconf.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.sysconf @ONLY)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari.sysconf.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari.sysconf @ONLY)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-host.init.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-host.init @ONLY)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-guest.init.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-guest.init @ONLY)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy.sysconf.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy.sysconf @ONLY)
+
+install(DIRECTORY DESTINATION ${localstatedir}/lib/matahari
+ DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_WRITE GROUP_EXECUTE)
+
+
+install(CODE "execute_process(COMMAND chown root:qpidd ${localstatedir}/lib/matahari)")
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari.sysconf
+ DESTINATION ${sysconfdir}/sysconfig RENAME matahari)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.sysconf
+ DESTINATION ${sysconfdir}/sysconfig RENAME matahari-broker)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.conf
+ DESTINATION ${sysconfdir})
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy.sysconf
+ DESTINATION ${sysconfdir}/sysconfig RENAME matahari-vios-proxy)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-host.init
+ DESTINATION ${initdir} RENAME matahari-vios-proxy-host)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-guest.init
+ DESTINATION ${initdir} RENAME matahari-vios-proxy-guest)
+
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/matahari-guest-agent.rules
+ DESTINATION ${sysconfdir}/udev/rules.d
+ RENAME 99-matahari-guest-agent.rules)
+
+
+# Check for systemd
+include(FindPkgConfig)
+pkg_check_modules(systemd systemd)
+
+if(systemd_FOUND)
+ set(systemdunitdir "/lib/systemd/system")
+
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-host.service.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-host.service)
+
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy-guest.service.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-guest.service)
+
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-host.service
+ DESTINATION ${systemdunitdir})
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy-guest.service
+ DESTINATION ${systemdunitdir})
+
+endif(systemd_FOUND)
+
diff --git a/sys/matahari-broker.conf.in b/sys/matahari-broker.conf.in
new file mode 100644
index 0000000..da050c0
--- /dev/null
+++ b/sys/matahari-broker.conf.in
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# Configuration file for qpidd. Entries are of the form:
+# name=value
+#
+# (Note: no spaces on either side of '='). Using default settings:
+# "qpidd --help" or "man qpidd" for more details.
+cluster-mechanism=ANONYMOUS
+auth=no
diff --git a/sys/matahari-broker.init.in b/sys/matahari-broker.init.in
new file mode 100755
index 0000000..0f03b44
--- /dev/null
+++ b/sys/matahari-broker.init.in
@@ -0,0 +1,120 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+# matahari-broker Startup script for the Qpid messaging daemon.
+#
+
+### BEGIN INIT INFO
+# Provides: matahari-broker
+# Required-Start: $local_fs
+# Required-Stop: $local_fs
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Should-Start: matahari-vios-proxy-guest
+# Short-Description: start or stop matahari broker
+# Description: Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
+### END INIT INFO
+
+# chkconfig: - 85 15
+# description: Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
+# processname: qpidd
+
+prog="matahari-brokerd --pid-dir @localstatedir@/run/matahari"
+proc=qpidd
+lockfile=@localstatedir@/lock/subsys/matahari-broker
+pidfile=@localstatedir(a)/run/matahari-broker.pid
+
+# Turn off automatic systemd redirects
+#SYSTEMCTL_SKIP_REDIRECT=1
+
+# Source function library.
+. @sysconfdir(a)/rc.d/init.d/functions
+
+if [ -f @sysconfdir@/sysconfig/matahari ]; then
+ . @sysconfdir@/sysconfig/matahari
+fi
+if [ -f @sysconfdir@/sysconfig/matahari-broker ]; then
+ . @sysconfdir@/sysconfig/matahari-broker
+fi
+
+if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
+ . @sysconfdir@/sysconfig/matahari-vios-proxy
+fi
+
+RETVAL=0
+
+start() {
+ echo -n $"Starting Matahari broker daemon: "
+ install -o root -g qpidd -m 775 -d @localstatedir@/run/matahari
+ daemon --pidfile $pidfile --check $proc --user qpidd /usr/sbin/$prog $QPIDD_OPTIONS --daemon
+ RETVAL=$?
+ echo
+ [ $RETVAL = 0 ] && touch $lockfile
+ if [ $RETVAL = 0 ]; then
+ touch $pidfile
+ chown qpidd.qpidd $pidfile
+ [ -x /sbin/restorecon ] && /sbin/restorecon $pidfile
+ runuser -s /bin/sh qpidd -c "/usr/sbin/$prog --check > $pidfile"
+ fi
+ return $RETVAL
+}
+
+stop() {
+ echo -n $"Stopping Matahari broker daemon: "
+ killproc -p $pidfile $proc
+ RETVAL=$?
+ echo
+ [ $RETVAL = 0 ] && rm -f $lockfile $pidfile
+}
+
+reload() {
+ echo 1>&2 $"$0: reload not supported"
+ exit 3
+}
+
+restart() {
+ stop
+ start
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ status -p $pidfile -l $lockfile $proc >/dev/null || $1
+ ;;
+ stop|restart|reload)
+ $1
+ ;;
+ status)
+ status -p $pidfile -l $lockfile $proc
+ RETVAL=$?
+ ;;
+ force-reload)
+ restart
+ ;;
+ try-restart|condrestart)
+ [ -e $lockfile ] && restart || :
+ ;;
+ *)
+ echo 1>&2 $"Usage: $0 {start|stop|restart|condrestart|status}"
+ exit 1
+esac
+
+exit $RETVAL
diff --git a/sys/matahari-broker.service.in b/sys/matahari-broker.service.in
new file mode 100644
index 0000000..5f28f48
--- /dev/null
+++ b/sys/matahari-broker.service.in
@@ -0,0 +1,23 @@
+[Unit]
+Description=Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
+After=syslog.target network.target matahari-vios-proxy-guest.service
+Requires=syslog.target network.target
+
+[Install]
+WantedBy=multi-user.target
+
+[Service]
+Type=simple
+NotifyAccess=all
+SysVStartPriority=85
+User=qpidd
+Group=qpidd
+
+EnvironmentFile=-@sysconfdir@/sysconfig/matahari
+EnvironmentFile=-@sysconfdir@/sysconfig/matahari-broker
+EnvironmentFile=-@sysconfdir@/sysconfig/matahari-vios-proxy
+
+ExecStart=/usr/sbin/matahari-brokerd $QPIDD_OPTIONS
+
+# Restart options include: no, on-success, on-failure, on-abort or always
+Restart=on-failure
diff --git a/sys/matahari-broker.sysconf.in b/sys/matahari-broker.sysconf.in
new file mode 100644
index 0000000..cd3d942
--- /dev/null
+++ b/sys/matahari-broker.sysconf.in
@@ -0,0 +1,21 @@
+# Override the broker port set in @sysconfdir@/sysconfig/matahari
+#MATAHARI_PORT=@MATAHARI_PORT@
+
+QPIDD_OPTIONS="--config @sysconfdir(a)/matahari-broker.conf"
+
+# Federated Broker configuration - list the brokers to federate with
+# The following formats are allowed:
+# Hostname and port
+# <fqdn>:<port>
+# amqp:tcp:<fqdn>:<port>
+# amqp:ssl:<fqdn>:<port>
+# DNS SRV query format ("_matahari._<protocol>" is REQUIRED)
+# _matahari._tcp.<fqdn>
+# _matahari._tls.<fqdn>
+#
+# Note that only the first (highest priority) SRV record returned by the DNS
+# for each given query will be used.
+#
+# Addresses need not all be in the same format.
+#FEDERATED_BROKERS="broker1.example.com:49000, _matahari._tcp.example.com"
+
diff --git a/sys/matahari-guest-agent.rules b/sys/matahari-guest-agent.rules
new file mode 100644
index 0000000..8cfacee
--- /dev/null
+++ b/sys/matahari-guest-agent.rules
@@ -0,0 +1,2 @@
+SUBSYSTEM=="virtio-ports", ATTR{name}}=="org.matahariproject.vios_proxy.0", \
+ TAG+="systemd" ENV{SYSTEMD_WANTS}="matahari-vios-proxy-guest.service"
diff --git a/sys/matahari-vios-proxy-guest.init.in b/sys/matahari-vios-proxy-guest.init.in
new file mode 100644
index 0000000..c85f712
--- /dev/null
+++ b/sys/matahari-vios-proxy-guest.init.in
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+# the following is chkconfig init header
+# matahari-vios-proxy-guest: Initscript for Matahari specific vios-proxy
+### BEGIN INIT INFO
+# Provides:
+# Required-Start: $local_fs matahari-broker
+# Required-Stop: $local_fs matahari-broker
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Starts and stops vios proxy guest daemon
+# Description: Matahari initscript for Vios Proxy Guest
+### END INIT INFO
+
+# chkconfig: - 99 01
+# description: Matahari initscript for Vios Proxy Guest
+# processname: matahari-vios-proxy-guest
+# pidfile: @localstatedir(a)/run/matahari-vios-proxy-guest.pid
+#
+
+# Turn off automatic systemd redirects
+#SYSTEMCTL_SKIP_REDIRECT=1
+
+# Source function library.
+. @sysconfdir(a)/rc.d/init.d/functions
+
+PROCESS=vios-proxy-guest
+
+RETVAL=0
+
+# Source function library.
+. @sysconfdir(a)/rc.d/init.d/functions
+
+if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
+ . @sysconfdir@/sysconfig/matahari
+fi
+
+start() {
+ echo -n $"Starting the $PROCESS daemon: "
+
+ daemon $PROCESS $VP_H_GUEST_DIR $VP_H_SERVICE_DIR
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$PROCESS
+}
+
+stop() {
+ echo -n $"Stopping the $PROCESS daemon: "
+
+ killproc $PROCESS
+ RETVAL=$?
+ echo
+ if [ $RETVAL -eq 0 ]; then
+ rm -f @localstatedir@/lock/subsys/$PROCESS
+ rm -f @localstatedir(a)/run/$PROCESS.pid
+ fi
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ echo -n $"Reloading the $PROCESS configuration: "
+
+ killproc $PROCESS -HUP
+ RETVAL=$?
+ echo
+ return $RETVAL
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ status $PROCESS >/dev/null || $1
+ ;;
+ stop|restart|reload)
+ $1
+ ;;
+ status)
+ status $PROCESS
+ RETVAL=$?
+ ;;
+ force-reload)
+ reload
+ ;;
+ condrestart|try-restart)
+ [ -f @localstatedir@/lock/subsys/$PROCESS ] && restart || :
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
+ exit 1
+ ;;
+esac
+exit $RETVAL
diff --git a/sys/matahari-vios-proxy-guest.service.in b/sys/matahari-vios-proxy-guest.service.in
new file mode 100644
index 0000000..b1ec32d
--- /dev/null
+++ b/sys/matahari-vios-proxy-guest.service.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=Matahari Vios Proxy Guest
+BindTo=dev-virtio\x2dports-org.matahariproject.vios_proxy.0.device
+After=dev-virtio\x2dports-org.matahariproject.vios_proxy.0.device
+
+[Service]
+EnvironmentFile=@sysconfdir@/sysconfig/matahari-vios-proxy
+ExecStart=-/usr/bin/vios-proxy-guest $VP_G_HOST_DIR $VP_G_SERVICE_PORT
+Restart=always
+RestartSec=0
+
+[Install]
diff --git a/sys/matahari-vios-proxy-host.init.in b/sys/matahari-vios-proxy-host.init.in
new file mode 100644
index 0000000..098b9bd
--- /dev/null
+++ b/sys/matahari-vios-proxy-host.init.in
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+# the following is chkconfig init header
+# matahari-vios-proxy-host: Initscript for Matahari specific vios-proxy
+### BEGIN INIT INFO
+# Provides:
+# Required-Start: $local_fs matahari-broker
+# Required-Stop: $local_fs matahari-broker
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Starts and stops vios proxy host daemon
+# Description: Matahari initscript for Vios Proxy Host
+### END INIT INFO
+
+# chkconfig: - 99 01
+# description: Matahari initscript for Vios Proxy Host
+# processname: matahari-vios-proxy-host
+# pidfile: @localstatedir(a)/run/matahari-vios-proxy-host.pid
+#
+
+# Turn off automatic systemd redirects
+#SYSTEMCTL_SKIP_REDIRECT=1
+
+# Source function library.
+. @sysconfdir(a)/rc.d/init.d/functions
+
+PROCESS=vios-proxy-host
+
+RETVAL=0
+
+# Source function library.
+. @sysconfdir(a)/rc.d/init.d/functions
+
+if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
+ . @sysconfdir@/sysconfig/matahari
+fi
+
+start() {
+ echo -n $"Starting the $PROCESS daemon: "
+
+ daemon $PROCESS $VP_H_GUEST_DIR $VP_H_SERVICE_DIR
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$PROCESS
+}
+
+stop() {
+ echo -n $"Stopping the $PROCESS daemon: "
+
+ killproc $PROCESS
+ RETVAL=$?
+ echo
+ if [ $RETVAL -eq 0 ]; then
+ rm -f @localstatedir@/lock/subsys/$PROCESS
+ rm -f @localstatedir(a)/run/$PROCESS.pid
+ fi
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ echo -n $"Reloading the $PROCESS configuration: "
+
+ killproc $PROCESS -HUP
+ RETVAL=$?
+ echo
+ return $RETVAL
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ status $PROCESS >/dev/null || $1
+ ;;
+ stop|restart|reload)
+ $1
+ ;;
+ status)
+ status $PROCESS
+ RETVAL=$?
+ ;;
+ force-reload)
+ reload
+ ;;
+ condrestart|try-restart)
+ [ -f @localstatedir@/lock/subsys/$PROCESS ] && restart || :
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
+ exit 1
+ ;;
+esac
+exit $RETVAL
diff --git a/sys/matahari-vios-proxy-host.service.in b/sys/matahari-vios-proxy-host.service.in
new file mode 100644
index 0000000..aa4a77d
--- /dev/null
+++ b/sys/matahari-vios-proxy-host.service.in
@@ -0,0 +1,21 @@
+[Unit]
+Description=Matahari specific requirements for a Vios proxy host
+After=syslog.target
+Requires=syslog.target
+
+[Install]
+WantedBy=multi-user.target
+
+[Service]
+Type=simple
+NotifyAccess=all
+SysVStartPriority=85
+User=root
+Group=root
+
+EnvironmentFile=@sysconfdir@/sysconfig/matahari-vios-proxy
+
+ExecStart=/usr/bin/vios-proxy-host $VP_H_GUEST_DIR $VP_H_SERVICE_PORT
+
+# Restart options include: no, on-success, on-failure, on-abort or always
+Restart=on-failure
diff --git a/sys/matahari-vios-proxy.sysconf.in b/sys/matahari-vios-proxy.sysconf.in
new file mode 100644
index 0000000..abe83c0
--- /dev/null
+++ b/sys/matahari-vios-proxy.sysconf.in
@@ -0,0 +1,7 @@
+# VIOS Proxy Host configuration
+VP_H_GUEST_DIR=/var/lib/libvirt
+VP_H_SERVICE_PORT=49000
+
+# VIOS Proxy Guest configuration
+VP_G_HOST_DIR=/dev/virtio-ports
+VP_G_SERVICE_PORT=48999
diff --git a/sys/matahari.init.in b/sys/matahari.init.in
new file mode 100644
index 0000000..18bd572
--- /dev/null
+++ b/sys/matahari.init.in
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+# the following is chkconfig init header
+# matahari-@BASE@@BASE_SUB@: Matahari QMF @BASE@@BASE_SUB@ daemon
+### BEGIN INIT INFO
+# Provides: matahari-@BASE@@BASE_SUB@
+# Required-Start: $local_fs
+# Required-Stop: $local_fs
+# Should-Start: matahari-broker
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Starts and stops the @BASE@@BASE_SUB@ matahari daemon
+# Description: Matahari @BASE@@BASE_SUB@ daemon using the AMQP protocol.
+### END INIT INFO
+
+# chkconfig: - 99 01
+# description: Matahari @BASE@@BASE_SUB@ daemon using the AMQP protocol.
+# processname: matahari-@BASE@@BASE_SUB@d
+# pidfile: @localstatedir@/run/matahari-@BASE@@BASE_SUB@.pid
+#
+
+# Turn off automatic systemd redirects
+#SYSTEMCTL_SKIP_REDIRECT=1
+
+# Source function library.
+. @sysconfdir(a)/rc.d/init.d/functions
+
+SERVICE=matahari-@BASE@@BASE_SUB@
+PROCESS=matahari-qmf-@BASE@@BASE_SUB@d
+# Old process naming convention, this is here
+# for compability sake when starting/stopping the
+# service from an upgrade of 0.4.0 > 0.4.2
+OLDPROCESS=matahari-@BASE@@BASE_SUB@d
+
+RETVAL=0
+
+test -f @sysconfdir@/sysconfig/matahari && . @sysconfdir@/sysconfig/matahari
+
+start() {
+ echo -n $"Starting the $SERVICE daemon: "
+
+ MATAHARI_ARGS="$MATAHARI_@DAEMON_TYPE@_ARGS $@BASE@_@DAEMON_TYPE@_ARGS"
+ if [ -n "$MATAHARI_PORT" ]; then
+ MATAHARI_ARGS="--port $MATAHARI_PORT $MATAHARI_ARGS"
+ fi
+ if [ -n "$MATAHARI_BROKER" ]; then
+ MATAHARI_ARGS="--broker $MATAHARI_BROKER $MATAHARI_ARGS"
+ fi
+
+
+ export QPID_SSL_CERT_DB
+ export QPID_SSL_CERT_PASSWORD_FILE
+
+ daemon $PROCESS $MATAHARI_ARGS --daemon
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$SERVICE
+}
+
+stop() {
+ echo -n $"Stopping the $SERVICE daemon: "
+
+ # Check for OLDPROCESS for pre 0.4.2 compat
+ pidofproc $OLDPROCESS >/dev/null
+ RETVAL=$?
+ if [ $RETVAL -lt 3 ]; then
+ killproc $OLDPROCESS
+ RETVAL=$?
+ else
+ killproc $PROCESS
+ RETVAL=$?
+ fi
+ echo
+ if [ $RETVAL -eq 0 ]; then
+ rm -f @localstatedir@/lock/subsys/$SERVICE
+ rm -f @localstatedir(a)/run/$SERVICE.pid
+ fi
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ echo -n $"Reloading the $SERVICE configuration: "
+
+ killproc $PROCESS -HUP
+ RETVAL=$?
+ echo
+ return $RETVAL
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ status $PROCESS >/dev/null || $1
+ ;;
+ stop|restart|reload)
+ $1
+ ;;
+ status)
+ status $PROCESS
+ RETVAL=$?
+ ;;
+ force-reload)
+ reload
+ ;;
+ condrestart|try-restart)
+ [ -f @localstatedir@/lock/subsys/$SERVICE ] && restart || :
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
+ exit 1
+ ;;
+esac
+exit $RETVAL
diff --git a/sys/matahari.service.in b/sys/matahari.service.in
new file mode 100644
index 0000000..2a7a741
--- /dev/null
+++ b/sys/matahari.service.in
@@ -0,0 +1,18 @@
+[Unit]
+Description=Matahari @BASE@@BASE_SUB@ daemon using the AMQP protocol.
+After=syslog.target network.target matahari-broker.service
+Requires=syslog.target network.target
+
+[Install]
+WantedBy=multi-user.target
+
+[Service]
+Type=simple
+NotifyAccess=main
+SysVStartPriority=99
+
+EnvironmentFile=-@sysconfdir@/sysconfig/matahari
+ExecStart=/usr/sbin/matahari-qmf-@BASE@@BASE_SUB@d $MATAHARI_@DAEMON_TYPE@_ARGS $@BASE@_@DAEMON_TYPE@_ARGS
+
+# Restart options include: no, on-success, on-failure, on-abort or always
+Restart=on-failure
diff --git a/sys/matahari.sysconf.in b/sys/matahari.sysconf.in
new file mode 100644
index 0000000..e84e0cc
--- /dev/null
+++ b/sys/matahari.sysconf.in
@@ -0,0 +1,24 @@
+# Connect to a broker on the named host
+# If this is not defined, agents will attempt to connect to the server specified
+# by the _matahari._tcp SRV record in DNS if that exists, otherwise to localhost
+MATAHARI_BROKER=@MATAHARI_BROKER@
+
+# Connect to a broker on a non-standard port
+#MATAHARI_PORT=@MATAHARI_PORT@
+
+# Other options that all agents should observe
+MATAHARI_AGENT_ARGS="--reconnect=yes"
+
+# SSL client options
+#QPID_SSL_CERT_DB=
+#QPID_SSL_CERT_PASSWORD_FILE=
+
+# Other options that all consoles should observe
+#MATAHARI_CONSOLE_ARGS=
+
+# Per agent options
+#host_AGENT_ARGS=
+#network_AGENT_ARGS=
+
+# Per console options
+#sysconfig_CONSOLE_ARGS=
12 years, 6 months
Matahari 0.5.0 Released
by Russell Bryant
Greetings,
The Matahari development team has released version 0.5.0. It is
available for download from the github downloads area:
https://github.com/matahari/matahari/downloads/matahari-0.5.0.tar.gz
This release contains a number of bug fixes and enhancements. Some of
the enhancements are:
* Host API UUIDs
The Host::get_uuid() and Host::set_uuid() APIs are now implemented
on Windows. The agent also now supports getting the Amazon EC2
instance ID.
* Augeas support in Sysconfig agent
The Sysconfig agent now supports using augeas for reading and
writing configuration files.
* D-bus Sysconfig Agent
There is now a D-bus agent that exposes the Sysconfig APIs in
addition to the existing QMF agent.
* Vios-proxy integration
Matahari now includes integration with vios-proxy to make it easier
to have the matahari broker on a guest federate with a broker on the
host over virtio-serial.
* SSL support for QMF Agents
SSL is now supported for all of the QMF agents.
* Systemd support in the Services agent
The services agent now knows how to control services on a system
that is using systemd. This is in addition to knowing how to run
LSB style init scripts and OCF resource agents.
Thanks,
--
Russell Bryant
12 years, 6 months
[PATCH] host: Add power management functionality
by Radek Novacek
Functions for listing, setting and getting power management profiles for
the host agent, including unittest. Based on patch by
Jaroslav Skarvada <jskarvad(a)redhat.com>
I didn't test it on windows, because I don't have windows machine around.
Please someone test it.
Signed-off-by: Radek Novacek <rnovacek(a)redhat.com>
---
matahari.spec.in | 2 +
src/host/host-dbus.c | 79 +++++++++++
src/host/host-qmf.cpp | 31 ++++
src/host/org.matahariproject.Host.policy | 21 +++
src/host/schema.xml | 12 ++
src/include/matahari/host.h | 12 ++
src/lib/host.c | 18 +++
src/lib/host_linux.c | 227 ++++++++++++++++++++++++++++++
src/lib/host_private.h | 27 ++++
src/lib/host_windows.c | 209 +++++++++++++++++++++++++++
src/unittests/mh_api_host.h | 37 +++++
11 files changed, 675 insertions(+), 0 deletions(-)
diff --git a/matahari.spec.in b/matahari.spec.in
index 68404df..9615db8 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -154,6 +154,8 @@ Requires: %{name}-agent-lib = %{version}-%{release}
%ifarch i386 x86_64
Requires: dmidecode
%endif
+# Power management functions in host agent require tuned
+Requires: tuned
%description host
QMF agent for viewing and controlling remote hosts
diff --git a/src/host/host-dbus.c b/src/host/host-dbus.c
index 05b25f3..19a7c57 100644
--- a/src/host/host-dbus.c
+++ b/src/host/host-dbus.c
@@ -119,6 +119,85 @@ Host_set_uuid(Matahari* matahari, const char *lifetime, const char *uuid, DBusGM
return TRUE;
}
+gboolean
+Host_set_power_profile(Matahari* matahari, const char *profile, DBusGMethodInvocation *context)
+{
+ GError *error = NULL;
+ enum mh_result res;
+
+ if (!check_authorization(HOST_BUS_NAME ".set_profile", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ g_error_free(error);
+ return FALSE;
+ }
+ res = mh_host_set_power_profile(profile);
+ if (res != MH_RES_SUCCESS) {
+ error = g_error_new(MATAHARI_ERROR, res, mh_result_to_str(res));
+ dbus_g_method_return_error(context, error);
+ g_error_free(error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, 0);
+ return TRUE;
+}
+
+gboolean
+Host_get_power_profile(Matahari* matahari, DBusGMethodInvocation *context)
+{
+ char *profile = NULL;
+ GError *error = NULL;
+ enum mh_result res;
+
+ if (!check_authorization(HOST_BUS_NAME ".get_profile", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ g_error_free(error);
+ return FALSE;
+ }
+ res = mh_host_get_power_profile(&profile);
+ if (res != MH_RES_SUCCESS) {
+ error = g_error_new(MATAHARI_ERROR, res, mh_result_to_str(res));
+ dbus_g_method_return_error(context, error);
+ g_error_free(error);
+ return FALSE;
+ }
+ dbus_g_method_return(context, profile);
+ free(profile);
+ return TRUE;
+}
+
+gboolean
+Host_list_power_profiles(Matahari* matahari, DBusGMethodInvocation *context)
+{
+ GError *error = NULL;
+ GList *list, *plist;
+ char **profiles;
+ int i = 0;
+
+ if (!check_authorization(HOST_BUS_NAME ".list_profiles", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ g_error_free(error);
+ return FALSE;
+ }
+ // Get the list of profiles
+ list = mh_host_list_power_profiles();
+
+ // Convert GList * with profiles to array (char **)
+ profiles = g_new(char *, g_list_length(list) + 1);
+ for (plist = g_list_first(list);
+ plist;
+ plist = g_list_next(plist)) {
+ profiles[i++] = plist->data;
+ }
+ profiles[i] = NULL; // Sentinel
+
+ dbus_g_method_return(context, profiles);
+ g_list_free_full(list, free);
+ g_free(profiles);
+ return TRUE;
+}
+
+
/* Generated dbus stuff for host
* MUST be after declaration of user defined functions.
*/
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index 618cf9c..4b72d00 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -112,6 +112,7 @@ HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
return TRUE;
}
+ enum mh_result res = MH_RES_SUCCESS;
const std::string& methodName(event.getMethodName());
qpid::types::Variant::Map& args = event.getArguments();
@@ -153,7 +154,37 @@ HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
if (uuid) {
event.addReturnArgument("uuid", uuid);
}
+ } else if (methodName == "set_power_profile") {
+ res = mh_host_set_power_profile(args["profile"].asString().c_str());
+ if (res != MH_RES_SUCCESS) {
+ session.raiseException(event, mh_result_to_str(res));
+ goto bail;
+ } else {
+ event.addReturnArgument("status", 0);
+ }
+ } else if (methodName == "get_power_profile") {
+ char *profile = NULL;
+ res = mh_host_get_power_profile(&profile);
+ if (res != MH_RES_SUCCESS) {
+ session.raiseException(event, mh_result_to_str(res));
+ goto bail;
+ } else {
+ event.addReturnArgument("profile", profile);
+ }
+ free(profile);
+ } else if (methodName == "list_power_profiles") {
+ GList *plist = NULL;
+ GList *profile_list = NULL;
+ _qtype::Variant::List s_list;
+
+ profile_list = mh_host_list_power_profiles();
+ for (plist = g_list_first(profile_list); plist;
+ plist = g_list_next(plist)) {
+ s_list.push_back((const char *) plist->data);
+ }
+ event.addReturnArgument("profiles", s_list);
+ g_list_free_full(profile_list, free);
} else {
session.raiseException(event, mh_result_to_str(MH_RES_NOT_IMPLEMENTED));
goto bail;
diff --git a/src/host/org.matahariproject.Host.policy b/src/host/org.matahariproject.Host.policy
index ed04a25..90636a8 100644
--- a/src/host/org.matahariproject.Host.policy
+++ b/src/host/org.matahariproject.Host.policy
@@ -200,4 +200,25 @@
<allow_active>auth_admin</allow_active>
</defaults>
</action>
+ <action id="org.matahariproject.Host.get_power_profile">
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Host.set_power_profile">
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Host.list_power_profiles">
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
</policyconfig>
diff --git a/src/host/schema.xml b/src/host/schema.xml
index cb179cf..6f1ac32 100644
--- a/src/host/schema.xml
+++ b/src/host/schema.xml
@@ -92,6 +92,18 @@
<arg name="rc" dir="O" type="int32" />
</method>
+ <method name="set_power_profile" desc="Set power management profile">
+ <arg name="profile" dir="I" type="sstr" />
+ <arg name="status" dir="O" type="uint32" />
+ </method>
+
+ <method name="get_power_profile" desc="Get current power management profile">
+ <arg name="profile" dir="O" type="sstr" />
+ </method>
+
+ <method name="list_power_profiles" desc="List available power management profiles">
+ <arg name="profiles" dir="O" type="list" />
+ </method>
</class>
<event name="heartbeat" args="timestamp,sequence,hostname,uuid" />
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index 1da756a..8f1cc61 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -28,6 +28,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <sigar.h>
+#include <glib.h>
+
+#include "matahari/errors.h"
/**
* Get a UUID for a host.
@@ -118,4 +121,13 @@ mh_host_get_load_averages(sigar_loadavg_t *avg);
void
mh_host_get_processes(sigar_proc_stat_t *procs);
+enum mh_result
+mh_host_set_power_profile(const char *profile);
+
+enum mh_result
+mh_host_get_power_profile(char **profile);
+
+GList *
+mh_host_list_power_profiles(void);
+
#endif // __MH_HOST_H__
diff --git a/src/lib/host.c b/src/lib/host.c
index 29cb654..66c5baf 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -311,3 +311,21 @@ mh_host_set_uuid(const char *lifetime, const char *uuid)
return G_FILE_ERROR_NOSYS;
}
+
+enum mh_result
+mh_host_set_power_profile(const char* profile)
+{
+ return host_os_set_power_profile(profile);
+}
+
+enum mh_result
+mh_host_get_power_profile(char **profile)
+{
+ return host_os_get_power_profile(profile);
+}
+
+GList *
+mh_host_list_power_profiles(void)
+{
+ return host_os_list_power_profiles();
+}
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 304592a..7be51b7 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -24,10 +24,12 @@
#include <limits.h>
#include <string.h>
#include <fcntl.h>
+#include <errno.h>
#include <sys/reboot.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <sys/ioctl.h>
+#include <sys/wait.h>
#include <linux/reboot.h>
#include <linux/kd.h>
@@ -45,6 +47,7 @@
#define UUID_STR_BUF_LEN 37
+#define BUFSIZE 4096
const char *
host_os_get_cpu_flags(void)
@@ -422,3 +425,227 @@ host_os_set_custom_uuid(const char *uuid)
return rc;
}
+static void
+read_output(int fd, char **data)
+{
+ int bytes = 0, len = 0;
+ char buf[BUFSIZE];
+
+ while ((((bytes = read(fd, buf, BUFSIZE - 1)) > 0) &&
+ (*data = realloc(*data, len + bytes + 1))) ||
+ errno == EINTR)
+ if (bytes > 0) {
+ buf[bytes] = 0;
+ mh_info("Read %d: %.*s", len, bytes, buf);
+ sprintf(*data + len, "%s", buf);
+ len += bytes;
+ }
+
+ mh_info("Read %d bytes", len);
+}
+
+static enum mh_result
+exec_command(const char *apath, char *args[], int atimeout, char **stdoutbuf,
+ char **stderrbuf)
+{
+ enum mh_result res = MH_RES_SUCCESS;
+ GPid pid = 0;
+ GError *gerr = NULL;
+ int status = 0;
+ int timeout = atimeout;
+ gint stdout_fd;
+ gint stderr_fd;
+
+ if (!args || !args[0])
+ return MH_RES_OTHER_ERROR;
+
+ mh_trace("Spawning '%s'\n", args[0]);
+ if (!g_spawn_async_with_pipes(apath, args, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL, NULL, &pid, NULL, &stdout_fd,
+ &stderr_fd, &gerr)) {
+ mh_perror(LOG_ERR, "Spawn_process failed with code %d, message: %s\n",
+ gerr->code, gerr->message);
+ return MH_RES_OTHER_ERROR;
+ }
+
+ mh_trace("Waiting for %d", pid);
+ while (timeout > 0 && waitpid(pid, &status, WNOHANG) <= 0) {
+ sleep(1);
+ timeout--;
+ }
+
+ if (timeout == 0) {
+ int killrc = sigar_proc_kill(pid, SIGKILL);
+
+ res = MH_RES_BACKEND_ERROR;
+ mh_warn("%d - timed out after %dms", pid, atimeout);
+
+ if (killrc != SIGAR_OK && killrc != ESRCH) {
+ mh_err("kill(%d, KILL) failed: %d", pid, killrc);
+ }
+
+ } else if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status) > 0)
+ res = MH_RES_BACKEND_ERROR;
+ mh_err("Managed process %d exited with rc=%d", pid, WEXITSTATUS(status));
+
+ } else if (WIFSIGNALED(status)) {
+ int signo = WTERMSIG(status);
+ res = MH_RES_BACKEND_ERROR;
+ mh_err("Managed process %d exited with signal=%d", pid, signo);
+ }
+
+ mh_trace("Child done: %d", pid);
+
+ read_output(stdout_fd, stdoutbuf);
+ read_output(stderr_fd, stderrbuf);
+
+ if (*stdoutbuf)
+ mh_debug("stdout: %s", *stdoutbuf);
+ if (*stderrbuf)
+ mh_debug("stderr: %s", *stderrbuf);
+
+ close(stdout_fd);
+ close(stderr_fd);
+
+ g_spawn_close_pid(pid);
+
+ return res;
+}
+
+GList *
+host_os_list_power_profiles(void)
+{
+ char *stdoutbuf = NULL;
+ char *stderrbuf = NULL;
+ char *c1, *c2;
+ char *args[3] = {0};
+ int cnt = 0;
+ GList *list = NULL;
+ enum mh_result res;
+
+ args[0] = TUNEDADM;
+ args[1] = TA_LISTPROFILES;
+ args[2] = NULL;
+
+ res = exec_command(NULL, args, TIMEOUT, &stdoutbuf, &stderrbuf);
+ if (res == MH_RES_SUCCESS && stdoutbuf) {
+ c1 = stdoutbuf;
+ do {
+ if (*c1 == '-') {
+ c2 = strchr(c1++, '\n');
+ if (c2 > c1) {
+ *c2 = 0;
+ list = g_list_append(list, strdup(++c1));
+ *c2 = '\n';
+ cnt++;
+ }
+ }
+ c2 = strchr(c1, '\n');
+ if (c2)
+ c1 = ++c2;
+ }
+ while (c2 && c1 - stdoutbuf < strlen(stdoutbuf));
+
+ if (cnt)
+ list = g_list_append(list, strdup(TA_OFF));
+ }
+
+ free(stdoutbuf);
+ free(stderrbuf);
+
+ return list;
+}
+
+static gboolean
+check_profile(const char *profile)
+{
+ GList *list = NULL;
+ GList *llist;
+ gboolean rc = FALSE;
+
+ if (!(list = host_os_list_power_profiles()))
+ return FALSE;
+
+ if (!g_list_length(list))
+ return FALSE;
+
+ for (llist = g_list_first(list); llist && !rc; llist = g_list_next(llist)) {
+ mh_trace("comparing '%s' with '%s'", (char *) llist->data, profile);
+ if (!strcmp(profile, (char *) llist->data)) {
+ rc = TRUE;
+ break;
+ }
+ }
+ g_list_free_full(list, free);
+
+ return rc;
+}
+
+enum mh_result
+host_os_set_power_profile(const char *profile)
+{
+ char *stdoutbuf = NULL;
+ char *stderrbuf = NULL;
+ char *args[4] = {0};
+ enum mh_result res;
+
+ args[0] = TUNEDADM;
+ if (!profile)
+ return MH_RES_INVALID_ARGS;
+
+ if (!strcmp(profile, TA_OFF)) {
+ args[1] = TA_OFF;
+ mh_trace("switching tuning off");
+ } else {
+ if (!check_profile(profile)) {
+ mh_err("invalid profile: %s", profile);
+ return MH_RES_INVALID_ARGS;
+ }
+ args[1] = TA_SETPROFILE;
+ mh_trace("setting profile: %s", profile);
+ }
+
+ args[2] = (char *) profile;
+ args[3] = NULL;
+
+ res = exec_command(NULL, args, TIMEOUT, &stdoutbuf, &stderrbuf);
+
+ free(stdoutbuf);
+ free(stderrbuf);
+
+ return res;
+}
+
+enum mh_result
+host_os_get_power_profile(char **profile)
+{
+ char *stdoutbuf = NULL;
+ char *stderrbuf = NULL;
+ char *c1, *c2;
+ char *args[3] = {0};
+ enum mh_result res;
+
+ args[0] = TUNEDADM;
+ args[1] = TA_GETPROFILE;
+ args[2] = NULL;
+
+ res = exec_command(NULL, args, TIMEOUT, &stdoutbuf, &stderrbuf);
+ if (res == MH_RES_SUCCESS) {
+ if (stdoutbuf && strlen(stdoutbuf) && (c1 = strchr(stdoutbuf, ':')) &&
+ (++c1 - stdoutbuf < strlen(stdoutbuf))) {
+ if ((c2 = strchr(stdoutbuf, '\n')))
+ *c2 = 0;
+ *profile = strdup(++c1);
+ }
+ else
+ *profile = strdup(STR_UNK);
+ }
+ else
+ res = MH_RES_BACKEND_ERROR;
+
+ free(stdoutbuf);
+ free(stderrbuf);
+
+ return res;
+}
diff --git a/src/lib/host_private.h b/src/lib/host_private.h
index c2f7a1b..b71cf3c 100644
--- a/src/lib/host_private.h
+++ b/src/lib/host_private.h
@@ -31,6 +31,24 @@
#include <glib.h>
+#define TIMEOUT 10
+#define TA_PATH "/usr/bin/"
+#define TA_SETPROFILE "profile"
+#define TA_GETPROFILE "active"
+#define TA_LISTPROFILES "list"
+#define TA_OFF "off"
+#define TUNEDADM TA_PATH "tuned-adm"
+
+#define SYSTEM32 "system32"
+#define POWERCFG "powercfg"
+#define PC_SETPROFILE "-SETACTIVE"
+#define PC_GETPROFILE "-GETACTIVESCHEME"
+#define PC_LISTPROFILES "-LIST"
+
+#define STR_UNK "UNKNOWN"
+#define STR_ERR "ERROR"
+
+
const char *
host_os_get_cpu_flags(void);
@@ -67,4 +85,13 @@ host_os_agent_uuid(void);
int
host_os_set_custom_uuid(const char *uuid);
+enum mh_result
+host_os_set_power_profile(const char *profile);
+
+enum mh_result
+host_os_get_power_profile(char **profile);
+
+GList *
+host_os_list_power_profiles(void);
+
#endif /* __MH_HOST_PRIVATE_H__ */
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index f53567c..10bf5be 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -33,12 +33,15 @@
#include "matahari/logging.h"
#include "matahari/host.h"
+#include "matahari/errors.h"
#include "host_private.h"
static const char CUSTOM_UUID_KEY[] = "CustomUUID";
static const char REBOOT_UUID_KEY[] = "RebootUUID";
+#define BUFSIZE 4096
+
const char *
host_os_get_cpu_flags(void)
{
@@ -394,3 +397,209 @@ host_os_set_custom_uuid(const char *uuid)
return ret;
}
+
+static void
+read_output(gint h, char **data)
+{
+ int len = 0;
+ int bytes = 0;
+ char buf[BUFSIZE];
+
+ while ((bytes = _read(h, buf, BUFSIZE - 1)) > 0 &&
+ (*data = realloc(*data, len + bytes + 1)))
+ {
+ buf[bytes] = 0;
+ mh_info("Read %d: %.*s", len, bytes, buf);
+ sprintf(*data + len, "%s", buf);
+ len += bytes;
+ }
+
+ mh_info("Read %d bytes", len);
+}
+
+static enum mh_result
+exec_command(const char *apath, char *args[], int atimeout, char **stdoutbuf,
+ char **stderrbuf)
+{
+ enum mh_result res = MH_RES_SUCCESS;
+ DWORD status = 0;
+ gint stdout_fd;
+ gint stderr_fd;
+ HANDLE phandle = NULL;
+ GError *gerr = NULL;
+
+ if (!args || !args[0])
+ return MH_RES_OTHER_ERROR;
+
+ /* convert to ms */
+ atimeout = atimeout * 1000;
+
+ mh_trace("Spawning '%s'\n", args[0]);
+ if (!g_spawn_async_with_pipes(apath, args, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL, NULL, (GPid *) &phandle, NULL,
+ &stdout_fd, &stderr_fd, &gerr)) {
+ mh_perror(LOG_ERR, "Spawn_process failed with code %d, message: %s\n",
+ gerr->code, gerr->message);
+ return MH_RES_OTHER_ERROR;
+ }
+
+ mh_trace("Waiting for %p", (void *)phandle);
+ WaitForSingleObject(phandle, atimeout);
+
+ if (GetExitCodeProcess(phandle, &status) == 0) {
+ mh_err("Could not get exit code: %lu", GetLastError());
+ res = MH_RES_BACKEND_ERROR;
+ }
+
+ if (res == MH_RES_BACKEND_ERROR) {
+ TerminateProcess(phandle, 1);
+ mh_err("%p - timed out after %dms", (void *)phandle, atimeout);
+ }
+
+ /* Nice to log it somewhere */
+ mh_debug("Result of '%s' was %d", args[0], (int)status);
+
+ mh_trace("Child done: %p", (void *)phandle);
+
+ read_output(stdout_fd, stdoutbuf);
+ read_output(stderr_fd, stderrbuf);
+
+ if (*stdoutbuf)
+ mh_debug("stdout: %s", *stdoutbuf);
+ if (*stderrbuf)
+ mh_debug("stderr: %s", *stderrbuf);
+
+ _close(stdout_fd);
+ _close(stderr_fd);
+
+ g_spawn_close_pid((GPid *)phandle);
+
+ return res;
+}
+
+static gboolean
+get_profiles(GList **names, GList **guids)
+{
+ gboolean rc = FALSE;
+ int len;
+ char *stdoutbuf = NULL;
+ char *stderrbuf = NULL;
+ char *c1, *c2;
+ char *args[3] = {0};
+
+ args[0] = SYSTEM32 "\\" POWERCFG;
+ args[1] = PC_LISTPROFILES;
+ args[2] = NULL;
+
+ if (exec_command(getenv("WINDIR"), args , TIMEOUT, &stdoutbuf, &stderrbuf)
+ == MH_RES_SUCCESS && stdoutbuf) {
+ rc = TRUE;
+ len = strlen(stdoutbuf);
+ c1 = stdoutbuf;
+
+ while ((c1 = strstr(c1, "GUID: "))) {
+ c1 += 6;
+ if (c1 - stdoutbuf < len && (c2 = strchr(c1, ' '))) {
+ *c2++ = 0;
+ *guids = g_list_append(*guids, strdup(c1));
+ if ((c1 = strchr(c2, '(')) && ++c1 - stdoutbuf < len &&
+ (c2 = strchr(c1, ')'))) {
+ *c2 = 0;
+ *names = g_list_append(*names, strdup(c1));
+ *c2 = ')';
+ }
+ }
+ }
+ }
+
+ if (!*names || !*guids || g_list_length(*names) != g_list_length(*guids))
+ rc = FALSE;
+
+ free(stdoutbuf);
+ free(stderrbuf);
+
+ return rc;
+}
+
+enum mh_result
+host_os_set_power_profile(const char *profile)
+{
+ enum mh_result res = MH_RES_SUCCESS;
+ char *guid = NULL;
+ char *stdoutbuf = NULL;
+ char *stderrbuf = NULL;
+ GList *names = NULL;
+ GList *guids = NULL;
+ GList *pnames = NULL;
+ GList *pguids = NULL;
+ char *args[4] = {0};
+
+ if (!get_profiles(&names, &guids))
+ return MH_RES_BACKEND_ERROR;
+
+ for (pnames = g_list_first(names), pguids = g_list_first(guids);
+ pnames && pguids && !guid;
+ pnames = g_list_next(pnames), pguids = g_list_next(pguids))
+ if (!strcmp((char *) pnames->data, profile))
+ guid = strdup((char *) pguids->data);
+
+ g_list_free_full(names, free);
+ g_list_free_full(guids, free);
+
+ if (guid) {
+ args[0] = SYSTEM32 "\\" POWERCFG;
+ args[1] = PC_SETPROFILE;
+ args[2] = guid;
+ args[3] = NULL;
+ res = exec_command(getenv("WINDIR"), args, TIMEOUT, &stdoutbuf,
+ &stderrbuf);
+ free(guid);
+ } else
+ res = MH_RES_INVALID_ARGS;
+
+ free(stdoutbuf);
+ free(stderrbuf);
+
+ return res;
+}
+
+enum mh_result
+host_os_get_power_profile(char **profile)
+{
+ enum mh_result res;
+ char *stdoutbuf = NULL;
+ char *stderrbuf = NULL;
+ char *c1, *c2;
+ char *args[3] = {0};
+
+ args[0] = SYSTEM32 "\\" POWERCFG;
+ args[1] = PC_GETPROFILE;
+ args[2] = NULL;
+
+ res = exec_command(getenv("WINDIR"), args, TIMEOUT, &stdoutbuf, &stderrbuf);
+ if (res == MH_RES_SUCCESS) {
+ if (stdoutbuf && (c1 = strchr(stdoutbuf, '(')) &&
+ ++c1 - stdoutbuf < strlen(stdoutbuf) && (c2 = strchr(c1, ')'))) {
+ *c2 = 0;
+ *profile = strdup(c1);
+ } else
+ res = MH_RES_BACKEND_ERROR;
+ }
+
+ free(stdoutbuf);
+ free(stderrbuf);
+
+ return res;
+}
+
+GList *
+host_os_list_power_profiles(void)
+{
+ GList *names = NULL;
+ GList *guids = NULL;
+
+ get_profiles(&names, &guids);
+ g_list_free_full(guids, free);
+
+ return names;
+}
diff --git a/src/unittests/mh_api_host.h b/src/unittests/mh_api_host.h
index 00287ca..56b3feb 100644
--- a/src/unittests/mh_api_host.h
+++ b/src/unittests/mh_api_host.h
@@ -163,6 +163,43 @@ class MhApiHostSuite : public CxxTest::TestSuite
infomsg.str("");
}
+ void testPowerManagement(void)
+ {
+ char *original, *newProfile;
+ const char *profile;
+ GList *profiles;
+ guint len;
+
+ srand(time(NULL));
+
+ // Save the original profile
+ TS_ASSERT(mh_host_get_power_profile(&original) == MH_RES_SUCCESS);
+
+ // List all profiles
+ profiles = mh_host_list_power_profiles();
+ len = g_list_length(profiles);
+
+ // Check if at least one profile is present
+ TS_ASSERT(len > 0);
+
+ // Choose random profile
+ profile = (const char *) g_list_nth(profiles, rand() % len)->data;
+
+ // Set it
+ TS_ASSERT(mh_host_set_power_profile(profile) == MH_RES_SUCCESS);
+
+ // Check if the profile is set
+ TS_ASSERT(mh_host_get_power_profile(&newProfile) == MH_RES_SUCCESS);
+
+ TS_ASSERT(strcmp(newProfile, profile) == 0);
+
+ // Restore original profile
+ TS_ASSERT(mh_host_set_power_profile(original) == MH_RES_SUCCESS);
+
+ free(original);
+ free(newProfile);
+ g_list_free_full(profiles, free);
+ }
};
#endif
--
1.7.6.4
12 years, 6 months
[PATCH] Broker: automatic federation routes for dynamic/aggregate setups (v4)
by Adam Stokes
Setting up some different routes for either using bi-directional or
the push-route federation which is primarily used within the
vios-proxy setup.
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari-broker.init.in | 5 ++
matahari-broker.service.in | 3 +-
matahari.spec.in | 26 +++++++++++
src/broker/broker_federation.c | 93 ++++++++++++++++++++++++++-------------
src/broker/broker_linux.c | 29 +++++++++++-
src/broker/broker_os.h | 11 +++++
src/lib/mh_agent.cpp | 2 +-
7 files changed, 133 insertions(+), 36 deletions(-)
diff --git a/matahari-broker.init.in b/matahari-broker.init.in
index d9ca4ee..0f03b44 100755
--- a/matahari-broker.init.in
+++ b/matahari-broker.init.in
@@ -27,6 +27,7 @@
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
+# Should-Start: matahari-vios-proxy-guest
# Short-Description: start or stop matahari broker
# Description: Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
### END INIT INFO
@@ -53,6 +54,10 @@ if [ -f @sysconfdir@/sysconfig/matahari-broker ]; then
. @sysconfdir@/sysconfig/matahari-broker
fi
+if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
+ . @sysconfdir@/sysconfig/matahari-vios-proxy
+fi
+
RETVAL=0
start() {
diff --git a/matahari-broker.service.in b/matahari-broker.service.in
index 62898fb..5f28f48 100644
--- a/matahari-broker.service.in
+++ b/matahari-broker.service.in
@@ -1,6 +1,6 @@
[Unit]
Description=Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
-After=syslog.target network.target
+After=syslog.target network.target matahari-vios-proxy-guest.service
Requires=syslog.target network.target
[Install]
@@ -15,6 +15,7 @@ Group=qpidd
EnvironmentFile=-@sysconfdir@/sysconfig/matahari
EnvironmentFile=-@sysconfdir@/sysconfig/matahari-broker
+EnvironmentFile=-@sysconfdir@/sysconfig/matahari-vios-proxy
ExecStart=/usr/sbin/matahari-brokerd $QPIDD_OPTIONS
diff --git a/matahari.spec.in b/matahari.spec.in
index 552cbd7..8f105f4 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -100,6 +100,7 @@ Requires: %{name}-core = %{version}-%{release}
Requires: qpid-cpp-server > 0.7
Requires: qpid-cpp-server-ssl > 0.7
Requires: qmf > 0.7
+Requires: qpid-tools
Requires(post): chkconfig
Requires(preun):chkconfig
Requires(preun):initscripts
@@ -114,6 +115,9 @@ Summary: Network proxy using virtioserial for QEMU host
Group: Applications/System
Requires: %{name}-broker = %{version}-%{release}
Requires: vios-proxy-host
+Requires(post): chkconfig
+Requires(preun): chkconfig
+Requires(preun): initscripts
%description vios-proxy-host
%{name} specific host initialization scripts
@@ -124,6 +128,9 @@ Summary: Network proxy using virtioserial for QEMU guest
Group: Applications/System
Requires: %{name}-broker = %{version}-%{release}
Requires: vios-proxy-guest
+Requires(post): chkconfig
+Requires(preun): chkconfig
+Requires(preun): initscripts
%description vios-proxy-guest
%{name} specific guest initialization scripts
@@ -399,6 +406,25 @@ if [ "$1" -ge "1" ]; then
/sbin/service matahari-vios-proxy-host condrestart >/dev/null 2>&1 || :
fi
+#== Vios Proxy guest
+%post vios-proxy-guest
+%if %{systemd}
+systemctl --system daemon-reload
+%endif
+/sbin/service matahari-vios-proxy-guest condrestart
+
+%preun vios-proxy-guest
+if [ $1 = 0 ]; then
+ /sbin/service matahari-vios-proxy-guest stop >/dev/null 2>&1 || :
+%if !%{systemd}
+ chkconfig --del matahari-vios-proxy-guest
+%endif
+fi
+
+%postun vios-proxy-guest
+if [ "$1" -ge "1" ]; then
+ /sbin/service matahari-vios-proxy-guest condrestart >/dev/null 2>&1 || :
+fi
#== Core
%pre core
diff --git a/src/broker/broker_federation.c b/src/broker/broker_federation.c
index e775d3e..173f437 100644
--- a/src/broker/broker_federation.c
+++ b/src/broker/broker_federation.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <glib.h>
#include <matahari/dnssrv.h>
#include <matahari/utilities.h>
@@ -38,35 +39,56 @@
DNS_SRV_PREFIX_##TYPE, \
strlen(DNS_SRV_PREFIX_##TYPE)) == 0)
-#define ROUTE_LIST(LOCAL, REMOTE) { \
- {REMOTE, LOCAL, "amq.direct"}, \
- {LOCAL, REMOTE, "amq.direct"}, \
- {REMOTE, LOCAL, "qmf.default.direct"}, \
- {LOCAL, REMOTE, "qmf.default.direct"}, \
- {REMOTE, LOCAL, "qmf.default.topic"}, \
- {LOCAL, REMOTE, "qmf.default.topic"} \
+static int
+broker_add_route(const char *local, const char *remote,
+ const char *exchange, const char *route_key, int srclocal,
+ int aggregate)
+{
+ int ret;
+ struct mh_qpid_route route[] = {
+ { local, remote, exchange, route_key, srclocal, aggregate }
+ };
+
+ mh_info("Adding routes for federated broker \"%s\"", remote);
+ ret = broker_os_add_qpid_route(route);
+ if (ret) {
+ mh_err("Failed to route %s => %s", local, remote);
+ }
+ return ret;
}
-
-static int broker_federate(const char *local, const char *remote)
+static int
+broker_federate(const char *local, const char *remote, int route_type)
{
- int i;
- struct mh_qpid_route routes[] = ROUTE_LIST(local, remote);
-
- mh_trace("Adding routes for federated broker \"%s\"", remote);
+ int ret = broker_os_add_qpid_route_link(local, remote);
+ if (ret) {
+ mh_err("Failed to link brokers \"%s\" to \"%s\"", local, remote);
+ return ret;
+ }
- for (i = 0; i < DIMOF(routes); i++) {
- int ret = broker_os_add_qpid_route(&routes[i]);
- if (ret) {
- mh_err("Failed to add federated broker \"%s\"", remote);
- return ret;
+ if (route_type) {
+ if ((broker_add_route(local, remote, "qmf.default.topic", "direct-agent.#", FALSE, TRUE) ||
+ broker_add_route(local, remote, "qmf.default.topic", "console.#", FALSE, TRUE) ||
+ broker_add_route(remote, local, "qmf.default.topic", "direct-console.#", TRUE, TRUE) ||
+ broker_add_route(remote, local, "qmf.default.topic", "agent.#", TRUE, TRUE)) > 0) {
+ return 1;
+ }
+ } else {
+ if ((broker_add_route(remote, local, "amq.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(local, remote, "amq.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(remote, local, "qmf.default.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(local, remote, "qmf.default.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(remote, local, "qmf.default.topic", NULL, FALSE, FALSE) ||
+ broker_add_route(local, remote, "qmf.default.topic", NULL, FALSE, FALSE)) > 0) {
+ return 1;
}
}
return 0;
}
-static char *broker_lookup(const char *query)
+static char *
+broker_lookup(const char *query)
{
#ifdef HAVE_RESOLV_H
static char broker[1025 + 6];
@@ -90,30 +112,39 @@ static char *broker_lookup(const char *query)
return NULL;
}
-void broker_federation_configure(void)
+void
+broker_federation_configure(void)
{
const char *brokers = getenv("FEDERATED_BROKERS");
+ const char *proxy_service_port = getenv("VP_G_SERVICE_PORT");
+ const char *proxy_service_dir = getenv("VP_G_HOST_DIR");
char local[16];
char peers[1024];
char *p = NULL;
char *peer;
- if (!brokers) {
- return;
- }
+ if (g_file_test(proxy_service_dir, G_FILE_TEST_IS_DIR)) {
+ char remote[16];
+ snprintf(remote, sizeof(local), "localhost:%s", proxy_service_port);
+ snprintf(local, sizeof(remote), "localhost:%hu", broker_get_port());
+ broker_federate(local, remote, TRUE);
+ } else if (brokers) {
+ snprintf(local, sizeof(local), "localhost:%hu", broker_get_port());
- snprintf(local, sizeof(local), "localhost:%hu", broker_get_port());
+ mh_string_copy(peers, brokers, sizeof(peers));
- mh_string_copy(peers, brokers, sizeof(peers));
+ while ((peer = strtok_r(p ? NULL : peers, ",; ", &p)) != NULL) {
+ if (IS_DNS_SRV(peer, TCP) || IS_DNS_SRV(peer, TLS)) {
+ peer = broker_lookup(peer);
+ }
- while ((peer = strtok_r(p ? NULL : peers, ",; ", &p)) != NULL) {
- if (IS_DNS_SRV(peer, TCP) || IS_DNS_SRV(peer, TLS)) {
- peer = broker_lookup(peer);
+ if (peer) {
+ broker_federate(local, peer, FALSE);
+ }
}
- if (peer) {
- broker_federate(local, peer);
- }
+ } else {
+ return;
}
}
diff --git a/src/broker/broker_linux.c b/src/broker/broker_linux.c
index 997734f..8d5689d 100644
--- a/src/broker/broker_linux.c
+++ b/src/broker/broker_linux.c
@@ -55,14 +55,37 @@ int broker_os_start_broker(char * const args[])
}
}
-int broker_os_add_qpid_route(const struct mh_qpid_route *route)
+int broker_os_add_qpid_route_link(const char *local, const char *remote)
{
char cmd[1024];
int ret;
- snprintf(cmd, sizeof(cmd), "qpid-route --timeout=5 dynamic add %s %s %s",
- route->dest, route->src, route->exchange);
+ snprintf(cmd, sizeof(cmd), "qpid-route link add %s untrusted/untrusted@%s PLAIN",
+ local, remote);
+
+ ret = system(cmd);
+
+ if (ret < 0) {
+ perror("system()");
+ }
+ return ret;
+}
+
+int broker_os_add_qpid_route(const struct mh_qpid_route *route)
+{
+ char cmd[1024];
+ int ret;
+ if (route->aggregate && route->srclocal) {
+ snprintf(cmd, sizeof(cmd), "qpid-route --src-local route add %s %s %s %s",
+ route->dest, route->src, route->exchange, route->route_key);
+ } else if (route->aggregate) {
+ snprintf(cmd, sizeof(cmd), "qpid-route route add %s %s %s %s",
+ route->dest, route->src, route->exchange, route->route_key);
+ } else {
+ snprintf(cmd, sizeof(cmd), "qpid-route --timeout=5 dynamic add %s %s %s",
+ route->dest, route->src, route->exchange);
+ }
ret = system(cmd);
if (ret < 0) {
diff --git a/src/broker/broker_os.h b/src/broker/broker_os.h
index 788fe78..7f8f8a9 100644
--- a/src/broker/broker_os.h
+++ b/src/broker/broker_os.h
@@ -31,6 +31,9 @@ struct mh_qpid_route {
const char *dest; /**< The route destination */
const char *src; /**< The route source */
const char *exchange; /**< The exchange */
+ const char *route_key; /**< The routing key */
+ int srclocal; /**< Is this route static? */
+ int aggregate; /**< Is this route part of aggregate? */
};
@@ -42,6 +45,14 @@ struct mh_qpid_route {
int broker_os_start_broker(char * const args[]);
/**
+ * Add a route link between two Qpid brokers.
+ * @param local local broker to link
+ * @param remote remote broker to link
+ * @return -1 on error, otherwise the result of the external route add command.
+ */
+int broker_os_add_qpid_route_link(const char *local, const char *remote);
+
+/**
* Add a route between two Qpid brokers.
* @param route pointer to the route to add
* @return -1 on error, otherwise the result of the external route add command.
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 5417680..49098b0 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -449,7 +449,7 @@ mh_parse_options(const char *proc_name, int argc, char **argv, OptionsMap &optio
/* Force local-only handling */
mh_add_option('b', required_argument, "broker", "specify broker host name", &options, map_option);
mh_add_option('D', no_argument, "dns-srv", "interpret the value of --broker as a domain name for DNS SRV lookups", &options, map_option);
- mh_add_option('p', required_argument, "port", "specify broker ", &options, map_option);
+ mh_add_option('p', required_argument, "port", "specify broker port", &options, map_option);
mh_add_option('v', no_argument, "verbose", "Increase the log level", NULL, map_option);
mh_add_option('u', required_argument, "username", "username to use for authentication to the broker", &amqp_options, connection_option);
--
1.7.6.4
12 years, 6 months
[PATCH] Broker: automatic federation routes for dynamic/aggregate setups (v3)
by Adam Stokes
Setting up some different routes for either using bi-directional or
the push-route federation which is primarily used within the
vios-proxy
setup.
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari-broker.init.in | 5 ++
matahari-broker.service.in | 3 +-
matahari.spec.in | 26 +++++++++++
src/broker/broker_federation.c | 91 +++++++++++++++++++++++++++-------------
src/broker/broker_linux.c | 29 +++++++++++-
src/broker/broker_os.h | 11 +++++
src/lib/mh_agent.cpp | 2 +-
7 files changed, 132 insertions(+), 35 deletions(-)
diff --git a/matahari-broker.init.in b/matahari-broker.init.in
index d9ca4ee..0f03b44 100755
--- a/matahari-broker.init.in
+++ b/matahari-broker.init.in
@@ -27,6 +27,7 @@
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
+# Should-Start: matahari-vios-proxy-guest
# Short-Description: start or stop matahari broker
# Description: Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
### END INIT INFO
@@ -53,6 +54,10 @@ if [ -f @sysconfdir@/sysconfig/matahari-broker ]; then
. @sysconfdir@/sysconfig/matahari-broker
fi
+if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
+ . @sysconfdir@/sysconfig/matahari-vios-proxy
+fi
+
RETVAL=0
start() {
diff --git a/matahari-broker.service.in b/matahari-broker.service.in
index 62898fb..5f28f48 100644
--- a/matahari-broker.service.in
+++ b/matahari-broker.service.in
@@ -1,6 +1,6 @@
[Unit]
Description=Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
-After=syslog.target network.target
+After=syslog.target network.target matahari-vios-proxy-guest.service
Requires=syslog.target network.target
[Install]
@@ -15,6 +15,7 @@ Group=qpidd
EnvironmentFile=-@sysconfdir@/sysconfig/matahari
EnvironmentFile=-@sysconfdir@/sysconfig/matahari-broker
+EnvironmentFile=-@sysconfdir@/sysconfig/matahari-vios-proxy
ExecStart=/usr/sbin/matahari-brokerd $QPIDD_OPTIONS
diff --git a/matahari.spec.in b/matahari.spec.in
index 130c4d8..a2934a2 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -100,6 +100,7 @@ Requires: %{name}-core = %{version}-%{release}
Requires: qpid-cpp-server > 0.7
Requires: qpid-cpp-server-ssl > 0.7
Requires: qmf > 0.7
+Requires: qpid-tools
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
@@ -114,6 +115,9 @@ Summary: Network proxy using virtioserial for QEMU host
Group: Applications/System
Requires: %{name}-broker = %{version}-%{release}
Requires: vios-proxy-host
+Requires(post): chkconfig
+Requires(preun): chkconfig
+Requires(preun): initscripts
%description vios-proxy-host
%{name} specific host initialization scripts
@@ -124,6 +128,9 @@ Summary: Network proxy using virtioserial for QEMU guest
Group: Applications/System
Requires: %{name}-broker = %{version}-%{release}
Requires: vios-proxy-guest
+Requires(post): chkconfig
+Requires(preun): chkconfig
+Requires(preun): initscripts
%description vios-proxy-guest
%{name} specific guest initialization scripts
@@ -399,6 +406,25 @@ if [ "$1" -ge "1" ]; then
/sbin/service matahari-vios-proxy-host condrestart >/dev/null 2>&1 || :
fi
+#== Vios Proxy guest
+%post vios-proxy-guest
+%if %{systemd}
+systemctl --system daemon-reload
+%endif
+/sbin/service matahari-vios-proxy-guest condrestart
+
+%preun vios-proxy-guest
+if [ $1 = 0 ]; then
+ /sbin/service matahari-vios-proxy-guest stop >/dev/null 2>&1 || :
+%if !%{systemd}
+ chkconfig --del matahari-vios-proxy-guest
+%endif
+fi
+
+%postun vios-proxy-guest
+if [ "$1" -ge "1" ]; then
+ /sbin/service matahari-vios-proxy-guest condrestart >/dev/null 2>&1 || :
+fi
#== Core
%pre core
diff --git a/src/broker/broker_federation.c b/src/broker/broker_federation.c
index e775d3e..efdb6fa 100644
--- a/src/broker/broker_federation.c
+++ b/src/broker/broker_federation.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <glib.h>
#include <matahari/dnssrv.h>
#include <matahari/utilities.h>
@@ -38,27 +39,47 @@
DNS_SRV_PREFIX_##TYPE, \
strlen(DNS_SRV_PREFIX_##TYPE)) == 0)
-#define ROUTE_LIST(LOCAL, REMOTE) { \
- {REMOTE, LOCAL, "amq.direct"}, \
- {LOCAL, REMOTE, "amq.direct"}, \
- {REMOTE, LOCAL, "qmf.default.direct"}, \
- {LOCAL, REMOTE, "qmf.default.direct"}, \
- {REMOTE, LOCAL, "qmf.default.topic"}, \
- {LOCAL, REMOTE, "qmf.default.topic"} \
+static int
+broker_add_route(const char *local, const char *remote,
+ const char *exchange, const char *route_key, int srclocal,
+ int aggregate)
+{
+ int ret;
+ struct mh_qpid_route route[] = {
+ { local, remote, exchange, route_key, srclocal, aggregate }
+ };
+
+ mh_info("Adding routes for federated broker \"%s\"", remote);
+ ret = broker_os_add_qpid_route(route);
+ if (ret) {
+ mh_err("Failed to route %s => %s", local, remote);
+ }
+ return ret;
}
-
-static int broker_federate(const char *local, const char *remote)
+static int
+broker_federate(const char *local, const char *remote, int route_type)
{
- int i;
- struct mh_qpid_route routes[] = ROUTE_LIST(local, remote);
-
- mh_trace("Adding routes for federated broker \"%s\"", remote);
+ int ret = broker_os_add_qpid_route_link(local, remote);
+ if (ret) {
+ mh_err("Failed to link brokers \"%s\" to \"%s\"", local, remote);
+ return ret;
+ }
- for (i = 0; i < DIMOF(routes); i++) {
- int ret = broker_os_add_qpid_route(&routes[i]);
- if (ret) {
- mh_err("Failed to add federated broker \"%s\"", remote);
+ if (route_type) {
+ if ((broker_add_route(local, remote, "qmf.default.topic", "direct-agent.#", FALSE, TRUE) ||
+ broker_add_route(local, remote, "qmf.default.topic", "console.#", FALSE, TRUE) ||
+ broker_add_route(remote, local, "qmf.default.topic", "direct-console.#", TRUE, TRUE) ||
+ broker_add_route(remote, local, "qmf.default.topic", "agent.#", TRUE, TRUE)) < 0) {
+ return ret;
+ }
+ } else {
+ if ((broker_add_route(remote, local, "amq.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(local, remote, "amq.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(remote, local, "qmf.default.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(local, remote, "qmf.default.direct", NULL, FALSE, FALSE) ||
+ broker_add_route(remote, local, "qmf.default.topic", NULL, FALSE, FALSE) ||
+ broker_add_route(local, remote, "qmf.default.topic", NULL, FALSE, FALSE)) < 0) {
return ret;
}
}
@@ -66,7 +87,8 @@ static int broker_federate(const char *local, const char *remote)
return 0;
}
-static char *broker_lookup(const char *query)
+static char *
+broker_lookup(const char *query)
{
#ifdef HAVE_RESOLV_H
static char broker[1025 + 6];
@@ -90,30 +112,39 @@ static char *broker_lookup(const char *query)
return NULL;
}
-void broker_federation_configure(void)
+void
+broker_federation_configure(void)
{
const char *brokers = getenv("FEDERATED_BROKERS");
+ const char *proxy_service_port = getenv("VP_G_SERVICE_PORT");
+ const char *proxy_service_dir = getenv("VP_G_HOST_DIR");
char local[16];
char peers[1024];
char *p = NULL;
char *peer;
- if (!brokers) {
- return;
- }
+ if (g_file_test(proxy_service_dir, G_FILE_TEST_IS_DIR)) {
+ char remote[16];
+ snprintf(remote, sizeof(local), "localhost:%s", proxy_service_port);
+ snprintf(local, sizeof(remote), "localhost:%hu", broker_get_port());
+ broker_federate(local, remote, TRUE);
+ } else if (brokers) {
+ snprintf(local, sizeof(local), "localhost:%hu", broker_get_port());
- snprintf(local, sizeof(local), "localhost:%hu", broker_get_port());
+ mh_string_copy(peers, brokers, sizeof(peers));
- mh_string_copy(peers, brokers, sizeof(peers));
+ while ((peer = strtok_r(p ? NULL : peers, ",; ", &p)) != NULL) {
+ if (IS_DNS_SRV(peer, TCP) || IS_DNS_SRV(peer, TLS)) {
+ peer = broker_lookup(peer);
+ }
- while ((peer = strtok_r(p ? NULL : peers, ",; ", &p)) != NULL) {
- if (IS_DNS_SRV(peer, TCP) || IS_DNS_SRV(peer, TLS)) {
- peer = broker_lookup(peer);
+ if (peer) {
+ broker_federate(local, peer, FALSE);
+ }
}
- if (peer) {
- broker_federate(local, peer);
- }
+ } else {
+ return;
}
}
diff --git a/src/broker/broker_linux.c b/src/broker/broker_linux.c
index 997734f..8d5689d 100644
--- a/src/broker/broker_linux.c
+++ b/src/broker/broker_linux.c
@@ -55,14 +55,37 @@ int broker_os_start_broker(char * const args[])
}
}
-int broker_os_add_qpid_route(const struct mh_qpid_route *route)
+int broker_os_add_qpid_route_link(const char *local, const char *remote)
{
char cmd[1024];
int ret;
- snprintf(cmd, sizeof(cmd), "qpid-route --timeout=5 dynamic add %s %s %s",
- route->dest, route->src, route->exchange);
+ snprintf(cmd, sizeof(cmd), "qpid-route link add %s untrusted/untrusted@%s PLAIN",
+ local, remote);
+
+ ret = system(cmd);
+
+ if (ret < 0) {
+ perror("system()");
+ }
+ return ret;
+}
+
+int broker_os_add_qpid_route(const struct mh_qpid_route *route)
+{
+ char cmd[1024];
+ int ret;
+ if (route->aggregate && route->srclocal) {
+ snprintf(cmd, sizeof(cmd), "qpid-route --src-local route add %s %s %s %s",
+ route->dest, route->src, route->exchange, route->route_key);
+ } else if (route->aggregate) {
+ snprintf(cmd, sizeof(cmd), "qpid-route route add %s %s %s %s",
+ route->dest, route->src, route->exchange, route->route_key);
+ } else {
+ snprintf(cmd, sizeof(cmd), "qpid-route --timeout=5 dynamic add %s %s %s",
+ route->dest, route->src, route->exchange);
+ }
ret = system(cmd);
if (ret < 0) {
diff --git a/src/broker/broker_os.h b/src/broker/broker_os.h
index 788fe78..7f8f8a9 100644
--- a/src/broker/broker_os.h
+++ b/src/broker/broker_os.h
@@ -31,6 +31,9 @@ struct mh_qpid_route {
const char *dest; /**< The route destination */
const char *src; /**< The route source */
const char *exchange; /**< The exchange */
+ const char *route_key; /**< The routing key */
+ int srclocal; /**< Is this route static? */
+ int aggregate; /**< Is this route part of aggregate? */
};
@@ -42,6 +45,14 @@ struct mh_qpid_route {
int broker_os_start_broker(char * const args[]);
/**
+ * Add a route link between two Qpid brokers.
+ * @param local local broker to link
+ * @param remote remote broker to link
+ * @return -1 on error, otherwise the result of the external route add command.
+ */
+int broker_os_add_qpid_route_link(const char *local, const char *remote);
+
+/**
* Add a route between two Qpid brokers.
* @param route pointer to the route to add
* @return -1 on error, otherwise the result of the external route add command.
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 5417680..49098b0 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -449,7 +449,7 @@ mh_parse_options(const char *proc_name, int argc, char **argv, OptionsMap &optio
/* Force local-only handling */
mh_add_option('b', required_argument, "broker", "specify broker host name", &options, map_option);
mh_add_option('D', no_argument, "dns-srv", "interpret the value of --broker as a domain name for DNS SRV lookups", &options, map_option);
- mh_add_option('p', required_argument, "port", "specify broker ", &options, map_option);
+ mh_add_option('p', required_argument, "port", "specify broker port", &options, map_option);
mh_add_option('v', no_argument, "verbose", "Increase the log level", NULL, map_option);
mh_add_option('u', required_argument, "username", "username to use for authentication to the broker", &amqp_options, connection_option);
--
1.7.6.4
12 years, 6 months
[PATCH] Spec: convert tabs to spaces
by Adam Stokes
Make life less complicated.
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari.spec.in | 226 +++++++++++++++++++++++++++---------------------------
1 files changed, 113 insertions(+), 113 deletions(-)
diff --git a/matahari.spec.in b/matahari.spec.in
index a2934a2..d54fe4e 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -20,54 +20,54 @@
%global mh_release %{specversion}
%endif
-Name: matahari
-Version: #MATAHARI_VERSION#
-Release: %{mh_release}%{?dist}
-Summary: Matahari QMF Agents for Linux guests
+Name: matahari
+Version: #MATAHARI_VERSION#
+Release: %{mh_release}%{?dist}
+Summary: Matahari QMF Agents for Linux guests
-Group: Applications/System
-License: GPLv2
-URL: http://matahariproject.org
+Group: Applications/System
+License: GPLv2
+URL: http://matahariproject.org
# wget --no-check-certificate -O matahari-matahari-{upstream_version}.tgz https://github.com/matahari/matahari/tarball/{upstream_version}
-Source0: matahari-matahari-%{upstream_version}.tgz
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+Source0: matahari-matahari-%{upstream_version}.tgz
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
# NOTE: The host API uses dbus for the machine uuid
-Requires: dbus
-Requires: qmf > 0.7
-Requires: pcre
-
-Requires: %{name}-core = %{version}-%{release}
-Requires: %{name}-consoles = %{version}-%{release}
-Requires: %{name}-broker = %{version}-%{release}
-Requires: %{name}-host = %{version}-%{release}
-Requires: %{name}-network = %{version}-%{release}
-Requires: %{name}-service = %{version}-%{release}
-Requires: %{name}-sysconfig = %{version}-%{release}
-
-BuildRequires: cmake
-BuildRequires: libuuid-devel
-BuildRequires: gcc-c++
-BuildRequires: pcre-devel
-BuildRequires: glib2-devel
-BuildRequires: sigar-devel
-BuildRequires: libcurl-devel
-BuildRequires: nss-devel
-BuildRequires: help2man
-BuildRequires: augeas-devel >= 0.9.0
+Requires: dbus
+Requires: qmf > 0.7
+Requires: pcre
+
+Requires: %{name}-core = %{version}-%{release}
+Requires: %{name}-consoles = %{version}-%{release}
+Requires: %{name}-broker = %{version}-%{release}
+Requires: %{name}-host = %{version}-%{release}
+Requires: %{name}-network = %{version}-%{release}
+Requires: %{name}-service = %{version}-%{release}
+Requires: %{name}-sysconfig = %{version}-%{release}
+
+BuildRequires: cmake
+BuildRequires: libuuid-devel
+BuildRequires: gcc-c++
+BuildRequires: pcre-devel
+BuildRequires: glib2-devel
+BuildRequires: sigar-devel
+BuildRequires: libcurl-devel
+BuildRequires: nss-devel
+BuildRequires: help2man
+BuildRequires: augeas-devel >= 0.9.0
%if %{with qmf}
-BuildRequires: qpid-cpp-client-devel > 0.7
-BuildRequires: qpid-qmf-devel > 0.7
+BuildRequires: qpid-cpp-client-devel > 0.7
+BuildRequires: qpid-qmf-devel > 0.7
%endif
%if %{with dbus}
-BuildRequires: dbus-devel dbus-glib-devel polkit-devel libxslt
+BuildRequires: dbus-devel dbus-glib-devel polkit-devel libxslt
%endif
%if %{defined run_unit_tests}
-BuildRequires: cxxtest
+BuildRequires: cxxtest
%endif
%description
@@ -84,26 +84,26 @@ as a set of objects with properties and methods.
%package core
-License: GPLv2+
-Summary: Core files for Matahari
-Group: Applications/System
+License: GPLv2+
+Summary: Core files for Matahari
+Group: Applications/System
%description core
Core files for Matahari
%if %{with qmf}
%package broker
-License: GPLv2+
-Summary: Optional AMQP Broker for Matahari
-Group: Applications/System
-Requires: %{name}-core = %{version}-%{release}
-Requires: qpid-cpp-server > 0.7
-Requires: qpid-cpp-server-ssl > 0.7
-Requires: qmf > 0.7
+License: GPLv2+
+Summary: Optional AMQP Broker for Matahari
+Group: Applications/System
+Requires: %{name}-core = %{version}-%{release}
+Requires: qpid-cpp-server > 0.7
+Requires: qpid-cpp-server-ssl > 0.7
+Requires: qmf > 0.7
Requires: qpid-tools
-Requires(post): chkconfig
-Requires(preun): chkconfig
-Requires(preun): initscripts
+Requires(post): chkconfig
+Requires(preun):chkconfig
+Requires(preun):initscripts
%description broker
Optional AMQP Broker for Matahari
@@ -115,9 +115,9 @@ Summary: Network proxy using virtioserial for QEMU host
Group: Applications/System
Requires: %{name}-broker = %{version}-%{release}
Requires: vios-proxy-host
-Requires(post): chkconfig
-Requires(preun): chkconfig
-Requires(preun): initscripts
+Requires(post): chkconfig
+Requires(preun):chkconfig
+Requires(preun):initscripts
%description vios-proxy-host
%{name} specific host initialization scripts
@@ -128,111 +128,111 @@ Summary: Network proxy using virtioserial for QEMU guest
Group: Applications/System
Requires: %{name}-broker = %{version}-%{release}
Requires: vios-proxy-guest
-Requires(post): chkconfig
-Requires(preun): chkconfig
-Requires(preun): initscripts
+Requires(post): chkconfig
+Requires(preun):chkconfig
+Requires(preun):initscripts
%description vios-proxy-guest
%{name} specific guest initialization scripts
%package lib
-License: GPLv2+
-Summary: C libraries used by Matahari agents
-Group: Applications/System
-Requires: %{name}-core = %{version}-%{release}
+License: GPLv2+
+Summary: C libraries used by Matahari agents
+Group: Applications/System
+Requires: %{name}-core = %{version}-%{release}
%description lib
C libraries used by Matahari agents
%package agent-lib
-License: GPLv2+
-Summary: C++ library used by Matahari agents
-Group: Applications/System
-Requires: %{name}-lib = %{version}-%{release}
-Requires: qpid-cpp-client-ssl > 0.7
-Requires(pre): shadow-utils
+License: GPLv2+
+Summary: C++ library used by Matahari agents
+Group: Applications/System
+Requires: %{name}-lib = %{version}-%{release}
+Requires: qpid-cpp-client-ssl > 0.7
+Requires(pre): shadow-utils
Requires: kstart
%description agent-lib
C++ library containing the base class for Matahari agents
%package host
-License: GPLv2+
-Summary: QMF agent for remote hosts
-Group: Applications/System
-Requires: %{name}-lib = %{version}-%{release}
-Requires: %{name}-agent-lib = %{version}-%{release}
+License: GPLv2+
+Summary: QMF agent for remote hosts
+Group: Applications/System
+Requires: %{name}-lib = %{version}-%{release}
+Requires: %{name}-agent-lib = %{version}-%{release}
%ifarch i386 x86_64
-Requires: dmidecode
+Requires: dmidecode
%endif
-Requires(post): chkconfig
-Requires(preun): chkconfig
-Requires(preun): initscripts
+Requires(post): chkconfig
+Requires(preun):chkconfig
+Requires(preun):initscripts
%description host
QMF agent for viewing and controlling remote hosts
%package network
-License: GPLv2+
-Summary: QMF agent for network devices
-Group: Applications/System
-Requires: %{name}-lib = %{version}-%{release}
-Requires: %{name}-agent-lib = %{version}-%{release}
-Requires(post): chkconfig
-Requires(preun): chkconfig
-Requires(preun): initscripts
-Obsoletes: matahari-net < %{version}-%{release}
+License: GPLv2+
+Summary: QMF agent for network devices
+Group: Applications/System
+Requires: %{name}-lib = %{version}-%{release}
+Requires: %{name}-agent-lib = %{version}-%{release}
+Requires(post): chkconfig
+Requires(preun):chkconfig
+Requires(preun):initscripts
+Obsoletes: matahari-net < %{version}-%{release}
%description network
QMF agent for viewing and controlling network devices
%package service
-License: GPLv2+
-Summary: QMF agent for system services
-Group: Applications/System
-Requires: %{name}-lib = %{version}-%{release}
-Requires: %{name}-agent-lib = %{version}-%{release}
-Requires(post): chkconfig
-Requires(preun): initscripts
-Requires(preun): chkconfig
+License: GPLv2+
+Summary: QMF agent for system services
+Group: Applications/System
+Requires: %{name}-lib = %{version}-%{release}
+Requires: %{name}-agent-lib = %{version}-%{release}
+Requires(post): chkconfig
+Requires(preun):initscripts
+Requires(preun):chkconfig
%description service
QMF agent for viewing and controlling system services
%package sysconfig
-License: GPLv2+
-Summary: QMF agent for post boot configuration services
-Group: Applications/System
-Requires: %{name}-lib = %{version}-%{release}
-Requires: %{name}-agent-lib = %{version}-%{release}
-Requires: puppet
-Requires(post): chkconfig
-Requires(preun): chkconfig
-Requires(preun): initscripts
+License: GPLv2+
+Summary: QMF agent for post boot configuration services
+Group: Applications/System
+Requires: %{name}-lib = %{version}-%{release}
+Requires: %{name}-agent-lib = %{version}-%{release}
+Requires: puppet
+Requires(post): chkconfig
+Requires(preun):chkconfig
+Requires(preun):initscripts
%description sysconfig
QMF agent/console for providing post boot capabilities.
%package devel
-License: GPLv2+
-Summary: Matahari development package
-Group: Development/Libraries
-Requires: %{name} = %{version}-%{release}
-Requires: %{name}-lib = %{version}-%{release}
-Requires: %{name}-agent-lib = %{version}-%{release}
-Requires: qpid-cpp-client-devel > 0.7
-Requires: qmf-devel > 0.7
-Requires: glib2-devel
+License: GPLv2+
+Summary: Matahari development package
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+Requires: %{name}-lib = %{version}-%{release}
+Requires: %{name}-agent-lib = %{version}-%{release}
+Requires: qpid-cpp-client-devel > 0.7
+Requires: qmf-devel > 0.7
+Requires: glib2-devel
%description devel
Headers and shared libraries for developing Matahari agents.
%package consoles
-License: GPLv2+
-Summary: QMF console for monitoring various agents
-Group: Applications/System
-Requires: %{name}-lib = %{version}-%{release}
-Requires: %{name}-agent-lib = %{version}-%{release}
+License: GPLv2+
+Summary: QMF console for monitoring various agents
+Group: Applications/System
+Requires: %{name}-lib = %{version}-%{release}
+Requires: %{name}-agent-lib = %{version}-%{release}
%description consoles
QMF console for monitoring various agents
--
1.7.6.4
12 years, 6 months
[PATCH] Broker: automatic federation routes for dynamic/aggregate setups (v2)
by Adam Stokes
Setting up some different routes for either using bi-directional or
the push-route federation which is primarily used within the
vios-proxy
setup.
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari-broker.init.in | 5 ++
matahari-broker.service.in | 3 +-
matahari.spec.in | 20 ++++++++
src/broker/broker_federation.c | 97 +++++++++++++++++++++++++++-------------
src/broker/broker_linux.c | 29 +++++++++++-
src/broker/broker_os.h | 11 +++++
src/lib/mh_agent.cpp | 3 +-
7 files changed, 131 insertions(+), 37 deletions(-)
diff --git a/matahari-broker.init.in b/matahari-broker.init.in
index d9ca4ee..0f03b44 100755
--- a/matahari-broker.init.in
+++ b/matahari-broker.init.in
@@ -27,6 +27,7 @@
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
+# Should-Start: matahari-vios-proxy-guest
# Short-Description: start or stop matahari broker
# Description: Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
### END INIT INFO
@@ -53,6 +54,10 @@ if [ -f @sysconfdir@/sysconfig/matahari-broker ]; then
. @sysconfdir@/sysconfig/matahari-broker
fi
+if [ -f @sysconfdir@/sysconfig/matahari-vios-proxy ]; then
+ . @sysconfdir@/sysconfig/matahari-vios-proxy
+fi
+
RETVAL=0
start() {
diff --git a/matahari-broker.service.in b/matahari-broker.service.in
index 62898fb..5f28f48 100644
--- a/matahari-broker.service.in
+++ b/matahari-broker.service.in
@@ -1,6 +1,6 @@
[Unit]
Description=Matahari Broker is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
-After=syslog.target network.target
+After=syslog.target network.target matahari-vios-proxy-guest.service
Requires=syslog.target network.target
[Install]
@@ -15,6 +15,7 @@ Group=qpidd
EnvironmentFile=-@sysconfdir@/sysconfig/matahari
EnvironmentFile=-@sysconfdir@/sysconfig/matahari-broker
+EnvironmentFile=-@sysconfdir@/sysconfig/matahari-vios-proxy
ExecStart=/usr/sbin/matahari-brokerd $QPIDD_OPTIONS
diff --git a/matahari.spec.in b/matahari.spec.in
index 130c4d8..0c525eb 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -100,6 +100,7 @@ Requires: %{name}-core = %{version}-%{release}
Requires: qpid-cpp-server > 0.7
Requires: qpid-cpp-server-ssl > 0.7
Requires: qmf > 0.7
+Requires: qpid-tools
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
@@ -399,6 +400,25 @@ if [ "$1" -ge "1" ]; then
/sbin/service matahari-vios-proxy-host condrestart >/dev/null 2>&1 || :
fi
+#== Vios Proxy guest
+%post vios-proxy-guest
+%if %{systemd}
+systemctl --system daemon-reload
+%endif
+/sbin/service matahari-vios-proxy-guest condrestart
+
+%preun vios-proxy-guest
+if [ $1 = 0 ]; then
+ /sbin/service matahari-vios-proxy-guest stop >/dev/null 2>&1 || :
+%if !%{systemd}
+ chkconfig --del matahari-vios-proxy-guest
+%endif
+fi
+
+%postun vios-proxy-guest
+if [ "$1" -ge "1" ]; then
+ /sbin/service matahari-vios-proxy-guest condrestart >/dev/null 2>&1 || :
+fi
#== Core
%pre core
diff --git a/src/broker/broker_federation.c b/src/broker/broker_federation.c
index e775d3e..a34bc39 100644
--- a/src/broker/broker_federation.c
+++ b/src/broker/broker_federation.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <glib.h>
#include <matahari/dnssrv.h>
#include <matahari/utilities.h>
@@ -38,35 +39,58 @@
DNS_SRV_PREFIX_##TYPE, \
strlen(DNS_SRV_PREFIX_##TYPE)) == 0)
-#define ROUTE_LIST(LOCAL, REMOTE) { \
- {REMOTE, LOCAL, "amq.direct"}, \
- {LOCAL, REMOTE, "amq.direct"}, \
- {REMOTE, LOCAL, "qmf.default.direct"}, \
- {LOCAL, REMOTE, "qmf.default.direct"}, \
- {REMOTE, LOCAL, "qmf.default.topic"}, \
- {LOCAL, REMOTE, "qmf.default.topic"} \
-}
-
-
-static int broker_federate(const char *local, const char *remote)
+static void
+mh_add_broker_route(const char *local, const char *remote,
+ const char *exchange, const char *route_key, int srclocal,
+ int aggregate)
{
- int i;
- struct mh_qpid_route routes[] = ROUTE_LIST(local, remote);
+ int ret;
+ struct mh_qpid_route *route;
+
+ route = malloc(sizeof(*route));
+ route->src = local;
+ route->dest = remote;
+ route->exchange = exchange;
+ route->route_key = route_key;
+ route->srclocal = srclocal;
+ route->aggregate = aggregate;
mh_trace("Adding routes for federated broker \"%s\"", remote);
+ ret = broker_os_add_qpid_route(route);
+ if (ret) {
+ mh_err("Failed to add federated broker \"%s\"", remote);
+ }
+ free(route);
+}
- for (i = 0; i < DIMOF(routes); i++) {
- int ret = broker_os_add_qpid_route(&routes[i]);
- if (ret) {
- mh_err("Failed to add federated broker \"%s\"", remote);
- return ret;
- }
+static int
+broker_federate(const char *local, const char *remote, int route_type)
+{
+ int ret = broker_os_add_qpid_route_link(local, remote);
+ if (ret) {
+ mh_err("Failed to link brokers \"%s\" to \"%s\"", local, remote);
+ return ret;
+ }
+
+ if (route_type) {
+ mh_add_broker_route(local, remote, "qmf.default.topic", "direct-agent.#", FALSE, TRUE);
+ mh_add_broker_route(local, remote, "qmf.default.topic", "console.#", FALSE, TRUE);
+ mh_add_broker_route(remote, local, "qmf.default.topic", "direct-console.#", TRUE, TRUE);
+ mh_add_broker_route(remote, local, "qmf.default.topic", "agent.#", TRUE, TRUE);
+ } else {
+ mh_add_broker_route(remote, local, "amq.direct", NULL, FALSE, FALSE);
+ mh_add_broker_route(local, remote, "amq.direct", NULL, FALSE, FALSE);
+ mh_add_broker_route(remote, local, "qmf.default.direct", NULL, FALSE, FALSE);
+ mh_add_broker_route(local, remote, "qmf.default.direct", NULL, FALSE, FALSE);
+ mh_add_broker_route(remote, local, "qmf.default.topic", NULL, FALSE, FALSE);
+ mh_add_broker_route(local, remote, "qmf.default.topic", NULL, FALSE, FALSE);
}
return 0;
}
-static char *broker_lookup(const char *query)
+static char *
+broker_lookup(const char *query)
{
#ifdef HAVE_RESOLV_H
static char broker[1025 + 6];
@@ -90,30 +114,39 @@ static char *broker_lookup(const char *query)
return NULL;
}
-void broker_federation_configure(void)
+void
+broker_federation_configure(void)
{
const char *brokers = getenv("FEDERATED_BROKERS");
+ const char *proxy_service_port = getenv("VP_G_SERVICE_PORT");
+ const char *proxy_service_dir = getenv("VP_G_HOST_DIR");
char local[16];
char peers[1024];
char *p = NULL;
char *peer;
- if (!brokers) {
- return;
- }
+ if (g_file_test(proxy_service_dir, G_FILE_TEST_IS_DIR)) {
+ char remote[16];
+ snprintf(remote, sizeof(local), "localhost:%s", proxy_service_port);
+ snprintf(local, sizeof(remote), "localhost:%hu", broker_get_port());
+ broker_federate(local, remote, TRUE);
+ } else if (brokers) {
+ snprintf(local, sizeof(local), "localhost:%hu", broker_get_port());
- snprintf(local, sizeof(local), "localhost:%hu", broker_get_port());
+ mh_string_copy(peers, brokers, sizeof(peers));
- mh_string_copy(peers, brokers, sizeof(peers));
+ while ((peer = strtok_r(p ? NULL : peers, ",; ", &p)) != NULL) {
+ if (IS_DNS_SRV(peer, TCP) || IS_DNS_SRV(peer, TLS)) {
+ peer = broker_lookup(peer);
+ }
- while ((peer = strtok_r(p ? NULL : peers, ",; ", &p)) != NULL) {
- if (IS_DNS_SRV(peer, TCP) || IS_DNS_SRV(peer, TLS)) {
- peer = broker_lookup(peer);
+ if (peer) {
+ broker_federate(local, peer, FALSE);
+ }
}
- if (peer) {
- broker_federate(local, peer);
- }
+ } else {
+ return;
}
}
diff --git a/src/broker/broker_linux.c b/src/broker/broker_linux.c
index 997734f..8d5689d 100644
--- a/src/broker/broker_linux.c
+++ b/src/broker/broker_linux.c
@@ -55,14 +55,37 @@ int broker_os_start_broker(char * const args[])
}
}
-int broker_os_add_qpid_route(const struct mh_qpid_route *route)
+int broker_os_add_qpid_route_link(const char *local, const char *remote)
{
char cmd[1024];
int ret;
- snprintf(cmd, sizeof(cmd), "qpid-route --timeout=5 dynamic add %s %s %s",
- route->dest, route->src, route->exchange);
+ snprintf(cmd, sizeof(cmd), "qpid-route link add %s untrusted/untrusted@%s PLAIN",
+ local, remote);
+
+ ret = system(cmd);
+
+ if (ret < 0) {
+ perror("system()");
+ }
+ return ret;
+}
+
+int broker_os_add_qpid_route(const struct mh_qpid_route *route)
+{
+ char cmd[1024];
+ int ret;
+ if (route->aggregate && route->srclocal) {
+ snprintf(cmd, sizeof(cmd), "qpid-route --src-local route add %s %s %s %s",
+ route->dest, route->src, route->exchange, route->route_key);
+ } else if (route->aggregate) {
+ snprintf(cmd, sizeof(cmd), "qpid-route route add %s %s %s %s",
+ route->dest, route->src, route->exchange, route->route_key);
+ } else {
+ snprintf(cmd, sizeof(cmd), "qpid-route --timeout=5 dynamic add %s %s %s",
+ route->dest, route->src, route->exchange);
+ }
ret = system(cmd);
if (ret < 0) {
diff --git a/src/broker/broker_os.h b/src/broker/broker_os.h
index 788fe78..7f8f8a9 100644
--- a/src/broker/broker_os.h
+++ b/src/broker/broker_os.h
@@ -31,6 +31,9 @@ struct mh_qpid_route {
const char *dest; /**< The route destination */
const char *src; /**< The route source */
const char *exchange; /**< The exchange */
+ const char *route_key; /**< The routing key */
+ int srclocal; /**< Is this route static? */
+ int aggregate; /**< Is this route part of aggregate? */
};
@@ -42,6 +45,14 @@ struct mh_qpid_route {
int broker_os_start_broker(char * const args[]);
/**
+ * Add a route link between two Qpid brokers.
+ * @param local local broker to link
+ * @param remote remote broker to link
+ * @return -1 on error, otherwise the result of the external route add command.
+ */
+int broker_os_add_qpid_route_link(const char *local, const char *remote);
+
+/**
* Add a route between two Qpid brokers.
* @param route pointer to the route to add
* @return -1 on error, otherwise the result of the external route add command.
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 5417680..7a5d7dc 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -445,11 +445,12 @@ mh_parse_options(const char *proc_name, int argc, char **argv, OptionsMap &optio
options["protocol"] = "tcp";
options["serverport"] = "49000";
amqp_options["reconnect"] = true;
+ amqp_options["strict-security"] = true;
/* Force local-only handling */
mh_add_option('b', required_argument, "broker", "specify broker host name", &options, map_option);
mh_add_option('D', no_argument, "dns-srv", "interpret the value of --broker as a domain name for DNS SRV lookups", &options, map_option);
- mh_add_option('p', required_argument, "port", "specify broker ", &options, map_option);
+ mh_add_option('p', required_argument, "port", "specify broker port", &options, map_option);
mh_add_option('v', no_argument, "verbose", "Increase the log level", NULL, map_option);
mh_add_option('u', required_argument, "username", "username to use for authentication to the broker", &amqp_options, connection_option);
--
1.7.6.4
12 years, 6 months
[PATCH 1/2] services: systemd support in Resources API v2
by Radek Novacek
* Systemd is now standard for Resources. It uses systemctl command to list
services and invoke actions.
* List of supported standards has been moved from agents to services
library. It's now function instead of global list.
* Make DBus invoke method asynchronous to ensure same behaviour as QMF
agent.
* Make standard and provider case insensitive
* Disable interval for invoke method in DBus agent because dbus can't
emit events (might use signal in the future).
Signed-off-by: Radek Novacek <rnovacek(a)redhat.com>
---
src/include/matahari/services.h | 11 ++++++
src/lib/mh_dbus_common.c | 2 +
src/lib/services.c | 40 ++++++++++++++++++---
src/lib/services_linux.c | 39 ++++++++++++++++++++-
src/lib/services_private.h | 5 ++-
src/service/service-dbus.c | 73 +++++++++++++++++++++++----------------
src/service/service-qmf.cpp | 44 ++++++++++-------------
7 files changed, 151 insertions(+), 63 deletions(-)
diff --git a/src/include/matahari/services.h b/src/include/matahari/services.h
index 82d0aa9..6e61b4d 100644
--- a/src/include/matahari/services.h
+++ b/src/include/matahari/services.h
@@ -33,6 +33,8 @@
#define OCF_ROOT "/usr/lib/ocf"
#define LSB_ROOT "/etc/init.d"
+#define SYSTEMCTL "/bin/systemctl"
+
enum lsb_exitcode {
LSB_OK = 0,
LSB_UNKNOWN_ERROR = 1,
@@ -180,6 +182,15 @@ resources_list_providers(const char *standard);
GList *
resources_list_agents(const char *standard, const char *provider);
+/**
+ * Get list of available standards
+ *
+ * \return a list of resource standards. The list items are char *. This list _must_
+ * be destroyed using g_list_free_full(list, free).
+ */
+GList *
+resources_list_standards(void);
+
svc_action_t *
services_action_create(const char *name, const char *action,
int interval /* ms */, int timeout /* ms */);
diff --git a/src/lib/mh_dbus_common.c b/src/lib/mh_dbus_common.c
index be58428..874b207 100644
--- a/src/lib/mh_dbus_common.c
+++ b/src/lib/mh_dbus_common.c
@@ -24,6 +24,7 @@
#include "matahari/dbus_common.h"
#include "matahari/logging.h"
+#include "matahari/mainloop.h"
#include "matahari/errors.h"
#include <glib/gi18n.h>
@@ -207,6 +208,7 @@ run_dbus_server(char *bus_name, char *object_path)
return 1;
}
+ mainloop_track_children(G_PRIORITY_DEFAULT);
g_main_loop_run(loop);
g_main_loop_unref(loop);
g_object_unref(obj);
diff --git a/src/lib/services.c b/src/lib/services.c
index 6ab5a66..3241002 100644
--- a/src/lib/services.c
+++ b/src/lib/services.c
@@ -96,7 +96,7 @@ svc_action_t *resources_action_create(
op->sequence = ++operations;
asprintf(&op->id, "%s_%s_%d", name, action, interval);
- if(strcmp(standard, "ocf") == 0) {
+ if(strcasecmp(standard, "ocf") == 0) {
op->provider = strdup(provider);
op->params = params;
@@ -105,9 +105,16 @@ svc_action_t *resources_action_create(
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(action);
- } else if(strcmp(standard, "lsb") == 0 || strcmp(standard, "windows") == 0) {
+ } else if(strcasecmp(standard, "lsb") == 0 || strcasecmp(standard, "windows") == 0) {
services_os_set_exec(op);
+ } else if(strcasecmp(standard, "systemd") == 0) {
+ char *service;
+ op->opaque->exec = strdup(SYSTEMCTL);
+ op->opaque->args[0] = strdup(SYSTEMCTL);
+ op->opaque->args[1] = strdup(action);
+ asprintf(&service, "%s.service", agent);
+ op->opaque->args[2] = service;
} else {
mh_err("Unknown resource standard: %s", standard);
services_action_free(op);
@@ -253,9 +260,25 @@ services_list(void)
}
GList *
+resources_list_standards(void)
+{
+ GList *standards = NULL;
+#ifdef __linux__
+ standards = g_list_append(standards, strdup("ocf"));
+ standards = g_list_append(standards, strdup("lsb"));
+ if (g_file_test(SYSTEMCTL, G_FILE_TEST_IS_REGULAR))
+ standards = g_list_append(standards, strdup("systemd"));
+#endif
+#ifdef WIN32
+ standards = g_list_append(standards, strdup("windows"));
+#endif
+ return standards;
+}
+
+GList *
resources_list_providers(const char *standard)
{
- if(strcmp(standard, "ocf") == 0) {
+ if (strcasecmp(standard, "ocf") == 0) {
return resources_os_list_ocf_providers();
}
@@ -265,12 +288,17 @@ resources_list_providers(const char *standard)
GList *
resources_list_agents(const char *standard, const char *provider)
{
- if(strcmp(standard, "ocf") == 0) {
+ if (strcasecmp(standard, "ocf") == 0) {
return resources_os_list_ocf_agents(provider);
- } else if(strcmp(standard, "lsb") == 0
- || strcmp(standard, "windows") == 0) {
+ } else if (strcasecmp(standard, "lsb") == 0
+ || strcasecmp(standard, "windows") == 0) {
return services_os_list();
+
+#ifdef __linux__
+ } else if (strcasecmp(standard, "systemd") == 0) {
+ return resources_os_list_systemd_services();
+#endif
}
return NULL;
diff --git a/src/lib/services_linux.c b/src/lib/services_linux.c
index 7760913..d2f8135 100644
--- a/src/lib/services_linux.c
+++ b/src/lib/services_linux.c
@@ -142,7 +142,7 @@ set_ocf_env_with_prefix(gpointer key, gpointer value, gpointer user_data)
static void
add_OCF_env_vars(svc_action_t *op)
{
- if (!op->standard || strcmp("ocf", op->standard) != 0) {
+ if (!op->standard || strcasecmp("ocf", op->standard) != 0) {
return;
}
@@ -503,3 +503,40 @@ resources_os_list_ocf_agents(const char *provider)
}
return NULL;
}
+
+GList *
+resources_os_list_systemd_services(void)
+{
+ GList *list = NULL;
+ char *ptr, *service, *end;
+ svc_action_t *action;
+ int len;
+ const char *args[] = { "list-units", "--all", "--type=service", "--full",
+ "--no-pager", NULL };
+
+ if (!(action = mh_services_action_create_generic(SYSTEMCTL, args))) {
+ return NULL;
+ }
+ if (!services_action_sync(action)) {
+ services_action_free(action);
+ return NULL;
+ }
+ ptr = action->stdout_data;
+ // Skip first line with column labels
+ while ((ptr = strchr(ptr, '\n')) != NULL) {
+ // Skip the line break
+ ptr++;
+
+ // Read beggining of the line until ".service"
+ if (!(end = strstr(ptr, ".service")))
+ break;
+ // Length of service name
+ len = end - ptr;
+ // Append the name to the list of services
+ service = malloc(sizeof(char) * (len + 1));
+ service = mh_string_copy(service, ptr, len + 1);
+ list = g_list_append(list, service);
+ }
+ services_action_free(action);
+ return list;
+}
diff --git a/src/lib/services_private.h b/src/lib/services_private.h
index d7931dc..dada879 100644
--- a/src/lib/services_private.h
+++ b/src/lib/services_private.h
@@ -21,7 +21,7 @@
struct svc_action_private_s {
char *exec;
- char *args[4];
+ char *args[7];
guint repeat_timer;
void (*callback)(svc_action_t *op);
@@ -51,4 +51,7 @@ resources_os_list_ocf_providers(void);
GList *
resources_os_list_ocf_agents(const char *provider);
+GList *
+resources_os_list_systemd_services(void);
+
#endif /* __MH_SERVICES_PRIVATE_H__ */
diff --git a/src/service/service-dbus.c b/src/service/service-dbus.c
index aefb842..e22e427 100644
--- a/src/service/service-dbus.c
+++ b/src/service/service-dbus.c
@@ -229,22 +229,14 @@ Services_describe(Matahari *matahari, const char *name,
return TRUE;
}
-// TODO: This and same code in service-qmf.cpp should go to the library
-const char *standards[] = {
-#ifdef __linux__
- "ocf",
-#endif
- "lsb",
-#ifndef WIN32
- "windows",
-#endif
- NULL};
-
-
gboolean
Resources_list_standards(Matahari *matahari, DBusGMethodInvocation *context)
{
GError* error = NULL;
+ gchar **list;
+ int i = 0;
+ GList *standards;
+
if (!check_authorization(RESOURCES_INTERFACE_NAME ".list_standards",
&error, context)) {
dbus_g_method_return_error(context, error);
@@ -252,7 +244,17 @@ Resources_list_standards(Matahari *matahari, DBusGMethodInvocation *context)
return FALSE;
}
- dbus_g_method_return(context, standards);
+ standards = resources_list_standards();
+
+ // Convert GList to (char **)
+ list = g_new(char *, g_list_length(standards) + 1);
+ for (; standards != NULL; standards = standards->next)
+ list[i++] = strdup(standards->data);
+ list[i] = NULL; // Sentinel
+
+ dbus_g_method_return(context, list);
+ g_strfreev(list);
+ g_list_free_full(standards, free);
return TRUE;
}
@@ -343,6 +345,19 @@ Resources_describe(Matahari *matahari, const char *standard,
return TRUE;
}
+struct invoke_cb_data {
+ DBusGMethodInvocation *context;
+ char *userdata;
+};
+
+void invoke_cb(svc_action_t *op)
+{
+ struct invoke_cb_data *cb_data = op->cb_data;
+ dbus_g_method_return(cb_data->context, op->rc, op->sequence, cb_data->userdata);
+ free(cb_data->userdata);
+ free(cb_data);
+}
+
gboolean
Resources_invoke(Matahari *matahari, const char *name, const char *standard,
const char *provider, const char *agent, const char *action,
@@ -350,10 +365,9 @@ Resources_invoke(Matahari *matahari, const char *name, const char *standard,
unsigned int timeout, unsigned int expected_rc,
const char *userdata_in, DBusGMethodInvocation *context)
{
- int i = 0;
GError* error = NULL;
svc_action_t *op = NULL;
- gboolean valid_standard = FALSE;
+ GList *standards;
if (!check_authorization(RESOURCES_INTERFACE_NAME ".invoke",
&error, context)) {
@@ -363,31 +377,30 @@ Resources_invoke(Matahari *matahari, const char *name, const char *standard,
}
// Check if standard is valid
- while (standards[i] != NULL)
- {
- if (strcmp(standard, standards[i]) == 0)
- {
- valid_standard = TRUE;
- break;
- }
- i++;
- }
- if (!valid_standard) {
+ standards = resources_list_standards();
+
+ if (g_list_find_custom(standards, standard, (GCompareFunc) strcasecmp) == NULL) {
mh_err("%s is not a known resource standard", standard);
error = g_error_new(MATAHARI_ERROR, MH_RES_NOT_IMPLEMENTED,
"%s is not a known resource standard", standard);
dbus_g_method_return_error(context, error);
g_error_free(error);
+ g_list_free_full(standards, free);
return FALSE;
}
+ g_list_free_full(standards, free);
op = resources_action_create(name, standard, provider, agent, action,
- interval, timeout, parameters);
+ 0, timeout, g_hash_table_ref(parameters));
op->expected_rc = expected_rc;
- services_action_sync(op); //TODO: maybe async
- dbus_g_method_return(context, op->rc, op->sequence, userdata_in);
- return TRUE;
+ struct invoke_cb_data *data = malloc(1 * sizeof(struct invoke_cb_data));
+ data->context = context;
+ data->userdata = strdup(userdata_in);
+ op->cb_data = data;
+
+ services_action_async(op, invoke_cb);
+ return FALSE;
}
gboolean
@@ -403,7 +416,7 @@ Resources_cancel(Matahari *matahari, const char *name, const char *action,
return FALSE;
}
- services_action_cancel(name, action, interval);
+ services_action_cancel(name, action, 0);
dbus_g_method_return(context);
return TRUE;
}
diff --git a/src/service/service-qmf.cpp b/src/service/service-qmf.cpp
index 63f5db2..6aa4904 100644
--- a/src/service/service-qmf.cpp
+++ b/src/service/service-qmf.cpp
@@ -55,8 +55,6 @@ private:
qmf::Data _resources;
static const char RESOURCES_NAME[];
- _qtype::Variant::List standards;
-
gboolean invoke_services(qmf::AgentSession session,
qmf::AgentEvent event, gpointer user_data);
gboolean invoke_resources(qmf::AgentSession session,
@@ -219,14 +217,6 @@ SrvAgent::raiseEvent(svc_action_t *op, enum service_id service, const std::strin
int
SrvAgent::setup(qmf::AgentSession session)
{
-#ifdef __linux__
- standards.push_back("ocf");
- standards.push_back("lsb");
-#endif
-#ifndef WIN32
- standards.push_back("windows");
-#endif
-
_package.configure(session);
_services = qmf::Data(_package.data_Services);
@@ -347,7 +337,17 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
qpid::types::Variant::Map& args = event.getArguments();
if (methodName == "list_standards") {
- event.addReturnArgument("standards", standards);
+ GList *gIter = NULL;
+ GList *standards = NULL;
+ _qtype::Variant::List s_list;
+
+ standards = resources_list_standards();
+ for (gIter = standards; gIter != NULL; gIter = gIter->next) {
+ s_list.push_back((const char *) gIter->data);
+ }
+ g_list_free_full(standards, free);
+
+ event.addReturnArgument("standards", s_list);
} else if (methodName == "list_providers") {
GList *gIter = NULL;
@@ -387,7 +387,6 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
} else if (methodName == "invoke") {
svc_action_t *op = NULL;
- bool valid_standard = false;
_qtype::Variant::List::iterator iter;
_qtype::Variant::Map map;
@@ -403,19 +402,6 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
std::string standard("ocf");
std::string provider("heartbeat");
- for ( iter=standards.begin() ; iter != standards.end(); iter++ ) {
- if(args["standard"].asString() == (*iter).asString()) {
- valid_standard = true;
- break;
- }
- }
-
- if(valid_standard == false) {
- mh_err("%s is not a known resource standard", args["standard"].asString().c_str());
- session.raiseException(event, mh_result_to_str(MH_RES_NOT_IMPLEMENTED));
- return TRUE;
- }
-
if (args.count("standard")) {
standard = args["standard"].asString();
}
@@ -435,6 +421,14 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
timeout = args["timeout"].asInt32();
}
+ GList *standards = resources_list_standards();
+
+ if (g_list_find_custom(standards, standard.c_str(), (GCompareFunc) strcasecmp) == NULL) {
+ mh_err("%s is not a known resource standard", standard.c_str());
+ session.raiseException(event, mh_result_to_str(MH_RES_NOT_IMPLEMENTED));
+ return TRUE;
+ }
+
op = resources_action_create(
args["name"].asString().c_str(),
standard.c_str(), provider.c_str(), agent.c_str(),
--
1.7.6.4
12 years, 6 months
[PATCH] Broker: add acl support for a trusted broker
by Adam Stokes
Builds an access policy file so that an administrator
could bind an untrusted broker to a trusted. This allows
for setting up a push-route federation link from matahari
brokers that may reside on a qemu guest which would not
need extensive permissions in order to access a trusted broker.
See:
https://github.com/matahari/matahari/wiki/Using-a-Qpid-Broker-to-Aggregat...
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
CMakeLists.txt | 9 +++++++++
matahari-broker.conf.in | 5 +++++
matahari-policy.acl | 22 ++++++++++++++++++++++
matahari-sasl.conf.in | 3 +++
matahari.spec.in | 5 +++++
5 files changed, 44 insertions(+), 0 deletions(-)
create mode 100644 matahari-policy.acl
create mode 100644 matahari-sasl.conf.in
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 077687d..6eadedf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -132,6 +132,9 @@ else(WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-vios-proxy.sysconf.in
${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy.sysconf @ONLY)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/matahari-sasl.conf.in
+ ${CMAKE_CURRENT_BINARY_DIR}/matahari-sasl.conf conf @ONLY)
+
install(DIRECTORY DESTINATION ${localstatedir}/lib/matahari
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE)
@@ -148,6 +151,12 @@ else(WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-broker.conf DESTINATION ${sysconfdir})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-vios-proxy.sysconf DESTINATION ${sysconfdir}/sysconfig RENAME matahari-vios-proxy)
+
+ # ACL Policy
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-policy.acl DESTINATION share/matahari)
+
+ # SASL
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-sasl.conf DESTINATION ${sysconfdir}/sasl2)
# Check for systemd
include(FindPkgConfig)
diff --git a/matahari-broker.conf.in b/matahari-broker.conf.in
index 8aeec38..c082bb2 100644
--- a/matahari-broker.conf.in
+++ b/matahari-broker.conf.in
@@ -23,3 +23,8 @@
# "qpidd --help" or "man qpidd" for more details.
cluster-mechanism=ANONYMOUS
auth=no
+
+# ACL
+# acl-file=/usr/share/matahari/matahari-policy.acl
+# SASL
+# sasl-config=/etc/sasl2/matahari-sasl.conf
diff --git a/matahari-policy.acl b/matahari-policy.acl
new file mode 100644
index 0000000..9e24320
--- /dev/null
+++ b/matahari-policy.acl
@@ -0,0 +1,22 @@
+group consoles consoleuser@QPID
+
+acl allow consoles create exchange name=qmf.default.direct
+acl allow consoles access exchange name=qmf.default.direct
+acl allow consoles bind exchange name=qmf.default.topic routingkey=direct-console.*
+acl allow consoles bind exchange name=qmf.default.topic routingkey=agent.*
+acl allow consoles publish exchange name=qmf.default.topic routingkey=direct-agent.*
+acl allow consoles publish exchange name=qmf.default.topic routingkey=console.*
+acl allow consoles publish exchange name=qmf.default.direct routingkey=broker
+
+acl allow all bind exchange name=qmf.default.topic routingkey=direct-agent.*
+acl allow all bind exchange name=qmf.default.topic routingkey=console.*
+acl allow all publish exchange name=qmf.default.topic routingkey=direct-console.*
+acl allow all publish exchange name=qmf.default.topic routingkey=agent.*
+acl allow all create link
+
+acl allow all create queue
+acl allow all create exchange name=qmf.default.topic
+acl allow all access exchange name=qmf.default.topic
+acl allow all consume
+
+acl deny all all
diff --git a/matahari-sasl.conf.in b/matahari-sasl.conf.in
new file mode 100644
index 0000000..8ce3e99
--- /dev/null
+++ b/matahari-sasl.conf.in
@@ -0,0 +1,3 @@
+mech_list: plain
+sasldb_path: @localstatedir(a)/lib/matahari/matahari.sasldb
+auxprop_plugin: sasldb
diff --git a/matahari.spec.in b/matahari.spec.in
index 130c4d8..0728a04 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -365,6 +365,9 @@ systemctl --system daemon-reload
/sbin/chkconfig --add matahari-broker
%endif
/sbin/service matahari-broker condrestart
+# SASL
+echo consoleuser | saslpasswd2 -f %{_localstatedir}/lib/matahari/matahari.sasldb -c consoleuser@QPID -p
+echo untrusted | saslpasswd2 -f %{_localstatedir}/lib/matahari/matahari.sasldb -c untrusted@QPID -p
%preun broker
if [ $1 = 0 ]; then
@@ -567,8 +570,10 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%endif
%config(noreplace) %{_sysconfdir}/sysconfig/matahari-broker
%config(noreplace) %{_sysconfdir}/matahari-broker.conf
+%config(noreplace) %{_sysconfdir}/sasl2/matahari-sasl.conf
%attr(755, root, root) %{_sbindir}/matahari-brokerd
%{_mandir}/man8/matahari-brokerd.8*
+%{_datadir}/matahari/matahari-policy.acl
%doc AUTHORS COPYING
%if %{systemd}
--
1.7.6.4
12 years, 6 months