Daemonize rigel

This commit is contained in:
Sameer Rahmani 2022-04-19 14:52:32 +01:00
parent e763f730d2
commit 9371de61e3
3 changed files with 32 additions and 7 deletions

View File

@ -124,7 +124,7 @@ function run() { ## Setup the working directory and make it ready for developmen
function rigel() { ## Run the rigel server function rigel() { ## Run the rigel server
# shellcheck source=.venv/bin/activate # shellcheck source=.venv/bin/activate
. "$ME/.venv/bin/activate" . "$ME/.venv/bin/activate"
"$ME/rigel/server.py" "$ME/.env" "$ME/rigel/server.py" "$ME/.env" $1
deactivate deactivate
} }

View File

@ -1,3 +1,5 @@
tts==0.6 tts==0.6
python-dotenv python-dotenv
simpleaudio simpleaudio
python-daemon==2.3
python-pidfile==3.0

View File

@ -12,23 +12,46 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
import os
import sys import sys
import signal
import asyncio import asyncio
import daemon
import dotenv import dotenv
import pidfile
from tcp import start, synth from tcp import start, synth
def main(): def main(conf):
config = dotenv.dotenv_values(sys.argv[1])
try: try:
asyncio.run(start(config, synth(config))) asyncio.run(start(config, synth(conf)))
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit() sys.exit()
if __name__ == "__main__": if __name__ == "__main__":
main() config = dotenv.dotenv_values(sys.argv[1])
action = sys.argv[2]
pfile = config.get("PID_FILE", "/var/run/rigel.pid")
pidlock = pidfile.PIDFile(pfile)
if action == "status":
print("Running" if pidlock.is_running else "Not running.")
elif action == "stop":
if pidlock.is_running:
print("Terminating...")
f = open(pfile, "r")
pid = int(f.read())
os.kill(pid, signal.SIGTERM)
else:
print("Not running.")
elif action == "start":
with daemon.DaemonContext(stdout=sys.stdout,
stderr=sys.stderr,
pidfile=pidlock):
main(config)