From 8923dbe0d0e1825452847a1a363aa31e5bbe141c Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Mon, 30 Nov 2026 18:20:57 +0100 Subject: [PATCH] Handle Paper's saved exit-130 service state during Lobby restart --- tools/lobby-arrakis-view-distance.py | 6 +++--- tools/test_lobby_arrakis_view_distance.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/lobby-arrakis-view-distance.py b/tools/lobby-arrakis-view-distance.py index 1a9188dc..ba7ea1ed 100644 --- a/tools/lobby-arrakis-view-distance.py +++ b/tools/lobby-arrakis-view-distance.py @@ -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') diff --git a/tools/test_lobby_arrakis_view_distance.py b/tools/test_lobby_arrakis_view_distance.py index 8b2896d4..9ad52cc2 100644 --- a/tools/test_lobby_arrakis_view_distance.py +++ b/tools/test_lobby_arrakis_view_distance.py @@ -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()