mirror of
https://github.com/Specoolazius/mcserver-discordbot.git
synced 2025-01-18 23:56:13 +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
|
# 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 = 848137923101982741 958692739065720832 418447236008116228
|
; debug_guilds =
|
||||||
|
|
||||||
[systemd]
|
[systemd]
|
||||||
; service_name = mc-status-bot
|
; service_name = mc-status-bot
|
@ -39,5 +39,8 @@ 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...')
|
||||||
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')
|
@slash_command(name='start')
|
||||||
async def __execute_start(self, ctx: discord.ApplicationContext) -> None:
|
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()
|
await process_chmod.communicate()
|
||||||
return process_chmod.returncode
|
return process_chmod.returncode
|
||||||
|
|
||||||
process = await asyncio.create_subprocess_exec(
|
if not retry:
|
||||||
program=os.path.join(os.getcwd(), SHELL_SCRIPT_PATH, file_name),
|
await __grant_permission()
|
||||||
stdout=asyncio.subprocess.PIPE,
|
|
||||||
stderr=asyncio.subprocess.PIPE,
|
|
||||||
)
|
|
||||||
|
|
||||||
stdout, stderr = await process.communicate()
|
try:
|
||||||
self.logger.info(f'Executed script {file_name} with exit code {process.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 process.returncode == 0:
|
stdout, stderr = await process.communicate()
|
||||||
self.logger.info(f'stdout:\n{stdout.decode()}')
|
self.logger.info(f'Executed script {file_name} with exit code {process.returncode}')
|
||||||
|
|
||||||
# bash returncode 126: permission error
|
if process.returncode == 0:
|
||||||
elif process.returncode == 126 and retry:
|
self.logger.info(f'stdout:\n{stdout.decode()}')
|
||||||
|
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
|
|
||||||
|
@ -5,4 +5,4 @@
|
|||||||
# 2022, created by Specoolazius
|
# 2022, created by Specoolazius
|
||||||
|
|
||||||
cd ~/mcserver-discordbot/bot || exit;
|
cd ~/mcserver-discordbot/bot || exit;
|
||||||
sudo python3.10 -O run.py
|
python3 -O run.py
|
||||||
|
@ -6,7 +6,7 @@ Requires=network.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=idle
|
Type=idle
|
||||||
ExecStart=~/mcserver-discordbot/bot/run.sh
|
ExecStart=/root/mcserver-discordbot/bot/run.sh
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
Loading…
Reference in New Issue
Block a user