|
1 | | -__version__ = "3.9.1" |
| 1 | +__version__ = "3.9.2" |
2 | 2 |
|
3 | 3 |
|
4 | 4 | import asyncio |
@@ -109,6 +109,18 @@ def hosting_method(self) -> HostingMethod: |
109 | 109 | if os.environ.get("pm_id"): |
110 | 110 | return HostingMethod.PM2 |
111 | 111 |
|
| 112 | + if os.environ.get("INVOCATION_ID"): |
| 113 | + return HostingMethod.SYSTEMD |
| 114 | + |
| 115 | + if os.environ.get("USING_DOCKER"): |
| 116 | + return HostingMethod.DOCKER |
| 117 | + |
| 118 | + if os.environ.get("INVOCATION_ID"): |
| 119 | + return HostingMethod.SYSTEMD |
| 120 | + |
| 121 | + if os.environ.get("TERM"): |
| 122 | + return HostingMethod.SCREEN |
| 123 | + |
112 | 124 | return HostingMethod.OTHER |
113 | 125 |
|
114 | 126 | def startup(self): |
@@ -242,39 +254,41 @@ def _cancel_tasks(): |
242 | 254 | if not tasks: |
243 | 255 | return |
244 | 256 |
|
245 | | - logger.info('Cleaning up after %d tasks.', len(tasks)) |
| 257 | + logger.info("Cleaning up after %d tasks.", len(tasks)) |
246 | 258 | for task in tasks: |
247 | 259 | task.cancel() |
248 | 260 |
|
249 | 261 | loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True)) |
250 | | - logger.info('All tasks finished cancelling.') |
| 262 | + logger.info("All tasks finished cancelling.") |
251 | 263 |
|
252 | 264 | for task in tasks: |
253 | 265 | if task.cancelled(): |
254 | 266 | continue |
255 | 267 | if task.exception() is not None: |
256 | | - loop.call_exception_handler({ |
257 | | - 'message': 'Unhandled exception during Client.run shutdown.', |
258 | | - 'exception': task.exception(), |
259 | | - 'task': task |
260 | | - }) |
| 268 | + loop.call_exception_handler( |
| 269 | + { |
| 270 | + "message": "Unhandled exception during Client.run shutdown.", |
| 271 | + "exception": task.exception(), |
| 272 | + "task": task, |
| 273 | + } |
| 274 | + ) |
261 | 275 |
|
262 | 276 | future = asyncio.ensure_future(runner(), loop=loop) |
263 | 277 | future.add_done_callback(stop_loop_on_completion) |
264 | 278 | try: |
265 | 279 | loop.run_forever() |
266 | 280 | except KeyboardInterrupt: |
267 | | - logger.info('Received signal to terminate bot and event loop.') |
| 281 | + logger.info("Received signal to terminate bot and event loop.") |
268 | 282 | finally: |
269 | 283 | future.remove_done_callback(stop_loop_on_completion) |
270 | | - logger.info('Cleaning up tasks.') |
| 284 | + logger.info("Cleaning up tasks.") |
271 | 285 |
|
272 | 286 | try: |
273 | 287 | _cancel_tasks() |
274 | 288 | if sys.version_info >= (3, 6): |
275 | 289 | loop.run_until_complete(loop.shutdown_asyncgens()) |
276 | 290 | finally: |
277 | | - logger.info('Closing the event loop.') |
| 291 | + logger.info("Closing the event loop.") |
278 | 292 | loop.close() |
279 | 293 |
|
280 | 294 | if not future.cancelled(): |
@@ -1635,7 +1649,7 @@ async def autoupdate(self): |
1635 | 1649 | elif res != "Already up to date.": |
1636 | 1650 | logger.info("Bot has been updated.") |
1637 | 1651 | channel = self.update_channel |
1638 | | - if self.hosting_method == HostingMethod.PM2: |
| 1652 | + if self.hosting_method in (HostingMethod.PM2, HostingMethod.SYSTEMD): |
1639 | 1653 | embed = discord.Embed(title="Bot has been updated", color=self.main_color) |
1640 | 1654 | embed.set_footer( |
1641 | 1655 | text=f"Updating Modmail v{self.version} " f"-> v{latest.version}" |
@@ -1663,6 +1677,10 @@ async def before_autoupdate(self): |
1663 | 1677 | logger.warning("Autoupdates disabled.") |
1664 | 1678 | self.autoupdate_loop.cancel() |
1665 | 1679 |
|
| 1680 | + if self.hosting_method == HostingMethod.DOCKER: |
| 1681 | + logger.warning("Autoupdates disabled as using Docker.") |
| 1682 | + self.autoupdate_loop.cancel() |
| 1683 | + |
1666 | 1684 | if not self.config.get("github_token") and self.hosting_method == HostingMethod.HEROKU: |
1667 | 1685 | logger.warning("GitHub access token not found.") |
1668 | 1686 | logger.warning("Autoupdates disabled.") |
|
0 commit comments