[Mod] Filesystem Safeguard [safeguard]

Post Reply
User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

[Mod] Filesystem Safeguard [safeguard]

by sorcerykid » Post

Filesystem Safeguard Mod v1.0
safeguard (by sorcerykid)

Filesystem Safeguard Mod performs a routine check of the mounted filesystems containing the Minetest debug log and world directory, and performs an immediate shutdown of the Minetest server if the available space is below a predefined threshold. This helps to protect against catastrophic data loss on production servers, including corruption of the map database.

Note: This mod will only work under Linux, since it performs a "df" shell command. It is also necessary to patch the Minetest engine with the minetest.get_system_path() API function in script/lua_api/l_util.cpp as shown below:

Code: Select all

// get_system_path( filespec )
int ModApiUtil::l_get_system_path( lua_State *L )
{
        NO_MAP_LOCK_REQUIRED;
        std::string filespec = luaL_checkstring( L, 1 );
        if( filespec == "debug.txt" ) {
                lua_pushstring( L, g_log_filename.c_str( ) );
        }
        else if( filespec == "minetest.conf" ) {
                lua_pushstring( L, g_settings_path.c_str( ) );
        }
        else if( filespec == "minetestserver" ) {
                char buf[ BUFSIZ ];
                bool success =
                        porting::getCurrentExecPath( buf, sizeof( buf ) ) ||
                        porting::getExecPathFromProcfs( buf, sizeof( buf ) );
                lua_pushstring( L, buf );
        }
        else {
                lua_pushnil( L );
        }
        return 1;
}
There are three available options which can be set in the config.lua file:

Code: Select all

min_world_free_space = 500      -- in megabytes
min_debug_free_space = 10       -- in megabytes
check_period = 30               -- in minutes
Keep in mind, the server will also not startup until the necessary disk space is available. This is an added precaution, particularly if you have automated scripts that restart the Minetest process after an error.

Code: Select all

2022-09-12 21:50:18: ACTION[Main]: [safeguard] Performing initial filesystem analysis...
  868580 MB used     727 MB free 100% usage /home/minetest/.minetest/test.log
  868580 MB used     727 MB free 100% usage /home/minetest/.minetest/worlds/test
2022-09-12 21:50:18: WARNING[Main]: [safeguard] Shutting down server to avoid potential data loss...
Repository:

https://bitbucket.org/sorcerykid/safeguard

Download Archive (.zip)
Download Archive (.tar.gz)

Dependencies:

Configuration Panel Mod (config)
Timekeeper Mod (timekeeper)

Source Code License:

The MIT License (MIT)

Installation:
  1. Unzip the archive into the mods directory of your game
  2. Rename the safeguard-master directory to "safeguard"

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 17 guests