mirror of
https://github.com/Specoolazius/mcserver-discordbot.git
synced 2025-01-19 00:16:12 +01:00
Compare commits
10 Commits
0a26310a2f
...
9ac6d5ecb1
Author | SHA1 | Date | |
---|---|---|---|
9ac6d5ecb1 | |||
88c4bd1992 | |||
e506424df3 | |||
b9f7320da8 | |||
5824486f6e | |||
ef46afd052 | |||
e4c3ccbf97 | |||
a01a46e20d | |||
33301ccfb2 | |||
013edeaa66 |
@ -22,7 +22,7 @@
|
||||
# the better option is to wait up to an hour (discords regulation) and let the bot
|
||||
# create the slash commands globally
|
||||
# enter multiple guild ids by separating them with space
|
||||
debug_guilds = 848137923101982741 958692739065720832 418447236008116228
|
||||
; debug_guilds =
|
||||
|
||||
[systemd]
|
||||
; service_name = mc-status-bot
|
@ -39,5 +39,8 @@ class Admin(discord.Cog):
|
||||
@__dev_group.command(name='restart')
|
||||
async def __restart_service(self, ctx: discord.ApplicationContext) -> None:
|
||||
await ctx.respond('attempting restart...')
|
||||
await asyncio.create_subprocess_shell(f'sudo systemctl restart')
|
||||
self.bot.logger.info('Restarting bot...')
|
||||
|
||||
process = await asyncio.create_subprocess_shell(cmd=f'sudo systemctl restart {self.bot.config.service_name}')
|
||||
# await process.communicate()
|
||||
|
||||
|
@ -21,4 +21,9 @@ class StartStop(discord.Cog):
|
||||
|
||||
@slash_command(name='start')
|
||||
async def __execute_start(self, ctx: discord.ApplicationContext) -> None:
|
||||
pass
|
||||
returncode = None
|
||||
|
||||
@slash_command(name='stop')
|
||||
async def __execute_stop(self, ctx: discord.ApplicationContext) -> None:
|
||||
returncode = None
|
||||
# hi
|
||||
|
@ -156,25 +156,27 @@ class Client(discord.Bot, ABC):
|
||||
await process_chmod.communicate()
|
||||
return process_chmod.returncode
|
||||
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
program=os.path.join(os.getcwd(), SHELL_SCRIPT_PATH, file_name),
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
if not retry:
|
||||
await __grant_permission()
|
||||
|
||||
stdout, stderr = await process.communicate()
|
||||
self.logger.info(f'Executed script {file_name} with exit code {process.returncode}')
|
||||
try:
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
program=os.path.join(os.getcwd(), SHELL_SCRIPT_PATH, file_name),
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
|
||||
if process.returncode == 0:
|
||||
self.logger.info(f'stdout:\n{stdout.decode()}')
|
||||
stdout, stderr = await process.communicate()
|
||||
self.logger.info(f'Executed script {file_name} with exit code {process.returncode}')
|
||||
|
||||
# bash returncode 126: permission error
|
||||
elif process.returncode == 126 and retry:
|
||||
if process.returncode == 0:
|
||||
self.logger.info(f'stdout:\n{stdout.decode()}')
|
||||
else:
|
||||
self.logger.error(f'stderr:\n{stderr.decode()}')
|
||||
|
||||
return process.returncode
|
||||
|
||||
except PermissionError:
|
||||
# retrying once
|
||||
self.logger.warning(f'Missing permissions for {file_name}')
|
||||
return await self.execute_shell(file_name, retry=False)
|
||||
|
||||
else:
|
||||
self.logger.error(f'stderr:\n{stderr.decode()}')
|
||||
|
||||
return process.returncode
|
||||
|
@ -5,4 +5,4 @@
|
||||
# 2022, created by Specoolazius
|
||||
|
||||
cd ~/mcserver-discordbot/bot || exit;
|
||||
sudo python3.10 -O run.py
|
||||
python3 -O run.py
|
||||
|
@ -6,7 +6,7 @@ Requires=network.target
|
||||
|
||||
[Service]
|
||||
Type=idle
|
||||
ExecStart=~/mcserver-discordbot/bot/run.sh
|
||||
ExecStart=/root/mcserver-discordbot/bot/run.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
Loading…
Reference in New Issue
Block a user