docker-minecraft-server icon indicating copy to clipboard operation
docker-minecraft-server copied to clipboard

Ability to run shell command instead/in addition to rcon commands.

Open Buco7854 opened this issue 2 years ago • 7 comments

Enhancement Type

Improve an existing feature

Describe the enhancement

Hello, That would be really nice if we could have something like RCON_CMDS_STARTUP for shell so that we could for example add custom scripts in a volume and run them when some events are triggered. I took a look to rcon-cmds-daemon.sh and I believe it could be easily adaptable for shell commands since it seems it just call the command prepended by rcon-cli. Either we could add a secondary run_command function or just remove the prepend but it woudl kind of break compatibility so I guess first option is better. Please let me know what you think about it and either way thanks for this wonderful image.

Buco7854 avatar Aug 06 '23 18:08 Buco7854

That would certainly be quite doable. It feels like a security risk to allow arbitrary system commands to run; however, I can't pinpoint any particular exploit that couldn't already done by exec'ing into the container.

What are some examples of things you would want to script into those events? Arbitrary scripts would also have to make use of things pre-installed.

itzg avatar Aug 06 '23 21:08 itzg

That would certainly be quite doable. It feels like a security risk to allow arbitrary system commands to run; however, I can't pinpoint any particular exploit that couldn't already done by exec'ing into the container.

What are some examples of things you would want to script into those events? Arbitrary scripts would also have to make use of things pre-installed.

Well for example some kind of webhook when someone gets online for a friends server. that was my use case, but I mean anything can be done, just need the events and then it's up to anyone to develop whatever they feel like doing.

Buco7854 avatar Aug 06 '23 22:08 Buco7854

It certainly is dependent on the container itself, but for example, Python is already pre-installed on quite a lot of them, and worst case we coudl use the startup event to run a script to install the dependencies.

Buco7854 avatar Aug 06 '23 22:08 Buco7854

I am 100% on board with supporting webhooks. mc-image-helper can be enhanced in any way to streamline that.

It certainly is dependent on the container itself, but for example, Python is already pre-installed on quite a lot of them,

Well, in this case, this image purposely hasn't installed python in order to try minimizing the image size.

and worst case we coudl use the startup event to run a script to install the dependencies.

That's starting to sound a little too arbitrary and makes me nervous. Besides, any extra packages installed will all go away on next container restart. It can take a minute or two to install packages -- that doesn't seem like an acceptable delay for event handling.

I will queue this up for considering webhook support, but even then I'd like to scope to a particular use case or two.

itzg avatar Aug 06 '23 23:08 itzg

I am 100% on board with supporting webhooks. mc-image-helper can be enhanced in any way to streamline that.

It certainly is dependent on the container itself, but for example, Python is already pre-installed on quite a lot of them,

Well, in this case, this image purposely hasn't installed python in order to try minimizing the image size.

and worst case we coudl use the startup event to run a script to install the dependencies.

That's starting to sound a little too arbitrary and makes me nervous. Besides, any extra packages installed will all go away on next container restart. It can take a minute or two to install packages -- that doesn't seem like an acceptable delay for event handling.

I will queue this up for considering webhook support, but even then I'd like to scope to a particular use case or two.

Well I certainly see your point. Limiting it to webhooks seems fine for me. I guess receive event and then executing some command using rcon from outside for aditional data or would it send some actual data with the event ?

Buco7854 avatar Aug 06 '23 23:08 Buco7854

Yeah, I'm thinking the webhook method (GET, POST, etc), URL, and body template string could be the input environment variables. That template can be JSON or whatever the receiver needs and substituted with certain variables: event type, player count, etc.

itzg avatar Aug 07 '23 00:08 itzg

Yeah, I'm thinking the webhook method (GET, POST, etc), URL, and body template string could be the input environment variables. That template can be JSON or whatever the receiver needs and substituted with certain variables: event type, player count, etc.

That seems like a good way, thanks for considering it 🙂.

Buco7854 avatar Aug 07 '23 00:08 Buco7854