{"id":16161429,"url":"https://github.com/gamemann/pterodactyl-game-server-watch","last_synced_at":"2025-07-31T13:34:41.676Z","repository":{"id":48646205,"uuid":"261254683","full_name":"gamemann/Pterodactyl-Game-Server-Watch","owner":"gamemann","description":"A tool programmed in Go to automatically restart 'hung' game servers/containers via a Pterodactyl API.","archived":false,"fork":false,"pushed_at":"2024-06-20T10:10:23.000Z","size":92,"stargazers_count":34,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T12:30:11.360Z","etag":null,"topics":["api","go","golang","hung","pterodactyl","restart","servers"],"latest_commit_sha":null,"homepage":"https://moddingcommunity.com/forums/topic/28-pterodactyl-game-server-watch-restart-hung-servers-automatically","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gamemann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-04T17:43:14.000Z","updated_at":"2025-02-16T12:55:31.000Z","dependencies_parsed_at":"2024-06-19T04:09:39.842Z","dependency_job_id":"a4371409-fb4b-4591-ba21-cbd10ec36cd9","html_url":"https://github.com/gamemann/Pterodactyl-Game-Server-Watch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FPterodactyl-Game-Server-Watch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FPterodactyl-Game-Server-Watch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FPterodactyl-Game-Server-Watch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FPterodactyl-Game-Server-Watch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gamemann","download_url":"https://codeload.github.com/gamemann/Pterodactyl-Game-Server-Watch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243950813,"owners_count":20373664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","go","golang","hung","pterodactyl","restart","servers"],"created_at":"2024-10-10T02:25:14.578Z","updated_at":"2025-03-18T22:30:44.867Z","avatar_url":"https://github.com/gamemann.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pterodactyl Game Server Watch\n\n## Description\nA tool programmed in Go to automatically restart 'hung' (game) servers via the Pterodactyl API (working since version 1.4.2). This only supports servers that respond to the [A2S_INFO](https://developer.valvesoftware.com/wiki/Server_queries#A2S_INFO) query (a Valve Master Server query). I am currently looking for a better way to detect if a server is hung, though.\n\n## Command Line Flags\nThere is only one command line argument/flag and it is `-cfg=\u003cpath\u003e`. This argument/flag changes the path to the Pterowatch config file. The default value is `/etc/pterowatch/pterowatch.conf`.\n\nExamples include:\n\n```\n./pterowatch -cfg=/home/cdeacon/myconf.conf\n./pterowatch -cfg=~/myconf.conf\n./pterowatch -cfg=myconf.conf\n```\n\n## Config File\nThe config file's default path is `/etc/pterowatch/pterowatch.conf` (this can be changed with a command line argument/flag as seen above). This should be a JSON array including the API URL, token, and an array of servers to check against. The main options are the following:\n\n* `apiurl` =\u003e The Pterodactyl API URL (do not include the `/` at the end).\n* `token` =\u003e The bearer token (from the client) to use when sending requests to the Pterodactyl API.\n* `apptoken` =\u003e The bearer token (from the application) to use when sending requests to the Pterodactyl API (this is only needed when `addservers` is set to `true`).\n* `debug` =\u003e The debug level (1-4).\n* `reloadtime` =\u003e If above 0, will reload the configuration file and retrieve servers from the API every *x* seconds.\n* `addservers` =\u003e Whether or not to automatically add servers to the config from the Pterodactyl API.\n* `defenable` =\u003e The default enable boolean of a server added via the Pterodactyl API.\n* `defscantime` =\u003e The default scan time of a server added via the Pterodactyl API.\n* `defmaxfails` =\u003e The default max fails of a server added via the Pterodactyl API.\n* `defmaxrestarts` =\u003e The default max restarts of a server added via the Pterodactyl API.\n* `defrestartint` =\u003e The default restart interval of a server added via the Pterodactyl API.\n* `defreportonly` =\u003e The default report only boolean of a server added via the Pterodactyl API.\n* `defmentions` =\u003e The default mentions JSON for servers added via the Pterodactyl API.\n* `servers` =\u003e An array of servers to watch (read below).\n* `misc` =\u003e An array of misc options (read below).\n\n## Egg Variable Overrides\nIf you have the `addservers` setting set to true (servers are automatically retrieved via the Pterodactyl API), you may use the following egg variables as overrides to the specific server's config.\n\n* `PTEROWATCH_DISABLE` =\u003e If set to above 0, will disable the specific server from the tool.\n* `PTEROWATCH_IP` =\u003e If not empty, will override the server IP to scan with this value for the specific server.\n* `PTEROWATCH_PORT` =\u003e If not empty, will override the server port to scan with this value for the specific server.\n* `PTEROWATCH_SCANTIME` =\u003e If not empty, will override the scan time with this value for the specific server.\n* `PTEROWATCH_MAXFAILS` =\u003e If not empty, will override the maximum fails with this value for the specific server.\n* `PTEROWATCH_MAXRESTARTS` =\u003e If not empty, will override the maximum restarts with this value for the specific server.\n* `PTEROWATCH_RESTARTINT` =\u003e If not empty, will override the restart interval with this value for the specific server.\n* `PTEROWATCH_REPORTONLY` =\u003e If not empty, will override report only with this value for the specific server.\n* `PTEROWATCH_MENTIONS` =\u003e If not empty, will override the mentions JSON string with this value for the specific server.\n\n## Server Options/Array\nThis array is used to manually add servers to watch. The `servers` array should contain the following items:\n\n* `name` =\u003e The server's name.\n* `enable` =\u003e If true, this server will be scanned.\n* `ip` =\u003e The IP to send A2S_INFO requests to.\n* `port` =\u003e The port to send A2S_INFO requests to.\n* `uid` =\u003e The server's Pterodactyl UID.\n* `scantime` =\u003e How often to scan a game server in seconds.\n* `maxfails` =\u003e The maximum amount of A2S_INFO response failures before attempting to restart the game server.\n* `maxrestarts` =\u003e The maximum amount of times we attempt to restart the server until A2S_INFO responses start coming back successfully.\n* `restartint` =\u003e When a game server is restarted, the program won't start scanning the server until *x* seconds later.\n* `reportonly` =\u003e If set, only debugging and misc options will be executed when a server is detected as down (e.g. no restart).\n* `mentions` =\u003e A JSON string that parses all custom role and user mentions inside of web hooks for this server.\n\n## Server Mentions Array\nThe server `mentions` JSON string's parsed JSON output includes a `data` list with each item including a `role` (boolean indicating whether we're mentioning a role) and `id` (the ID of the role or user in string format).\n\nHere are some examples:\n\n```JSON\n{\n        \"data\": [\n                {\n                        \"role\": true,\n                        \"id\": \"1293959919293959192\"\n                },\n                {\n                        \"role\": false,\n                        \"id\": \"1959192351293954123\"\n                }\n        ]\n}\n```\n\nThis is what it looks like inside of the mentions string.\n\n```JSON\n{\n        \"servers\": [\n                {\n                        \"mentions\": \"{\\\"data\\\":[{\\\"role\\\": true,\\\"id\\\": \\\"1293959919293959192\\\"},{\\\"role\\\": false,\\\"id\\\": \\\"1959192351293954123\\\"}]}\"\n                }\n        ]\n}\n```\n\nThe above will replace the `{MENTIONS}` text inside of the web hook's contents with `\u003c@\u00261293959919293959192\u003e, \u003c@1959192351293954123\u003e`.\n\n## Misc Options/Array\nThis tool supports misc options which are configured under the `misc` array inside of the config file. The only event supported for this at the moment is when a server is restarted from the tool. However, other events may be added in the future. An example may be found below.\n\n```JSON\n{\n        \"misc\": [\n                {\n                        \"type\": \"misctype\",\n                        \"data\": {\n                                \"option1\": \"val1\",\n                                \"option2\": \"val2\"\n                        }\n                }\n        ]\n}\n```\n\n### Web Hooks\nAs of right now, the only misc option `type` is `webhook` which indicates a web hook. The `app` data item represents what type of application the web hook is for (the default value is `discord`).\n\nPlease look at the following data items:\n\n* `app` =\u003e The web hook's application (either `discord` or `slack`).\n* `url` =\u003e The web hook's URL (**REQUIRED**).\n* `contents` =\u003e The contents of the web hook.\n* `username` =\u003e The username the web hook sends as (**only** Discord).\n* `avatarurl` =\u003e The avatar URL used with the web hook (**only** Discord).\n* `mentions` =\u003e An array including a `roles` item as a boolean allowing custom role mentions and `users` item as a boolean allowing custom user mentions.\n\n**Note** - Please copy the full web hook URL including `https://...`.\n\n#### Variable Replacements For Contents\nThe following strings are replaced inside of the `contents` string before the web hook submission.\n\n* `{IP}` =\u003e The server's IP.\n* `{PORT}` =\u003e The server's port.\n* `{FAILS}` =\u003e The server's current fail count.\n* `{RESTARTS}` =\u003e The amount of times the server has been restarted since down.\n* `{MAXFAILS}` =\u003e The server's configured max fails.\n* `{MAXRESTARTS}` =\u003e The server's configured max restarts.\n* `{UID}` =\u003e The server's UID from the config file/Pterodactyl API.\n* `{SCANTIME}` =\u003e The server's configured scan time.\n* `{RESTARTINT}` =\u003e The server's configured restart interval.\n* `{NAME}` =\u003e The server's name.\n* `{MENTIONS}` =\u003e If there are mentions, it will print them in `\u003cid\u003e, ...` format in this replacement.\n\n#### Defaults\nHere are the Discord web hook's default values.\n\n* `contents` =\u003e \\*\\*SERVER DOWN\\*\\*\\\\n- \\*\\*Name\\*\\* =\u003e {NAME}\\\\n- \\*\\*IP\\*\\* =\u003e {IP}:{PORT}\\\\n- \\*\\*Fail Count\\*\\* =\u003e {FAILS}/{MAXFAILS}\\\\n- \\*\\*Restart Count\\*\\* =\u003e {RESTARTS}/{MAXRESTARTS}\\\\n\\\\nScanning again in \\*{RESTARTINT}\\* seconds...\n* `username` =\u003e Pterowatch\n* `avatarurl` =\u003e *empty* (default)\n\n## Configuration Example\nHere's an configuration example in JSON:\n\n```JSON\n{\n        \"apiurl\": \"https://panel.mydomain.com\",\n        \"token\": \"12345\",\n        \"addservers\": true,\n\n        \"servers\": [\n                {\n                        \"enable\": true,\n                        \"ip\": \"172.20.0.10\",\n                        \"port\": 27015,\n                        \"uid\": \"testingUID\",\n                        \"scantime\": 5,\n                        \"maxfails\": 5,\n                        \"maxrestarts\": 1,\n                        \"restartint\": 120\n                },\n                {\n                        \"enable\": true,\n                        \"ip\": \"172.20.0.11\",\n                        \"port\": 27015,\n                        \"uid\": \"testingUID2\",\n                        \"scantime\": 5,\n                        \"maxfails\": 10,\n                        \"maxrestarts\": 2,\n                        \"restartint\": 120\n                }\n        ]\n}\n```\n\nYou may find other config examples in the [tests/](https://github.com/gamemann/Pterodactyl-Game-Server-Watch/tree/master/tests) directory.\n\n## Building\nYou may use `git` and `go build` to build this project and produce a binary. I'd suggest cloning this to `$GOPATH` so there aren't problems with linking modules. For example:\n\n```bash\n# Clone repository.\ngit clone https://github.com/gamemann/Pterodactyl-Game-Server-Watch.git\n\n# Change directory to respository.\ncd Pterodactyl-Game-Server-Watch/\n\n# Build, which should automatically download needed files.\ngo build -o pgsw\n```\n\n## Using Makefile To Build And Install\nYou may use `make` and `sudo make install` to build and install the project's executable to `/usr/bin` (in `$PATH` by default normally). This also copies a `Systemd` service called `pgsw.service`.\n\nSee below for examples.\n\n```bash\n# Build project into `./pgsw` executable.\nmake\n\n# Install Systemd service and file to /usr/bin/.\nsudo make install\n\n# Enable and start service (will start on bootup).\nsudo systemctl enable --now pgsw\n```\n\n## Credits\n* [Christian Deacon](https://github.com/gamemann) - Creator.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamemann%2Fpterodactyl-game-server-watch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgamemann%2Fpterodactyl-game-server-watch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamemann%2Fpterodactyl-game-server-watch/lists"}