Skip to content

Instantly share code, notes, and snippets.

@liyuntao
Last active May 15, 2020 07:58
Show Gist options
  • Save liyuntao/8b918d2ebabb0472f9c8ffa52065d116 to your computer and use it in GitHub Desktop.
Save liyuntao/8b918d2ebabb0472f9c8ffa52065d116 to your computer and use it in GitHub Desktop.
check sharedVolume mounted on startup
public class Starter {
Logger log = LoggerFactory.getLogger(Starter.class);
/**
* 服务启动方法
*/
public static void main(String[] args) {
SpringApplication app = new SpringApplication();
app.addListeners(new CheckSharedMount());
app.setSources(new HashSet(Arrays.asList(Starter.class)));
app.run(args);
}
}
@Slf4j
class CheckSharedMount implements ApplicationListener<ApplicationContextInitializedEvent> {
@Override
public void onApplicationEvent(ApplicationContextInitializedEvent event) {
ConfigurableEnvironment env = event.getApplicationContext().getEnvironment();
List<String> profiles = Arrays.asList(env.getActiveProfiles());
if (!profiles.contains("dev")
&& !profiles.contains("uat")
&& !profiles.contains("prod")) {
return;
}
if (!new File("/data/xxx/gfs.mounted").isFile()) {
log.error("Fatal Error: marker file 'gfs.mounted' not found! Please check whether shared volume(e.g. glusterfs) is correctly mounted.");
System.exit(1);
} else {
log.info("checking mount point: shared volume mounted successfully!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment