Skip to content

Commit

Permalink
Change way to run alignak-app
Browse files Browse the repository at this point in the history
Now create a script inside user bin.
alignak-app can be launch everywhere.
Fix the logs inside user bin.
  • Loading branch information
algorys committed Oct 7, 2016
1 parent a3c0856 commit b6ad770
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
10 changes: 5 additions & 5 deletions alignak_app/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def launch():
"""

# Actually, we must verify we are in DESKTOP_SESSION or not
try:
os.environ['DESKTOP_SESSION']
except KeyError as e:
logger.critical('You must be in desktop session to launch Alignak-App : ' + str(e))
sys.exit()
# try:
# os.environ['DESKTOP_SESSION']
# except KeyError as e:
# logger.critical('You must be in desktop session to launch Alignak-App : ' + str(e))
# sys.exit()

App().run()

Expand Down
19 changes: 11 additions & 8 deletions alignak_app/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from logging import Formatter
from logging import DEBUG
from logging import StreamHandler
from logging.handlers import TimedRotatingFileHandler
import os
import sys


def create_logger(logger):
Expand All @@ -37,8 +37,17 @@ def create_logger(logger):
:param logger: the main logger.
:type logger: :class:`~`
"""
path = 'logs'

# Get HOME to make log dir
home = os.environ['HOME']
if 'root' in home or not home:
sys.exit('Application can\'t find the user HOME or maybe you are connected as ROOT.')
if home.endswith('/'):
home = home[:-1]

path = home + '/bin/alignak_app/'
filename = 'alignakapp.log'

if not os.path.isdir(path):
# noinspection PyBroadException
try: # pragma: no cover - not testable
Expand All @@ -62,10 +71,4 @@ def create_logger(logger):
file_handler.setFormatter(formatter)

logger.addHandler(file_handler)

# TEMPORARY: create a second handler for console output.
steam_handler = StreamHandler()
steam_handler.setLevel(DEBUG)

logger.setLevel(DEBUG)
logger.addHandler(steam_handler)
4 changes: 4 additions & 0 deletions etc/bin/alignak-app
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Alignak-app start !"
python $HOME/bin/alignak_app/launch.py &
43 changes: 35 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# along with (AlignakApp). If not, see <http://www.gnu.org/licenses/>.

import sys
from importlib import import_module
import os
import subprocess

try:
from setuptools import setup, find_packages
Expand All @@ -41,12 +42,27 @@
'alignak_backend_client'
]

# Get HOME and USER
home = os.environ['HOME']
if 'root' in home or not home:
sys.exit('Application can\'t find the user HOME or maybe you are connected as ROOT.')
if home.endswith('/'):
home = home[:-1]
home += '/bin'

print('HOME = ' + home)

user = home.split('/')[2]

print('USER = ' + user)

# Define paths
paths = {}
if 'linux' in sys.platform or 'sunos5' in sys.platform:
paths = {
'etc': "/etc/alignak_app",
'log': "/var/log/alignak_app",
'etc': "/etc/alignak_app",
'log': home + "alignak_app/logs",
'bin': home,
}
else:
print("Unsupported platform, sorry!")
Expand Down Expand Up @@ -89,15 +105,17 @@
(paths['etc'] + '/images', ['etc/images/service_critical.svg']),
(paths['etc'] + '/images', ['etc/images/service_warning.svg']),
(paths['etc'] + '/images', ['etc/images/service_unknown.svg']),
(paths['bin'], ['etc/bin/alignak-app']),
(paths['bin'] + '/alignak_app', ['alignak_app/launch.py']),
],

install_requires=install_requires,

entry_points={
'gui_scripts': [
'alignak_app = alignak_app.launch:launch',
],
},
# entry_points={
# 'gui_scripts': [
# 'alignak_app = alignak_app.launch:launch',
# ],
# },

classifiers = [
'Development Status :: 4 - Beta',
Expand All @@ -116,3 +134,12 @@

)

cmd = 'sudo chown -R ' + user + ':' + user + ' ~/bin'
try:
subprocess.Popen(cmd,
shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except Exception:
print('ERROR : Alignak-app failed to give the necessary rights !')

0 comments on commit b6ad770

Please sign in to comment.