Handle Paper's saved exit-130 service state during Lobby restart
All checks were successful
Lobby Arrakis View Distance / configuration (push) Successful in 5s
DuneRealms Plugin CI / plugins (push) Successful in 2m53s

This commit is contained in:
unimatrixgit 2026-11-30 18:20:57 +01:00
commit 8923dbe0d0
2 changed files with 11 additions and 3 deletions

View file

@ -56,11 +56,11 @@ def main():
result={'world':'lobby_arrakis','viewDistance':20,'serverPropertiesViewDistance':20,'otherWorldDefaultPreserved':old_global,'previousOverride':previous,'beforeSha256':sha(before),'afterSha256':sha(after),'propertiesBeforeSha256':sha(prop_before),'propertiesAfterSha256':sha(prop_after),'applied':False}
if args.apply and any(old!=new for _,old,new,_ in changes):
state=control('show',UNIT,'--property=ActiveState','--value').stdout.strip()
if state not in ('active','inactive'):raise ValueError('Lobby service is in transition')
active=state=='active';directory=RECEIPT_ROOT/datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ');directory.mkdir(parents=True,mode=0o700)
if state not in ('active','inactive','failed'):raise ValueError('Lobby service is in transition')
active=state in ('active','failed');directory=RECEIPT_ROOT/datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ');directory.mkdir(parents=True,mode=0o700)
for path,old,_,_ in changes:
saved=directory/(path.name+'.before');saved.write_bytes(old);saved.chmod(0o600)
if active and (control('stop',UNIT).returncode or control('show',UNIT,'--property=ActiveState','--value').stdout.strip()!='inactive'):raise RuntimeError('Lobby did not stop')
if active and (control('stop',UNIT).returncode or control('show',UNIT,'--property=ActiveState','--value').stdout.strip() not in ('inactive','failed')):raise RuntimeError('Lobby did not stop')
if any(path.read_bytes()!=old for path,old,_,_ in changes):
if active:control('start',UNIT)
raise RuntimeError('Lobby configuration changed after planning; no files written')

View file

@ -31,4 +31,12 @@ class WorldViewDistance(unittest.TestCase):
with patch.object(module,'ROOT',root),patch.object(module,'RECEIPT_ROOT',root/'ops'),patch.object(module,'control',control),patch.object(sys,'argv',['helper','--apply']):
with self.assertRaisesRegex(RuntimeError,'no files written'):module.main()
self.assertEqual((root/'spigot.yml').read_bytes(),before);self.assertIn(b'motd=newer',(root/'server.properties').read_bytes());self.assertIn(('start',module.UNIT),calls)
def test_paper_exit_130_failed_unit_is_safely_stopped_and_restarted(self):
with tempfile.TemporaryDirectory() as name:
root=Path(name);(root/'lobby_base/dimensions/minecraft/lobby_arrakis').mkdir(parents=True);(root/'spigot.yml').write_bytes(b'world-settings:\n default:\n view-distance: default\n');(root/'server.properties').write_bytes(b'view-distance=5\nsimulation-distance=3\n')
calls=[]
def control(*args):
calls.append(args);return SimpleNamespace(returncode=0,stdout='failed' if any(c[0]=='stop' for c in calls) else 'active')
with patch.object(module,'ROOT',root),patch.object(module,'RECEIPT_ROOT',root/'ops'),patch.object(module,'control',control),patch.object(module,'write',lambda p,data,meta:p.write_bytes(data)),patch.object(sys,'argv',['helper','--apply']):module.main()
self.assertIn(b'view-distance=20',(root/'server.properties').read_bytes());self.assertIn(('start',module.UNIT),calls)
if __name__=='__main__':unittest.main()