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
# shellcheck source=.venv/bin/activate
. "$ME/.venv/bin/activate"
"$ME/rigel/server.py" "$ME/.env"
"$ME/rigel/server.py" "$ME/.env" $1
deactivate
}

View File

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

View File

@ -12,23 +12,46 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
import os
import sys
import signal
import asyncio
import daemon
import dotenv
import pidfile
from tcp import start, synth
def main():
config = dotenv.dotenv_values(sys.argv[1])
def main(conf):
try:
asyncio.run(start(config, synth(config)))
asyncio.run(start(config, synth(conf)))
except KeyboardInterrupt:
sys.exit()
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)