mirror of
https://github.com/chillout2k/gulag.git
synced 2025-12-13 16:00:18 +00:00
uwsgi with vassals
This commit is contained in:
parent
feff285ee3
commit
e1dcba19c1
5
app/Entities.py
Normal file
5
app/Entities.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class Mailbox:
|
||||||
|
|
||||||
|
class QuarMail:
|
||||||
|
|
||||||
|
class Attachment:
|
||||||
@ -9,10 +9,12 @@ class GulagException(Exception):
|
|||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
class Gulag:
|
class Gulag:
|
||||||
|
version = None
|
||||||
config = None
|
config = None
|
||||||
db = None
|
db = None
|
||||||
|
|
||||||
def __init__(self, path_to_config_file):
|
def __init__(self, path_to_config_file):
|
||||||
|
self.version = "VERSION-TODO!"
|
||||||
try:
|
try:
|
||||||
with open(path_to_config_file, 'r') as f:
|
with open(path_to_config_file, 'r') as f:
|
||||||
self.config = json.load(f)
|
self.config = json.load(f)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from flask import request
|
from flask import request
|
||||||
from flask_restful import Resource, Api, abort
|
from flask_restful import Resource, abort
|
||||||
import json
|
import json
|
||||||
|
|
||||||
class GulagResource(Resource):
|
class GulagResource(Resource):
|
||||||
@ -29,9 +29,29 @@ class GulagResource(Resource):
|
|||||||
|
|
||||||
class ResRoot(GulagResource):
|
class ResRoot(GulagResource):
|
||||||
def get(self):
|
def get(self):
|
||||||
return {"resource": "root :)"}
|
return {"resource": "Root :)"}
|
||||||
|
|
||||||
|
class ResMailboxes(GulagResource):
|
||||||
|
def get(self):
|
||||||
|
return {"resource": "Mailboxes"}
|
||||||
|
|
||||||
|
class ResMailbox(GulagResource):
|
||||||
|
def get(self,id):
|
||||||
|
return {"resource": "Mailbox by ID"}
|
||||||
|
|
||||||
class ResQuarMails(GulagResource):
|
class ResQuarMails(GulagResource):
|
||||||
def get(self):
|
def get(self):
|
||||||
return {"abc": "1234"}
|
return {"resource": "QuarMails"}
|
||||||
# return self.gulag.get_quarmails()
|
|
||||||
|
class ResQuarMail(GulagResource):
|
||||||
|
def get(self,id):
|
||||||
|
return {"resource": "QuarMail by ID"}
|
||||||
|
|
||||||
|
class ResAttachments(GulagResource):
|
||||||
|
def get(self):
|
||||||
|
return {"resource": "Attachments"}
|
||||||
|
|
||||||
|
class ResAttachment(GulagResource):
|
||||||
|
def get(self,id):
|
||||||
|
return {"resource": "Attachment by ID"}
|
||||||
|
|
||||||
|
|||||||
BIN
app/__pycache__/Gulag.cpython-35.pyc
Normal file
BIN
app/__pycache__/Gulag.cpython-35.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/GulagDB.cpython-35.pyc
Normal file
BIN
app/__pycache__/GulagDB.cpython-35.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/GulagMailbox.cpython-35.pyc
Normal file
BIN
app/__pycache__/GulagMailbox.cpython-35.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/Resources.cpython-35.pyc
Normal file
BIN
app/__pycache__/Resources.cpython-35.pyc
Normal file
Binary file not shown.
54
app/gulag_helpers.py
Executable file
54
app/gulag_helpers.py
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse,sys,os,time,signal
|
||||||
|
from Gulag import Gulag,GulagException
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--config', required=True, help="Path to config file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
child_pids = []
|
||||||
|
importer_pid = os.fork()
|
||||||
|
if(importer_pid == 0):
|
||||||
|
# Child process: importer
|
||||||
|
try:
|
||||||
|
gulag = Gulag(args.config)
|
||||||
|
except GulagException as e:
|
||||||
|
print(e.message)
|
||||||
|
sys.exit(1)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
gulag.import_quarmails()
|
||||||
|
except GulagException as e:
|
||||||
|
print("Importer-Exception: " + e.message)
|
||||||
|
time.sleep(gulag.config['importer']['interval'])
|
||||||
|
|
||||||
|
cleaner_pid = os.fork()
|
||||||
|
if(cleaner_pid == 0):
|
||||||
|
# Child process: cleaner
|
||||||
|
try:
|
||||||
|
gulag = Gulag(args.config)
|
||||||
|
except GulagException as e:
|
||||||
|
print(e.message)
|
||||||
|
sys.exit(1)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
gulag.cleanup_quarmails()
|
||||||
|
except GulagException as e:
|
||||||
|
print("Cleaner-Exception: " + e.message)
|
||||||
|
time.sleep(gulag.config['cleaner']['interval'])
|
||||||
|
|
||||||
|
# Parent
|
||||||
|
child_pids.append(importer_pid)
|
||||||
|
child_pids.append(cleaner_pid)
|
||||||
|
try:
|
||||||
|
print("Entered helpers main loop...")
|
||||||
|
while True:
|
||||||
|
time.sleep(10)
|
||||||
|
except:
|
||||||
|
print("MAIN-EXCEPTION: " + str(sys.exc_info()))
|
||||||
|
# Destroy childs
|
||||||
|
for child_pid in child_pids:
|
||||||
|
print("Killing child pid: %s", child_pid)
|
||||||
|
os.kill(child_pid, signal.SIGTERM)
|
||||||
|
|
||||||
@ -1,49 +1,15 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse,sys,os,time,signal
|
import argparse,sys
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_restful import Api
|
from flask_restful import Api
|
||||||
from Gulag import Gulag,GulagException
|
from Gulag import Gulag,GulagException
|
||||||
from Resources import ResRoot,ResQuarMails
|
from Resources import ResRoot,ResMailboxes,ResQuarMails,ResAttachments
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--config', required=True, help="Path to config file")
|
parser.add_argument('--config', required=True, help="Path to config file")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
#child_pids = []
|
|
||||||
#importer_pid = os.fork()
|
|
||||||
#if(importer_pid == 0):
|
|
||||||
# # Child process: importer
|
|
||||||
# try:
|
|
||||||
# gulag = Gulag(args.config)
|
|
||||||
# except GulagException as e:
|
|
||||||
# print(e.message)
|
|
||||||
# sys.exit(1)
|
|
||||||
# while True:
|
|
||||||
# try:
|
|
||||||
# gulag.import_quarmails()
|
|
||||||
# except GulagException as e:
|
|
||||||
# print("Importer-Exception: " + e.message)
|
|
||||||
# time.sleep(gulag.config['importer']['interval'])
|
|
||||||
#
|
|
||||||
#cleaner_pid = os.fork()
|
|
||||||
#if(cleaner_pid == 0):
|
|
||||||
# # Child process: cleaner
|
|
||||||
# try:
|
|
||||||
# gulag = Gulag(args.config)
|
|
||||||
# except GulagException as e:
|
|
||||||
# print(e.message)
|
|
||||||
# sys.exit(1)
|
|
||||||
# while True:
|
|
||||||
# try:
|
|
||||||
# gulag.cleanup_quarmails()
|
|
||||||
# except GulagException as e:
|
|
||||||
# print("Cleaner-Exception: " + e.message)
|
|
||||||
# time.sleep(gulag.config['cleaner']['interval'])
|
|
||||||
|
|
||||||
# Parent
|
|
||||||
#child_pids.append(importer_pid)
|
|
||||||
#child_pids.append(cleaner_pid)
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
gulag = Gulag(args.config)
|
gulag = Gulag(args.config)
|
||||||
@ -55,10 +21,18 @@ try:
|
|||||||
'/api/v1/',
|
'/api/v1/',
|
||||||
resource_class_kwargs={'gulag_object': gulag}
|
resource_class_kwargs={'gulag_object': gulag}
|
||||||
)
|
)
|
||||||
|
api.add_resource(ResMailboxes,
|
||||||
|
'/api/v1/mailboxes/',
|
||||||
|
resource_class_kwargs={'gulag_object': gulag}
|
||||||
|
)
|
||||||
api.add_resource(ResQuarMails,
|
api.add_resource(ResQuarMails,
|
||||||
'/api/v1/quarmails/',
|
'/api/v1/quarmails/',
|
||||||
resource_class_kwargs={'gulag_object': gulag}
|
resource_class_kwargs={'gulag_object': gulag}
|
||||||
)
|
)
|
||||||
|
api.add_resource(ResAttachments,
|
||||||
|
'/api/v1/attachments/',
|
||||||
|
resource_class_kwargs={'gulag_object': gulag}
|
||||||
|
)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=False,
|
app.run(debug=False,
|
||||||
# will be overriden by uwsgi.ini
|
# will be overriden by uwsgi.ini
|
||||||
@ -69,9 +43,3 @@ try:
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except:
|
except:
|
||||||
print("MAIN-EXCEPTION: " + str(sys.exc_info()))
|
print("MAIN-EXCEPTION: " + str(sys.exc_info()))
|
||||||
# # Destroy childs
|
|
||||||
# for child_pid in child_pids:
|
|
||||||
# print("Killing child pid: %s", child_pid)
|
|
||||||
# os.kill(child_pid, signal.SIGTERM)
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
38
config/gulag-config.json
Normal file
38
config/gulag-config.json
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"daemon":{
|
||||||
|
"listen_host": "127.0.0.1",
|
||||||
|
"listen_port": 5001
|
||||||
|
},
|
||||||
|
"trusted_proxies": {
|
||||||
|
"rprx01":[
|
||||||
|
"172.16.100.5", "fd00:100::5"
|
||||||
|
],
|
||||||
|
"rprx02":[
|
||||||
|
"172.16.100.6", "fd00:100::6"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"api_keys": {
|
||||||
|
"HIGHLY_SECURE_API_KEY": {
|
||||||
|
"user": "GULAG APP"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uri_prefixes": {
|
||||||
|
"root": "https://<fqdn>/api/v1/",
|
||||||
|
"mailboxes": "https://<fqdn>/api/v1/mailboxes/",
|
||||||
|
"quarmails": "https://<fqdn>/api/v1/quarmails/",
|
||||||
|
"attachments": "https://<fqdn>/api/v1/attachments/"
|
||||||
|
},
|
||||||
|
"db":{
|
||||||
|
"server": "127.0.0.1",
|
||||||
|
"user": "root",
|
||||||
|
"password": "",
|
||||||
|
"name": "Gulag"
|
||||||
|
},
|
||||||
|
"cleaner":{
|
||||||
|
"retention_period": "12 hour",
|
||||||
|
"interval": 10
|
||||||
|
},
|
||||||
|
"importer":{
|
||||||
|
"interval": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
5
config/vassals/gulag_helpers.ini
Normal file
5
config/vassals/gulag_helpers.ini
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[uwsgi]
|
||||||
|
#uid = 65534
|
||||||
|
#gid = 65534
|
||||||
|
processes = 1
|
||||||
|
privileged-binary-patch-arg = /app/gulag_helpers.py --config /config/gulag-config.json
|
||||||
10
config/vassals/gulag_server.ini
Normal file
10
config/vassals/gulag_server.ini
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[uwsgi]
|
||||||
|
processes = 4
|
||||||
|
cheaper = 1
|
||||||
|
cheaper-initial = 1
|
||||||
|
cheaper-step = 1
|
||||||
|
plugin = python3
|
||||||
|
python-path = /app
|
||||||
|
wsgi-file = /app/uwsgi.py
|
||||||
|
pyargv = --config /config/gulag-config.json
|
||||||
|
socket = /socket/uwsgi-gulag_server.sock
|
||||||
@ -9,7 +9,7 @@ RUN set -ex ; \
|
|||||||
&& apt-get -qq --no-install-recommends install \
|
&& apt-get -qq --no-install-recommends install \
|
||||||
uwsgi-plugin-python3 python3-setuptools python3-flask \
|
uwsgi-plugin-python3 python3-setuptools python3-flask \
|
||||||
python3-flask-restful python3-mysql.connector \
|
python3-flask-restful python3-mysql.connector \
|
||||||
uwsgi uwsgi-plugin-python3
|
uwsgi uwsgi-plugin-python3 procps net-tools
|
||||||
|
|
||||||
RUN /bin/mkdir /config /socket /app
|
RUN /bin/mkdir /config /socket /app
|
||||||
COPY app/*.py /app/
|
COPY app/*.py /app/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user