- Notifications
You must be signed in to change notification settings - Fork5
A tool programmed in Go to automatically restart 'hung' game servers/containers via a Pterodactyl API.
License
gamemann/Pterodactyl-Game-Server-Watch
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A 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 theA2S_INFO query (a Valve Master Server query). I am currently looking for a better way to detect if a server is hung, though.
There is only one command line argument/flag and it is-cfg=<path>
. This argument/flag changes the path to the Pterowatch config file. The default value is/etc/pterowatch/pterowatch.conf
.
Examples include:
./pterowatch -cfg=/home/cdeacon/myconf.conf./pterowatch -cfg=~/myconf.conf./pterowatch -cfg=myconf.conf
The 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:
apiurl
=> The Pterodactyl API URL (do not include the/
at the end).token
=> The bearer token (from the client) to use when sending requests to the Pterodactyl API.apptoken
=> The bearer token (from the application) to use when sending requests to the Pterodactyl API (this is only needed whenaddservers
is set totrue
).debug
=> The debug level (1-4).reloadtime
=> If above 0, will reload the configuration file and retrieve servers from the API everyx seconds.addservers
=> Whether or not to automatically add servers to the config from the Pterodactyl API.defenable
=> The default enable boolean of a server added via the Pterodactyl API.defscantime
=> The default scan time of a server added via the Pterodactyl API.defmaxfails
=> The default max fails of a server added via the Pterodactyl API.defmaxrestarts
=> The default max restarts of a server added via the Pterodactyl API.defrestartint
=> The default restart interval of a server added via the Pterodactyl API.defreportonly
=> The default report only boolean of a server added via the Pterodactyl API.defmentions
=> The default mentions JSON for servers added via the Pterodactyl API.servers
=> An array of servers to watch (read below).misc
=> An array of misc options (read below).
If you have theaddservers
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.
PTEROWATCH_DISABLE
=> If set to above 0, will disable the specific server from the tool.PTEROWATCH_IP
=> If not empty, will override the server IP to scan with this value for the specific server.PTEROWATCH_PORT
=> If not empty, will override the server port to scan with this value for the specific server.PTEROWATCH_SCANTIME
=> If not empty, will override the scan time with this value for the specific server.PTEROWATCH_MAXFAILS
=> If not empty, will override the maximum fails with this value for the specific server.PTEROWATCH_MAXRESTARTS
=> If not empty, will override the maximum restarts with this value for the specific server.PTEROWATCH_RESTARTINT
=> If not empty, will override the restart interval with this value for the specific server.PTEROWATCH_REPORTONLY
=> If not empty, will override report only with this value for the specific server.PTEROWATCH_MENTIONS
=> If not empty, will override the mentions JSON string with this value for the specific server.
This array is used to manually add servers to watch. Theservers
array should contain the following items:
name
=> The server's name.enable
=> If true, this server will be scanned.ip
=> The IP to send A2S_INFO requests to.port
=> The port to send A2S_INFO requests to.uid
=> The server's Pterodactyl UID.scantime
=> How often to scan a game server in seconds.maxfails
=> The maximum amount of A2S_INFO response failures before attempting to restart the game server.maxrestarts
=> The maximum amount of times we attempt to restart the server until A2S_INFO responses start coming back successfully.restartint
=> When a game server is restarted, the program won't start scanning the server untilx seconds later.reportonly
=> If set, only debugging and misc options will be executed when a server is detected as down (e.g. no restart).mentions
=> A JSON string that parses all custom role and user mentions inside of web hooks for this server.
The servermentions
JSON string's parsed JSON output includes adata
list with each item including arole
(boolean indicating whether we're mentioning a role) andid
(the ID of the role or user in string format).
Here are some examples:
{"data": [ {"role":true,"id":"1293959919293959192" }, {"role":false,"id":"1959192351293954123" } ]}
This is what it looks like inside of the mentions string.
{"servers": [ {"mentions":"{\"data\":[{\"role\": true,\"id\":\"1293959919293959192\"},{\"role\": false,\"id\":\"1959192351293954123\"}]}" } ]}
The above will replace the{MENTIONS}
text inside of the web hook's contents with<@&1293959919293959192>, <@1959192351293954123>
.
This tool supports misc options which are configured under themisc
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.
{"misc": [ {"type":"misctype","data": {"option1":"val1","option2":"val2" } } ]}
As of right now, the only misc optiontype
iswebhook
which indicates a web hook. Theapp
data item represents what type of application the web hook is for (the default value isdiscord
).
Please look at the following data items:
app
=> The web hook's application (eitherdiscord
orslack
).url
=> The web hook's URL (REQUIRED).contents
=> The contents of the web hook.username
=> The username the web hook sends as (only Discord).avatarurl
=> The avatar URL used with the web hook (only Discord).mentions
=> An array including aroles
item as a boolean allowing custom role mentions andusers
item as a boolean allowing custom user mentions.
Note - Please copy the full web hook URL includinghttps://...
.
The following strings are replaced inside of thecontents
string before the web hook submission.
{IP}
=> The server's IP.{PORT}
=> The server's port.{FAILS}
=> The server's current fail count.{RESTARTS}
=> The amount of times the server has been restarted since down.{MAXFAILS}
=> The server's configured max fails.{MAXRESTARTS}
=> The server's configured max restarts.{UID}
=> The server's UID from the config file/Pterodactyl API.{SCANTIME}
=> The server's configured scan time.{RESTARTINT}
=> The server's configured restart interval.{NAME}
=> The server's name.{MENTIONS}
=> If there are mentions, it will print them in<id>, ...
format in this replacement.
Here are the Discord web hook's default values.
contents
=> **SERVER DOWN**\n- **Name** => {NAME}\n- **IP** => {IP}:{PORT}\n- **Fail Count** => {FAILS}/{MAXFAILS}\n- **Restart Count** => {RESTARTS}/{MAXRESTARTS}\n\nScanning again in *{RESTARTINT}* seconds...username
=> Pterowatchavatarurl
=>empty (default)
Here's an configuration example in JSON:
{"apiurl":"https://panel.mydomain.com","token":"12345","addservers":true,"servers": [ {"enable":true,"ip":"172.20.0.10","port":27015,"uid":"testingUID","scantime":5,"maxfails":5,"maxrestarts":1,"restartint":120 }, {"enable":true,"ip":"172.20.0.11","port":27015,"uid":"testingUID2","scantime":5,"maxfails":10,"maxrestarts":2,"restartint":120 } ]}
You may find other config examples in thetests/ directory.
You may usegit
andgo 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:
# Clone repository.git clone https://github.com/gamemann/Pterodactyl-Game-Server-Watch.git# Change directory to respository.cd Pterodactyl-Game-Server-Watch/# Build, which should automatically download needed files.go build -o pgsw
You may usemake
andsudo make install
to build and install the project's executable to/usr/bin
(in$PATH
by default normally). This also copies aSystemd
service calledpgsw.service
.
See below for examples.
# Build project into `./pgsw` executable.make# Install Systemd service and file to /usr/bin/.sudo make install# Enable and start service (will start on bootup).sudo systemctlenable --now pgsw
- Christian Deacon - Creator.
About
A tool programmed in Go to automatically restart 'hung' game servers/containers via a Pterodactyl API.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.