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
|
||||
# shellcheck source=.venv/bin/activate
|
||||
. "$ME/.venv/bin/activate"
|
||||
"$ME/rigel/server.py" "$ME/.env"
|
||||
"$ME/rigel/server.py" "$ME/.env" $1
|
||||
deactivate
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
tts==0.6
|
||||
python-dotenv
|
||||
simpleaudio
|
||||
python-daemon==2.3
|
||||
python-pidfile==3.0
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue