1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Added support for OpenSuse also (and created a build script)

Fixed up & tuning of actor
This commit is contained in:
Adolfo Gómez García 2014-12-04 12:45:55 +01:00
parent 42e8213442
commit 2159e0f29d
10 changed files with 173 additions and 45 deletions

1
actors/linux/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/udsactor-opensuse-1.7.0.spec

View File

@ -1,13 +1,30 @@
#!/bin/bash
VERSION=1.7.0
RELEASE=1
top=`pwd`
rm -rf rpm
for folder in SOURCES BUILD RPMS SPECS SRPMS; do
mkdir -p rpm/$folder
done
for pkg in udsactor-1.7.0.spec udsactor-xrdp-1.7.0.spec; do
rpmbuild -v -bb --clean --target noarch $pkg 2>&1
cat udsactor-template.spec |
sed -e s/"version 1.7.0"/"version ${VERSION}"/g |
sed -e s/"release 1"/"release ${RELEASE}"/g > udsactor-$VERSION.spec
# Now fix dependencies for opensuse
cat udsactor-template.spec |
sed -e s/"name udsactor"/"name udsactor-opensuse"/g |
sed -e s/"PyQt4"/"python-qt4"/g |
sed -e s/"libXScrnSaver"/"libXss1"/g > udsactor-opensuse-$VERSION.spec
# Right now, udsactor-xrdp-1.7.0.spec is not needed
for pkg in udsactor-$VERSION.spec udsactor-opensuse-$VERSION.spec; do
rm -rf rpm
for folder in SOURCES BUILD RPMS SPECS SRPMS; do
mkdir -p rpm/$folder
done
rpmbuild -v -bb --clean --buildroot=$top/rpm/BUILD/$pkg-root --target noarch $pkg 2>&1
done
#rm udsactor-$VERSION

View File

@ -1,10 +1,10 @@
#!/bin/sh
# Simple hack to wait for systray to be present
sleep 5
# Exec tool if not already runned by session manager
ps -ef | grep "$USER" | grep -v grep | grep 'UDSActorTool' -q
ps -ef | grep "$USER" | grep -v grep | grep -v UDSActorTool-startup | grep 'UDSActorTool' -q
# If not already running
if [ $? -eq 1 ]; then
sleep 5
exec /usr/bin/UDSActorTool
fi

View File

@ -0,0 +1,69 @@
%define _topdir %(echo $PWD)/rpm
%define name udsactor
%define version 1.7.0
%define release 1
%define buildroot %{_topdir}/%{name}-%{version}-%{release}-root
BuildRoot: %{buildroot}
Name: %{name}
Version: %{version}
Release: %{release}
Summary: Actor for Universal Desktop Services (UDS) Broker
License: BSD3
Group: Admin
Requires: python-six python-requests PyQt4 libXScrnSaver
Vendor: Virtual Cable S.L.U.
URL: http://www.udsenterprise.com
Provides: udsactor
%define _rpmdir ../
%define _rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
%install
curdir=`pwd`
cd ../..
make DESTDIR=$RPM_BUILD_ROOT DISTRO=rh install-udsactor
cd $curdir
%clean
rm -rf $RPM_BUILD_ROOT
curdir=`pwd`
cd ../..
make DESTDIR=$RPM_BUILD_ROOT DISTRO=rh clean
cd $curdir
%post
systemctl enable udsactor.service > /dev/null 2>&1
%preun
systemctl disable udsactor.service > /dev/null 2>&1
systemctl stop udsactor.service > /dev/null 2>&1
%postun
# $1 == 0 on uninstall, == 1 on upgrade for preun and postun (just a reminder for me... :) )
if [ $1 -eq 0 ]; then
rm -rf /etc/udsactor
rm /var/log/udsactor.log
fi
# And, posibly, the .pyc leaved behind on /usr/share/UDSActor
rm -rf /usr/share/UDSActor > /dev/null 2>&1
%description
This package provides the required components to allow this machine to work on an environment managed by UDS Broker.
%files
%defattr(-,root,root)
/etc/udsactor
/etc/xdg/autostart/UDSActorTool.desktop
/etc/init.d/udsactor
/usr/bin/UDSActorTool-startup
/usr/bin/udsactor
/usr/bin/UDSActorTool
/usr/sbin/UDSActorConfig
/usr/sbin/UDSActorConfig-pkexec
/usr/share/UDSActor/*
/usr/share/applications/UDS_Actor_Configuration.desktop
/usr/share/autostart/UDSActorTool.desktop
/usr/share/polkit-1/actions/org.openuds.pkexec.UDSActorConfig.policy

View File

@ -39,7 +39,6 @@ import logging
import json
import uuid
import six
import codecs
from udsactor.log import logger
@ -99,28 +98,11 @@ def ensureResultIsOk(result):
raise err
def unscramble(value):
if value is None or value == '':
return value
value = bytearray(codecs.decode(value, 'hex'))
n = 0x32
result = []
for ch in value:
c = ch ^ n
n = (n + c) & 0xFF
result.append(six.int2byte(c))
return b''.join(result)[::-1].decode('utf8')
class Api(object):
def __init__(self, host, masterKey, ssl, scrambledResponses=False):
def __init__(self, host, masterKey, ssl):
self.host = host
self.masterKey = masterKey
self.useSSL = ssl
self.scrambledResponses = scrambledResponses
self.uuid = None
self.mac = None
self.url = "{}://{}/rest/actor/".format(('http', 'https')[ssl], self.host)
@ -166,13 +148,6 @@ class Api(object):
ensureResultIsOk(r)
if self.scrambledResponses is True:
# test && init are not scrambled, even if rest of messages are
try:
r['result'] = unscramble(r['result'])
except Exception as e: # Can't unscramble, return result "as is"
r['warning'] = True
return r
@property

View File

@ -150,8 +150,8 @@ class Daemon:
if pid is None:
message = "pidfile {} does not exist. Daemon not running?\n".format(self.pidfile)
logger.error(message)
sys.stderr.write(message)
logger.info(message)
# sys.stderr.write(message)
return # not an error in a restart
# Try killing the daemon process

View File

@ -43,13 +43,13 @@ renamers = {}
# Renamers now are for IPv4 only addresses
def rename(newName):
distribution = platform.linux_distribution()[0].lower()
distribution = platform.linux_distribution()[0].lower().strip()
if distribution in renamers:
return renamers[distribution](newName)
# Try Debian renamer, simplest one
logger.info('Renamer for platform "{0}" not found, tryin debian renamer'.format(distribution))
return renamers['debian']
return renamers['debian'](newName)
# Do load of packages

View File

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
from udsactor.linux.renamer import renamers
from udsactor.log import logger
import os
def rename(newName):
'''
RH, Centos, Fedora Renamer
Expects new host name on newName
Host does not needs to be rebooted after renaming
'''
logger.debug('using SUSE renamer')
with open('/etc/hostname', 'w') as hostname:
hostname.write(newName)
# Force system new name
os.system('/bin/hostname %s' % newName)
# add name to "hosts"
with open('/etc/hosts', 'r') as hosts:
lines = hosts.readlines()
with open('/etc/hosts', 'w') as hosts:
hosts.write("127.0.1.1\t{}\n".format(newName))
for l in lines:
if l[:9] != '127.0.1.1': # Skips existing 127.0.1.1. if it already exists
hosts.write(l)
return True
# All names in lower case
renamers['opensuse'] = rename
renamers['suse'] = rename

View File

@ -86,7 +86,7 @@ class CommonService(object):
def setReady(self):
self.api.setReady([(v.mac, v.ip) for v in operations.getNetworkInfo()])
def interactWithBroker(self, scrambledResponses=False):
def interactWithBroker(self):
'''
Returns True to continue to main loop, false to stop & exit service
'''
@ -95,7 +95,7 @@ class CommonService(object):
logger.fatal('No configuration found, stopping service')
return False
self.api = REST.Api(cfg['host'], cfg['masterKey'], cfg['ssl'], scrambledResponses=scrambledResponses)
self.api = REST.Api(cfg['host'], cfg['masterKey'], cfg['ssl'])
# Wait for Broker to be ready
counter = 0
@ -125,7 +125,7 @@ class CommonService(object):
logger.fatal('This host is not managed by UDS Broker (ids: {})'.format(ids))
return False # On unmanaged hosts, there is no reason right now to continue running
except Exception as e:
logger.debug('Exception caugh: {}, retrying'.format(exceptionToMessage(e)))
logger.debug('Exception caught: {}, retrying'.format(exceptionToMessage(e)))
# Any other error is expectable and recoverable, so let's wait a bit and retry again
# but, if too many errors, will log it (one every minute, for
# example)
@ -176,7 +176,7 @@ class CommonService(object):
except Exception:
counter += 1
if counter % 60 == 0:
logger.warn('Too many retries in progress, though still trying (last error: {})'.format(e.message.decode('windows-1250', 'ignore')))
logger.warn('Too many retries in progress, though still trying (last error: {})'.format(exceptionToMessage(e)))
# Any other error is expectable and recoverable, so let's wait
# a bit and retry again
# Wait a bit before next check
@ -232,7 +232,7 @@ class CommonService(object):
self.ipc.start()
if self.api.mac in self.knownIps:
address = (self.knownIps[self.api.mac], random.randrange(32000, 64000))
address = (self.knownIps[self.api.mac], random.randrange(40000, 44000))
logger.debug('Starting REST listener at {}'.format(address))
self.httpServer = httpserver.HTTPServerThread(address, self.ipc)
self.httpServer.start()

View File

@ -180,7 +180,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
# ********************************************************
# * Ask brokers what to do before proceding to main loop *
# ********************************************************
if self.interactWithBroker(scrambledResponses=True) is False:
if self.interactWithBroker() is False:
logger.debug('Interact with broker returned false, stopping service after a while')
self.notifyStop()
win32event.WaitForSingleObject(self.hWaitStop, 5000)