Context and Need:
Currently, when a FiveM server is restarted or shut down (e.g., due to updates or scheduled restarts), the resource stop
event is not consistently triggered during the shutdown process. This creates issues for resources that need to perform specific actions during shutdown, such as saving data, releasing database connections, or gracefully shutting down services.
While the resource stop
event is triggered when an individual resource is stopped, it is not triggered when the entire server is shutting down or restarting, limiting the ability to perform proper shutdown tasks.
Proposed Implementation:
I propose adding a new native event, serverShuttingDown
, which would be automatically triggered when the server begins the shutdown or restart process. This event would be useful for:
- Executing shutdown tasks for resources: Allowing server resources to perform operations like saving persistent data, clearing caches, or closing external service connections.
- Synchronization with monitoring systems (e.g., txAdmin): Making it easier for monitoring and management systems, like txAdmin, to react to the server shutdown and perform controlled actions.
- Preventing issues with automatic restarts: Helping ensure that critical resources are properly finalized during restarts, preventing issues related to data loss or unexpected disconnections.
Proposed Usage of the serverShuttingDown
Event:
- The event would be triggered at the beginning of the server shutdown process.
- It would allow developers to add custom logic for saving data, closing connections, or performing other cleanup tasks.
Usage Example:
In Lua, a resource can listen for this event to perform cleanup operations when the server is shutting down:
AddEventHandler('serverShuttingDown', function()
print("Server is shutting down. Performing cleanup tasks...")
-- Add any necessary logic to finalize processes here
end)
Expected Benefits:
- Better control over resource shutdowns in FiveM.
- Reduced risk of failures or data loss during server restarts.
- More robust integration with external monitoring and server management tools.
- Ability to perform actions in an orderly fashion, especially in production environments.
Conclusion:
I believe the introduction of this event would allow for more reliable and secure server management, ensuring critical operations are completed before the server is fully shut down