@@ -17,6 +17,10 @@ trait UsesMinIOServer
1717
1818 public Collection $ minIODiskConfig ;
1919
20+ public bool $ minIODestroyed = false ;
21+
22+ public bool $ minIOEnvironmentRestored = false ;
23+
2024 public function bootUsesMinIOServer ()
2125 {
2226 $ this ->startMinIOServer ();
@@ -120,14 +124,24 @@ public function startMinIOServer(): bool
120124
121125 $ pid = $ this ->exec ("minio server {$ temporaryDirectory ->path ()} --address : {$ this ->minIOPort } > /dev/null 2>&1 & echo $! " );
122126
123- register_shutdown_function (function () use ($ pid , $ temporaryDirectory ) {
127+ $ killMinIOAndDeleteStorage = function () use ($ pid , $ temporaryDirectory ) {
128+ if ($ this ->minIODestroyed ) {
129+ return ;
130+ }
131+
124132 if ($ pid ) {
125133 $ this ->exec ("kill {$ pid }" );
126134 }
127135
128136 // deleting the directory might fail when minio is not killed yet
129137 rescue (fn () => $ temporaryDirectory ->delete ());
130- });
138+
139+ $ this ->minIODestroyed = true ;
140+ };
141+
142+ $ this ->beforeApplicationDestroyed ($ killMinIOAndDeleteStorage );
143+
144+ register_shutdown_function ($ killMinIOAndDeleteStorage );
131145
132146 $ tries = 0 ;
133147
@@ -216,6 +230,8 @@ public function updateEnvirionmentFile()
216230
217231 file_put_contents ($ envFilename , $ env );
218232
233+ $ this ->beforeApplicationDestroyed (fn () => $ this ->restoreEnvironmentFile ());
234+
219235 register_shutdown_function (fn () => $ this ->restoreEnvironmentFile ());
220236 }
221237
@@ -227,6 +243,10 @@ public function updateEnvirionmentFile()
227243 */
228244 public function restoreEnvironmentFile ()
229245 {
246+ if ($ this ->minIOEnvironmentRestored ) {
247+ return ;
248+ }
249+
230250 $ envFilename = base_path ('.env ' );
231251
232252 if (!file_exists ($ envFilename )) {
@@ -244,5 +264,7 @@ public function restoreEnvironmentFile()
244264 });
245265
246266 file_put_contents ($ envFilename , $ env );
267+
268+ $ this ->minIOEnvironmentRestored = true ;
247269 }
248270}
0 commit comments