dLine();
while (line != null) {
if (line.trim().startsWith("Active")) {
if (line.trim().indexOf("inactive (dead)") > 0)
status = DepolyStatus.Stopped;
else if (line.trim().indexOf("active (running)") > 0)
status = DepolyStatus.Running;
else if (line.trim().indexOf("failed") > 0)
status = DepolyStatus.Stopped;
}
line = reader.readLine();
}
} catch (IOException e) {
LogUtil.error(e);
}
return status;
}
通过拷贝service文件到systemd/system目录下注册linux服务
yml配置文件识别
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.26</version>
</dependency>
jarmanage:
port: 8555
username: admin
password: abcd@1234
backupcount: 5
public static String getConfigValue(String configName){
String configValue = "";
try{
Yaml yaml = new Yaml();
InputStream resourceAsStream = new FileInputStream(new File("resources"+File.separator+"application.yml"));
Map obj = yaml.load(resourceAsStream);
Map<String,Object> param = (Map) obj.get("jarmanage");
configValue = ConvertUtil.convert2String(param.get(configName));
}catch (Exception e){
LogUtil.error(e);
}
return configValue;
}
h2database使用
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.214</version>
</dependency>
public static Connection getConnection() throws Exception {
File file = new File("database");
Connection conn = DriverManager.getConnection("jdbc:h2:file:" + file.getAbsolutePath() + File.separator + "manage", "root", "abcd@1234");
return conn;
}
public static void executeSQL(String sql) {
try {
Connection conn = getConnection();
Statement stmt = conn.createStatement();
stmt.execute(sql);
stmt.close();
conn.close();
} catch (Exception e) {
LogUtil.error(e);
}
}
servelt内置tomcat打包
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.35</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>9.0.35</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.35</version>
</dependency>
//启动tomcat服务
// 1.创建一个内嵌的Tomcat
Tomcat tomcat = new Tomcat();
// 2.设置Tomcat端口
tomcat.setPort(8555);
// 3.设置工作目录,tomcat需要使用这个目录进行写一些东西
final String baseDir = "workspace" + File.separator;
tomcat.setBaseDir(baseDir);
tomcat.getHost().setAutoDeploy(false);
// 4. 设置webapp资源路径
String webappDirLocation = "webapp" + File.separator;
StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
// 5. 设置上下文路每径
String contextPath = "";
ctx.setPath(contextPath);
ctx.addLifecycleListener(new