mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
[Audio] V3/auto autostart only (#1420)
* Download jar at audio load * Messy... * Remove leftover log file stuff * Keep application.yml * Damn you windows
This commit is contained in:
41
redbot/cogs/audio/manager.py
Normal file
41
redbot/cogs/audio/manager.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user