Daemonize rigel
This commit is contained in:
parent
e763f730d2
commit
9371de61e3
2
builder
2
builder
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
tts==0.6
|
tts==0.6
|
||||||
python-dotenv
|
python-dotenv
|
||||||
simpleaudio
|
simpleaudio
|
||||||
|
python-daemon==2.3
|
||||||
|
python-pidfile==3.0
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue