Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor Startup #88

Merged
merged 13 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions genisys/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import grp
import os
import sys
import subprocess
from warnings import warn
from signal import signal, SIGTERM
from typing_extensions import Dict, TypedDict, cast
from genisys.config_parser import YAMLParser
from genisys.server.genisysinventory import GenisysInventory
from genisys.server.http import GenisysHTTPServer, GenisysHTTPRequestHandler
import genisys.server.tls
import pkg_resources
import tarfile

DEFAULT_PORT = 15206
DEFAULT_INVENTORY = "/etc/ansible/hosts"
Expand All @@ -29,6 +32,9 @@ def run(config: YAMLParser):
network = config.get_section("Network")
server_options = cast(ServerOptions, network.get("server", {}) or {})

# Launch meteor server
meteor_initialization(server_options)

# drop priviledges
try:
server_user = drop_priviledges(server_options)
Expand Down Expand Up @@ -66,6 +72,10 @@ def sigterm_handler(*_):
signal(SIGTERM, sigterm_handler)
httpd.serve_forever()

# end sigterm_handler

# end run

def drop_priviledges(config: ServerOptions) -> pwd.struct_passwd:
"""Attempts to drop the priviledges to that of the specified users, returns false on failure"""
if 'user' not in config:
Expand All @@ -79,3 +89,43 @@ def drop_priviledges(config: ServerOptions) -> pwd.struct_passwd:
os.setuid(uid.pw_uid)
os.setgid(gid.gr_gid)
return uid

# end drop_privledges

def meteor_initialization(server_config: ServerOptions):
'''Runs Meteor as a subprocess of Genisys and
initializes necessary environment variables for
Meteor. This process assumes that the user already
has MongoDB installed and running.'''

# Set environment variables
os.environ['ROOT_URL'] = 'http://localhost'
os.environ['PORT'] = '8080'
if 'MONGO_URL' not in os.environ:
print('MONGO_URL not found in environment variables, cancelling Meteor server.')
return
print('MONGO_URL found.')

if 'CONFIG_FILE' not in os.environ:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where will CONFIG_FILE get set at? Is it expected that the user will set it before they run genisys server? That could be redundant if the user has to do CONFIG_FILE=/path/to/genisys.yaml genisys server -f /path/to/genisys.yaml

print('CONFIG_FILE not found in environment variables, defaulting to /etc/genisys.yaml.')
else:
print('CONFIG_FILE env var found.')

# Make Meteor directory
meteor_dir = os.path.join(server_config.get('working-directory'), 'meteor')
os.makedirs(meteor_dir, exist_ok=True)

# Get path to tar file
tar_file_path = pkg_resources.resource_filename('genisys', 'server/external/meteor-dev.tar.gz')

# Extract tarball Meteor build
file = tarfile.open(tar_file_path)
file.extractall(meteor_dir, filter='fully_trusted')
file.close()

# npm install and run
subprocess.run(['npm', 'install', '--prefix', os.path.join(meteor_dir,'bundle', 'programs', 'server'), '--unsafe-perm'], check=True)
subprocess.run(['node', os.path.join(meteor_dir,'bundle', 'main.js')], check=True)


# end meteor_initialization
Binary file added genisys/server/external/meteor-dev.tar.gz
Binary file not shown.
74 changes: 0 additions & 74 deletions genisys/server/external/server/main.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions meteor-dev/server/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { ClientsCollection } from '../api/clients/clients';
import '../api/clients/server/publications';
import '../api/clients/server/methods';

const yaml = require('js-yaml')
const fs = require('fs')

const CONFIG_FILE_VAR = process.env.CONFIG_FILE || '/etc/genisys.yaml'
export const CONFIG_FILE = yaml.load(fs.readFileSync(String(CONFIG_FILE_VAR), 'utf8'))

Meteor.startup(() => {
console.log("Meteor Started")
});
File renamed without changes.
Loading