Will ccb322d08e [Audio] V3/auto autostart only (#1420)
* Download jar at audio load

* Messy...

* Remove leftover log file stuff

* Keep application.yml

* Damn you windows
2018-03-12 00:49:08 +01:00

42 lines
1010 B
Python

import shlex
import asyncio
from subprocess import Popen, DEVNULL
import os
proc = None
SHUTDOWN = asyncio.Event()
async def monitor_lavalink_server(loop):
while not SHUTDOWN.is_set():
if proc.poll() is not None:
break
await asyncio.sleep(0.5)
if not SHUTDOWN.is_set():
print("Lavalink jar shutdown, restarting.")
await start_lavalink_server(loop)
async def start_lavalink_server(loop):
from . import LAVALINK_DOWNLOAD_DIR, LAVALINK_JAR_FILE
start_cmd = "java -jar {}".format(LAVALINK_JAR_FILE.resolve())
global proc
proc = Popen(
shlex.split(start_cmd, posix=os.name == 'posix'),
cwd=str(LAVALINK_DOWNLOAD_DIR),
stdout=DEVNULL, stderr=DEVNULL
)
print("Lavalink jar started. PID: {}".format(proc.pid))
loop.create_task(monitor_lavalink_server(loop))
def shutdown_lavalink_server():
print("Shutting down lavalink server.")
SHUTDOWN.set()
if proc is not None:
proc.terminate()