Compare commits

..

No commits in common. "9ac6d5ecb143f30c3c7b680355aefda59e4d12e0" and "0a26310a2fd2b962577f93df5b409932a3f9eb9b" have entirely different histories.

6 changed files with 21 additions and 31 deletions

View File

@ -22,7 +22,7 @@
# the better option is to wait up to an hour (discords regulation) and let the bot # the better option is to wait up to an hour (discords regulation) and let the bot
# create the slash commands globally # create the slash commands globally
# enter multiple guild ids by separating them with space # enter multiple guild ids by separating them with space
; debug_guilds = debug_guilds = 848137923101982741 958692739065720832 418447236008116228
[systemd] [systemd]
; service_name = mc-status-bot ; service_name = mc-status-bot

View File

@ -39,8 +39,5 @@ class Admin(discord.Cog):
@__dev_group.command(name='restart') @__dev_group.command(name='restart')
async def __restart_service(self, ctx: discord.ApplicationContext) -> None: async def __restart_service(self, ctx: discord.ApplicationContext) -> None:
await ctx.respond('attempting restart...') await ctx.respond('attempting restart...')
self.bot.logger.info('Restarting bot...') await asyncio.create_subprocess_shell(f'sudo systemctl restart')
process = await asyncio.create_subprocess_shell(cmd=f'sudo systemctl restart {self.bot.config.service_name}')
# await process.communicate()

View File

@ -21,9 +21,4 @@ class StartStop(discord.Cog):
@slash_command(name='start') @slash_command(name='start')
async def __execute_start(self, ctx: discord.ApplicationContext) -> None: async def __execute_start(self, ctx: discord.ApplicationContext) -> None:
returncode = None pass
@slash_command(name='stop')
async def __execute_stop(self, ctx: discord.ApplicationContext) -> None:
returncode = None
# hi

View File

@ -156,27 +156,25 @@ class Client(discord.Bot, ABC):
await process_chmod.communicate() await process_chmod.communicate()
return process_chmod.returncode return process_chmod.returncode
if not retry: process = await asyncio.create_subprocess_exec(
await __grant_permission() program=os.path.join(os.getcwd(), SHELL_SCRIPT_PATH, file_name),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
try: stdout, stderr = await process.communicate()
process = await asyncio.create_subprocess_exec( self.logger.info(f'Executed script {file_name} with exit code {process.returncode}')
program=os.path.join(os.getcwd(), SHELL_SCRIPT_PATH, file_name),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await process.communicate() if process.returncode == 0:
self.logger.info(f'Executed script {file_name} with exit code {process.returncode}') self.logger.info(f'stdout:\n{stdout.decode()}')
if process.returncode == 0: # bash returncode 126: permission error
self.logger.info(f'stdout:\n{stdout.decode()}') elif process.returncode == 126 and retry:
else:
self.logger.error(f'stderr:\n{stderr.decode()}')
return process.returncode
except PermissionError:
# retrying once # retrying once
self.logger.warning(f'Missing permissions for {file_name}') self.logger.warning(f'Missing permissions for {file_name}')
return await self.execute_shell(file_name, retry=False) return await self.execute_shell(file_name, retry=False)
else:
self.logger.error(f'stderr:\n{stderr.decode()}')
return process.returncode

View File

@ -5,4 +5,4 @@
# 2022, created by Specoolazius # 2022, created by Specoolazius
cd ~/mcserver-discordbot/bot || exit; cd ~/mcserver-discordbot/bot || exit;
python3 -O run.py sudo python3.10 -O run.py

View File

@ -6,7 +6,7 @@ Requires=network.target
[Service] [Service]
Type=idle Type=idle
ExecStart=/root/mcserver-discordbot/bot/run.sh ExecStart=~/mcserver-discordbot/bot/run.sh
[Install] [Install]
WantedBy=default.target WantedBy=default.target