Skip to content

Commit

Permalink
fix(__init__.py): subprocess.Popen()
Browse files Browse the repository at this point in the history
Defined venv/bin/python3 absolute path for Worker Manager Server.
  • Loading branch information
mibs510 committed Jul 9, 2023
1 parent 50c1ae9 commit 11c4277
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 43 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ It was designed with an emphasis on security to meet organization/business needs
- 👉 IPBan (fail2ban for Flask) with [IPAbuseDB.com](https://ipabusedb.com) integration
- 👉 Webhook endpoint security

# ❗ This project is still in pre-release.

# 🐛 Known Bugs
- ~~Worker management needs reimplementation~~
- ~~Currently working on this~~
- Manually requeuing jobs fail
- Update vulnerable packages (Flask, requests, Werkzeug)
- Gunicorn with more than one worker has issues with Worker Manager Server
- ~~Searching plates will only work if pagination position is on page 1~~
- ~~This is a grid.js issue [#1314](https://github.com/grid-js/gridjs/issues/1314) [#1344](https://github.com/grid-js/gridjs/pull/1334) [#1311](https://github.com/grid-js/gridjs/issues/1311).~~

Expand Down Expand Up @@ -123,6 +122,8 @@ cd OpenALPR-Webhook
# Backup databases
mkdir apps/db.backup
cp apps/db/* apps/db.backup
# To overwrite any changes to project files (excluding databases, logs, secrets, etc)
git reset --hard
# Get latest version of OpenALPR-Webhook
git pull
# Apply changes to the databases
Expand Down
4 changes: 2 additions & 2 deletions apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import log
import version
from apps.alpr.ipban_config import IPBanConfig
from worker_manager import WorkerManager
from worker_manager import WorkerManager, python3
from worker_manager_enums import WorkerType, WMSCommand

setproctitle.setproctitle("OpenALPR-Webhook")
Expand Down Expand Up @@ -96,7 +96,7 @@ def start_redis_workers():
worker_manager_server = WorkerManager(WMSCommand.ACK)
worker_manager_server.debug = True
try:
subprocess.Popen(['python3', os.path.abspath(os.path.dirname(__file__) + "/..") +
subprocess.Popen([python3, os.path.abspath(os.path.dirname(__file__) + "/..") +
'/worker_manager_server.py'])
time.sleep(3)
worker_manager_server.send()
Expand Down
71 changes: 41 additions & 30 deletions apps/templates/settings/maintenance-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,10 @@ <h5 class="mx-auto w-100">
<div class="card-body">
<div class="row">
<div class="col-sm-12">
<p>The Worker Manager Server is responsible for spawning and terminating Redis workers as needed. One worker is spawned for every agent and camera that is enabled. This allows OpenALPR-Webhook to scale as needed without interruptions. <br>Because Redis forks workers on the process level, the Worker Manager Server only runs on *nix systems.</p>
<br>
<p>Restart: Restart the server when experiencing issues with worker allocation. This will not restart the webserver.</p>
<br>
<p>Shutdown: Shutting down the server is essential when performing a soft restart on the webserver. This makes sure that no worker turns to a zombie.</p>
<br>
<p>These actions are not needed when performing a system reboot.</p>
<div class="d-flex justify-content-lg-between mt-4">
<button type="button" class="btn btn btn-info" onclick="smtpTest()" disabled>Restart</button>
<button type="button" class="btn btn-danger" onclick="stopWMS()">Shutdown</button>
</div>
</div>
Expand All @@ -92,34 +87,50 @@ <h5 class="mx-auto w-100">
<script>
// Reset report settings
function stopWMS() {
$.ajax({
type: 'POST',
url: "{{ url_for('maintenance.shutdown_wms') }}",
async: true,
cache: false,
contentType: false,
processData: false,
beforeSend: function(){
Swal.fire({
text: 'Shutting down Worker Manager Server...',
allowOutsideClick: false,
didOpen: () => {
Swal.showLoading()
Swal.fire({
title: "Are you sure?",
text: "Shutting down the Worker Manager Server will require a server restart",
showCancelButton: true,
icon: "warning",
cancelButtonText: "Cancel",
confirmButtonText: "Yes, shut it down!",
buttonsStyling: false, customClass: {cancelButton:'mb-2 me-2 btn btn-primary', confirmButton: 'mb-2 me-2 btn btn-danger'}
}).then((isConfirm) => {
if (isConfirm.isConfirmed) {
$.ajax({
type: 'POST',
url: "{{ url_for('maintenance.shutdown_wms') }}",
async: true,
cache: false,
contentType: false,
processData: false,
beforeSend: function (){
Swal.fire({
text: 'Shutting down Worker Manager Server...',
didOpen: () => {
Swal.showLoading()
},
})
},
error : function(request,error) {
Swal.fire( {icon: 'error', buttonsStyling: false, customClass: {confirmButton: 'btn btn-primary'},
text: JSON.parse(request.responseText)['error']}).then(() => {
location.reload();
});
},
success : function(res) {
Swal.fire( {icon: 'success', buttonsStyling: false, customClass: {confirmButton: 'btn btn-primary'},
text: res['message']}).then(() => {
location.reload();
});
},
complete: function(){
Swal.hideLoading()
}
})
},
error: function(request,error) {
Swal.fire( {icon: 'error', buttonsStyling: false, customClass: {confirmButton: 'btn btn-primary'},
text: JSON.parse(request.responseText)['error']})
},
success: function(res) {
Swal.fire( {icon: 'success', buttonsStyling: false, customClass: {confirmButton: 'btn btn-primary'},
text: res['message']})
},
complete: function(){
Swal.hideLoading()
}
})
return false;
});
}
// Tooltips
$(document).ready(function(){
Expand Down
6 changes: 3 additions & 3 deletions apps/templates/settings/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h5 class="alert-heading"><i class="feather icon-alert-circle me-2"></i>Email Ve
</div>
<div class="col-sm-6">
<label class="form-label">Organization</label>
<input type="text" id="bio" name="bio" class="form-control" placeholder="Bio" value="{{ context['profile_bio']}}">
<input type="text" id="bio" name="bio" class="form-control" placeholder="Company Co." value="{{ context['profile_bio']}}">
</div>
</div>
<div class="row mt-3">
Expand All @@ -82,14 +82,14 @@ <h5 class="alert-heading"><i class="feather icon-alert-circle me-2"></i>Email Ve
<div class="col-sm-6">
<label class="form-label">Phone
<span class="sidebar-icon">
<a data-toggle="tooltip" title="Add your country calling code. e.g. +XYYYYYYYYYY">
<a data-toggle="tooltip" title="Add your country calling code. e.g. +WXXXYYYZZZZ">
<svg class="icon icon-xxs text-gray-400 me-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path clip-rule="evenodd" fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"></path>
</svg>
</a>
</span>
</label>
<input type="text" id="phone" name="phone" class="form-control" placeholder="Mobile Cellular" value="{{ context['profile_phone']}}">
<input type="text" id="phone" name="phone" class="form-control" placeholder="+WXXXYYYZZZZ" value="{{ context['profile_phone']}}">
</div>
</div>
<div class="row mt-3">
Expand Down
39 changes: 33 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
name='OpenALPR-Webhook',
version=__version__,
platforms='linux',
packages=['apps', 'nginx'],
packages=['apps', 'apps/alpr', 'apps/alpr/ipban', 'apps/alpr/models', 'apps/alpr/routes', 'apps/alpr/routes/alert',
'apps/alpr/routes/alerts', 'apps/alpr/routes/alerts/custom', 'apps/alpr/routes/alerts/rekor',
'apps/alpr/routes/capture', 'apps/alpr/routes/search', 'apps/alpr/routes/settings',
'apps/alpr/routes/settings/agents', 'apps/alpr/routes/settings/cameras',
'apps/alpr/routes/settings/cameras/manufacturers', 'apps/alpr/routes/settings/general',
'apps/alpr/routes/settings/maintenance', 'apps/alpr/routes/settings/maintenance/rq_dashboard',
'apps/alpr/routes/settings/notifications', 'apps/alpr/routes/settings/profile',
'apps/alpr/routes/settings/users', 'apps/alpr/routes/settings/vehicle', 'apps/api', 'apps/authentication',
'apps/db', 'apps/downloads', 'apps/exceptions', 'apps/home', 'apps/static', 'apps/templates',
'apps/uploads', 'nginx'],
include_package_data=True,
url='https://github.com/mibs510/OpenALPR-Webhook',
license='MIT',
Expand All @@ -21,11 +30,29 @@
'data retention. It was designed with an emphasis on security to meet organization/business needs.',
long_description=long_description,
python_requires=">=3.10",
install_requires=['certifi~=2021.10.8', 'charset-normalizer~=2.0.9', 'elevate~=0.1.3', 'idna~=3.3',
'keyboard~=0.13.5', 'numpy~=1.21.4', 'parse~=1.19.0', 'pexpect==4.8.0', 'psutil~=5.8.0',
'pycairo~=1.20.1', 'pydbus~=0.6.0', 'PyGObject~=3.42.0', 'pyserial~=3.5',
'python-json-logger~=2.0.2', 'requests~=2.26.0', 'sentry-sdk~=1.5.0', 'urllib3~=1.26.7',
'xxhash~=2.0.2', 'Yapsy~=1.12.2'],
install_requires=['aiohttp==3.8.4', 'aiohttp-retry==2.8.3', 'aiosignal==1.3.1', 'alembic==1.10.4',
'aniso8601==9.0.1', 'argcomplete==3.0.8', 'arrow==1.2.3', 'astral==2.2', 'async-timeout==4.0.2',
'asyncio==3.4.3', 'attrs==23.1.0', 'blinker==1.4', 'certifi==2022.12.7', 'cfgv==3.3.1',
'charset-normalizer==3.1.0', 'click==7.1.2', 'colorama==0.4.4', 'Cython==0.29.34',
'decli==0.6.1', 'distlib==0.3.6', 'dnspython==2.3.0', 'email-validator==2.0.0.post2',
'filelock==3.12.0', 'Flask==1.1.4', 'flask-ipban==1.1.5', 'Flask-Login==0.6.2',
'Flask-Mail==0.9.1', 'Flask-Migrate==2.6.0', 'Flask-Minify==0.41', 'flask-paginate==2022.1.8',
'flask-restx==0.5.1', 'Flask-Script==2.0.6', 'Flask-SQLAlchemy==2.5.1', 'Flask-WTF==1.0.0',
'frozenlist==1.3.3', 'greenlet==2.0.2', 'gunicorn==20.1.0', 'htmlmin==0.1.12', 'identify==2.5.24',
'idna==3.4', 'importlib-metadata==6.6.0', 'ipc-sun-sync==0.2.3', 'itsdangerous==1.1.0',
'Jinja2==2.11.3', 'jsmin==3.0.1', 'jsonschema==4.17.3', 'lesscpy==0.15.1', 'Mako==1.2.4',
'MarkupSafe==2.0.1', 'marshmallow==3.14.1', 'marshmallow-sqlalchemy==0.22.3', 'multidict==6.0.4',
'nodeenv==1.8.0', 'oauthlib==3.2.2', 'packaging==23.1', 'phonenumbers==8.13.11',
'platformdirs==3.5.1', 'ply==3.11', 'progressbar2==4.2.0', 'prompt-toolkit==3.0.38',
'psutil==5.9.5', 'pycountry==22.3.5', 'PyJWT==2.6.0', 'pyrsistent==0.19.3',
'python-dateutil==2.8.2', 'python-utils==3.7.0', 'pytimeparse==1.1.8', 'pytz==2022.1',
'PyYAML==6.0', 'questionary==1.10.0', 'random-password-generator==2.2.0', 'rcssmin==1.1.1',
'redis==4.4.4', 'Redis-Sentinel-Url==1.0.1', 'requests==2.28.2', 'requests-oauthlib==1.3.1',
'rq==1.12.0', 'setproctitle==1.3.2', 'six==1.16.0', 'SQLAlchemy==1.4.29',
'sqlalchemy-json==0.5.0', 'termcolor==2.3.0', 'tomlkit==0.11.8', 'twilio==8.0.0',
'typing_extensions==4.5.0', 'unqlite==0.9.3', 'urllib3==1.26.15', 'URLObject==2.4.3',
'virtualenv==20.23.0', 'wcwidth==0.2.6', 'Werkzeug==1.0.1', 'WTForms==3.0.0', 'xxhash==3.2.0',
'yarl==1.9.2', 'zipp==3.15.0'],
classifiers=['Development Status :: 4 - Beta',
'Framework :: Flask',
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
Expand Down
4 changes: 4 additions & 0 deletions worker_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import logging
import os
import socket

from worker_manager_enums import WMSCommand, WMSResponse

# Used to launch Worker Manager Server
python3 = os.path.abspath(os.path.dirname(__file__)) + "/venv/bin/python3"


class WorkerManager:
debug = False
Expand Down

0 comments on commit 11c4277

Please sign in to comment.