I use python 2.7 and Django 1.11.5.
I want to check that my process manage.py, running in screen. If check is false I want to start process manage.py.
I use three files: check.py, start_screen.sh, start_server.sh.
I check the process in the first file(check.py):
import subprocess
from settings import BASE_DIR, SERVER
process_list = subprocess.check_output(['/bin/ps', 'ax'])
my_server = re.search('SCREEN .* server', process_list)
if my_server is None:
s = subprocess.check_output(['/bin/bash', BASE_DIR + '/start_screen.sh'])
I start the screen in the second file(start_screen.sh) :
#!/usr/bin/env bash
screen -dmS server /bin/bash /home/user/Desktop/python_server/start_server.sh
I start the server in the third file(start_server.sh):
#!/bin/bash
cd /home/user/Desktop/python_server/
/usr/bin/python manage.py server 0.0.0.0:8000
I want to reduce the number of files to one python file.
Also I want to pass parameters like SERVER.PORT, SERVER.ADDRESS and BASE_DIR to the request.
Can anybody help with this?
pythonic.if ! pgrep -f "screen.*start_server.sh"; then screen -dmS server /bin/bash /home/user/Desktop/python_shome/user/Desktop/python_server/start_server.sh; fi? This way you don't have to invoke python script.SERVER.PORT,SERVER.ADDRESSandBASE_DIR. I can get it only from my python script, so the best way is to call it from python as far as I see. In addition, I need to run multiple server instances and I need to change this variables in this script. But I am open to the opinions of others.