Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new event onShutdown #3732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FileEX
Copy link
Contributor

@FileEX FileEX commented Sep 17, 2024

This PR adds the onShutdown event, which is triggered when the shutdown command or function is used. This event was created to allow for a 'safe shutdown.' We have no control over the order in which scripts shut down, which can cause issues in complex gamemodes, where, for example, the script handling the database may shut down first, and then the script saving the data, leading to problems. If we have multiple scripts that rely on, say, a database script, manually adding shutdown procedures to all of them can be tedious. This event allows resources to be stopped in the correct order to avoid potential problems. A similar issue is discussed here: https://forum.multitheftauto.com/topic/82046-resource-stop-priority/

Params: resource, reason

@Xenius97
Copy link
Contributor

We have no control over the order in which scripts shut down

I think this should based on download_priority_group just like starting them on client, but reversed, eg. 9999 prio resource shutting down before 9998.

@Fernando-A-Rocha
Copy link
Contributor

Nice! What code would u write in an onShutdown handler?

@FileEX
Copy link
Contributor Author

FileEX commented Sep 18, 2024

Nice! What code would u write in an onShutdown handler?

stopping resources in the right order to avoid problems with data saving. Read example from the link

@CrosRoad95
Copy link
Contributor

CrosRoad95 commented Sep 18, 2024

Test if it working well in docker environment, i imagine you shutdown container and you want graceful save players, vehicles ect.

I'm telling you this because mta may not work well with docker and novadays most big servers are using it. Mta may not send proper signal to operating system what may lead to killing process before "onShutdown" end

You probably should do something like print("stopping"), then few queries like select sleep(1000) and print("stopped") to test if everything went all right

@botder
Copy link
Member

botder commented Sep 18, 2024

If somebody plans or runs an MTA server in Docker, they should use something like https://github.com/krallin/tini for launching the server executable for graceful and clean shutdowns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants