2022-02-18 04:05:30 +08:00
|
|
|
package dev.leons.ward;
|
2020-05-13 14:06:58 +08:00
|
|
|
|
2022-03-20 23:49:08 +08:00
|
|
|
import dev.leons.ward.services.SetupService;
|
2020-06-28 22:04:59 +08:00
|
|
|
import lombok.Getter;
|
|
|
|
import org.springframework.boot.ApplicationArguments;
|
2020-05-13 14:06:58 +08:00
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
2020-06-28 22:04:59 +08:00
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
2022-02-18 01:07:23 +08:00
|
|
|
|
2020-07-21 09:25:11 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
2020-05-17 21:33:19 +08:00
|
|
|
/**
|
|
|
|
* Ward is a Spring Boot application class
|
|
|
|
*
|
|
|
|
* @author Rudolf Barbu
|
2020-08-22 15:22:08 +08:00
|
|
|
* @version 1.0.4
|
2020-05-17 21:33:19 +08:00
|
|
|
*/
|
2020-05-13 14:06:58 +08:00
|
|
|
@SpringBootApplication
|
2022-03-20 23:49:08 +08:00
|
|
|
public class Ward extends SpringBootServletInitializer {
|
2020-07-02 01:54:20 +08:00
|
|
|
/**
|
|
|
|
* Constant for determine settings file name
|
|
|
|
*/
|
2020-07-21 09:25:11 +08:00
|
|
|
public static final String SETUP_FILE_PATH = "setup.ini";
|
2020-07-02 01:54:20 +08:00
|
|
|
|
2020-07-02 03:35:28 +08:00
|
|
|
/**
|
|
|
|
* Constant for determine initial application port
|
|
|
|
*/
|
|
|
|
public static final int INITIAL_PORT = 4000;
|
|
|
|
|
2020-06-28 22:04:59 +08:00
|
|
|
/**
|
2020-07-29 08:30:33 +08:00
|
|
|
* Holder for determine first launch of application
|
2020-06-28 22:04:59 +08:00
|
|
|
*/
|
|
|
|
@Getter
|
|
|
|
private static boolean isFirstLaunch;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holder for application context
|
|
|
|
*/
|
|
|
|
private static ConfigurableApplicationContext configurableApplicationContext;
|
|
|
|
|
2020-05-17 21:33:19 +08:00
|
|
|
/**
|
|
|
|
* Entry point of Ward application
|
|
|
|
*
|
|
|
|
* @param args Spring Boot application arguments
|
|
|
|
*/
|
2022-03-20 23:49:08 +08:00
|
|
|
public static void main(final String[] args) {
|
|
|
|
|
2020-06-28 22:04:59 +08:00
|
|
|
isFirstLaunch = true;
|
|
|
|
configurableApplicationContext = SpringApplication.run(Ward.class, args);
|
2020-07-21 09:25:11 +08:00
|
|
|
|
|
|
|
File setupFile = new File(Ward.SETUP_FILE_PATH);
|
2022-03-20 23:49:08 +08:00
|
|
|
|
2024-02-25 01:59:42 +08:00
|
|
|
if (System.getenv("WARD_NAME") != null || (System.getenv("WARD_THEME") != null) || (System.getenv("WARD_PORT") != null) || (System.getenv("WARD_FOG") != null)) {
|
2022-03-20 23:49:08 +08:00
|
|
|
SetupService.envSetup();
|
|
|
|
} else if (setupFile.exists()) {
|
2020-07-21 09:25:11 +08:00
|
|
|
restart();
|
|
|
|
}
|
2020-06-28 22:04:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restarts application
|
|
|
|
*/
|
2022-03-20 23:49:08 +08:00
|
|
|
public static void restart() {
|
2020-06-28 22:04:59 +08:00
|
|
|
isFirstLaunch = false;
|
|
|
|
ApplicationArguments args = configurableApplicationContext.getBean(ApplicationArguments.class);
|
|
|
|
|
|
|
|
Thread thread = new Thread(() ->
|
|
|
|
{
|
|
|
|
configurableApplicationContext.close();
|
|
|
|
configurableApplicationContext = SpringApplication.run(Ward.class, args.getSourceArgs());
|
|
|
|
});
|
|
|
|
|
2020-08-22 22:28:19 +08:00
|
|
|
thread.setDaemon(false);
|
2020-06-28 22:04:59 +08:00
|
|
|
thread.start();
|
2020-05-13 14:06:58 +08:00
|
|
|
}
|
|
|
|
}
|