aura.py 3.22 KB
Newer Older
1
#!/usr/bin/python3.5
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
#  engine
#
#  Playout Daemon for autoradio project
#
#
#  Copyright (C) 2017-2018 Gottfried Gaisbauer <gottfried.gaisbauer@servus.at>
#
#  This file is part of engine.
#
#  engine is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  any later version.
#
#  engine is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with engine. If not, see <http://www.gnu.org/licenses/>.
#

27
import os
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
28
29
30
import sys
import signal
import unittest
31

32
33
from modules.scheduling.scheduler import AuraScheduler
from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator
34
from modules.communication.redis.adapter import ServerRedisAdapter
35
from modules.web.routes import Routes
36
from modules.monitoring.diskspace_watcher import DiskSpaceWatcher
37
from libraries.base.logger import AuraLogger
38

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
39
40
41
from testing.test import TestConfig, TestLogger

class Aura(AuraLogger):
42
    server = None
43
    messenger = None
44
    controller = None
45

46
    # ------------------------------------------------------------------------------------------ #
47
    def __init__(self):
48
        super(Aura, self).__init__()
49

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
50
51
    def startup(self):

52
        # self.controller = AuraController(self.config)
53
54
55
        # create scheduler and ls_communicator
        self.liquidsoapcommunicator = LiquidSoapCommunicator(self.config)
        self.scheduler = AuraScheduler(self.config)
56

57
58
59
60
61
        # give both a reference of each other
        self.liquidsoapcommunicator.scheduler = self.scheduler
        self.scheduler.liquidsoapcommunicator = self.liquidsoapcommunicator

        # create the redis adapter
62
        self.messenger = ServerRedisAdapter(self.config)
63
64
        self.messenger.scheduler = self.scheduler
        self.messenger.liquidsoapcommunicator = self.liquidsoapcommunicator
65

66
67
        #self.diskspace_watcher = DiskSpaceWatcher(self.config, self.logger, self.liquidsoapcommunicator)
        #self.diskspace_watcher.start()
68

69
        # and finally wait for redis message
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
70
        self.join_comm()
71

72
        # start the web service
73
        self.start_web_service()
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
74

75

76
    def join_comm(self):
77
        # start listener thread
78
        self.messenger.start()
79

80
    def start_web_service(self):
81
        try:
82
            self.logger.info("Listening on Port 5000 for API or Webcalls")
83
            Routes(self.scheduler, self.liquidsoapcommunicator, self.messenger, self.config)
84
85
86
        except OSError as e:
            self.messenger.halt()
            self.logger.critical("AuraEngine already running? Exception: " + e.strerror + ". Exiting...")
87
            os._exit(0)
88

89

90
91
92
93
94
# # ## ## ## ## ## # #
# # ENTRY FUNCTION # #
# # ## ## ## ## ## # #
def main():
    aura = Aura()
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
95

96
97
98
99
    if len(sys.argv) >= 2 and "--use-test-data" in sys.argv:
        aura.config.set("use_test_data", True)

    aura.startup()
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
100
101


102
103
104
105
# # ## ## ## ## ## ## # #
# # End ENTRY FUNCTION # #
# # ## ## ## ## ## ## # #

106

107
if __name__ == "__main__":
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
108
    main()