Skip to content

Commit c6ac963

Browse files
committed
kill server when a new version is uploaded
1 parent cd5c256 commit c6ac963

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

build.gradle

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ buildscript {
2020
}
2121
dependencies {
2222
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")
23+
classpath 'org.ajoberstar:grgit:1.1.0'
2324
}
2425
}
25-
26+
import groovy.json.JsonSlurper
27+
ext {
28+
git = org.ajoberstar.grgit.Grgit.open(file('./'))
29+
revision = git.head().abbreviatedId
30+
buildnum = "$System.env.BUILD_NUMBER"
31+
}
2632
jar {
2733
baseName = 'animecap'
2834
version = '0.0.1'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.animecap.system;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.stereotype.Component;
5+
6+
import java.io.File;
7+
import java.util.logging.Logger;
8+
9+
/**
10+
* Created by Nathaniel on 3/2/2017.
11+
*/
12+
@Component
13+
public class CloseHandler implements Runnable {
14+
@Bean
15+
public boolean createThread(){
16+
new Thread(new CloseHandler()).start();
17+
return true;
18+
}
19+
20+
protected Logger logger = Logger.getLogger(CloseHandler.class.getName());
21+
22+
public void run() {
23+
try {
24+
File file = new File(CloseHandler.class.getProtectionDomain().getCodeSource().getLocation().toString().split("!")[0].split("jar:file:")[1]);
25+
while (true) {
26+
if(!file.exists()){
27+
logger.info("Jar was deleted, closing down server!");
28+
logger.info("Closing in 30 seconds!");
29+
System.exit(0);
30+
}
31+
try {
32+
Thread.sleep(200);
33+
} catch (Exception e) {
34+
e.printStackTrace();
35+
}
36+
}
37+
}catch (Exception e){
38+
e.printStackTrace();
39+
}
40+
}
41+
}

src/main/java/com/animecap/system/VideoConverter.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.animecap.system;
22
import org.springframework.boot.SpringApplication;
33
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
45
import org.springframework.scheduling.annotation.EnableScheduling;
56

67
import javax.annotation.PostConstruct;
78
import java.io.File;
9+
import java.util.HashMap;
810

911
/**
1012
* Created by Nathaniel on 11/26/2016.
@@ -16,10 +18,19 @@ public class VideoConverter {
1618
public static String sourceDirectory = "sources/";
1719
public static String uploadDirectory = "uploads/";
1820
public static void main(String[] args) {
19-
SpringApplication app = new SpringApplication(VideoConverter.class);
21+
System.setProperty("spring.config.name", "www-server");
22+
2023
if(!new File("uploads/").exists()){
2124
new File("uploads/").mkdir();
2225
}
23-
app.run(args);
26+
27+
int port=2115;
28+
29+
System.setProperty("server.port", String.valueOf(port));
30+
31+
HashMap<String, Object> props = new HashMap<>();
32+
props.put("server.port", port);
33+
34+
new SpringApplicationBuilder().sources(VideoConverter.class).properties(props).run(args);
2435
}
2536
}

src/main/java/com/animecap/system/controllers/VideoController.java

+1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ public Video video(@RequestParam("uuid") String vUUID) {
6565
}
6666

6767

68+
6869
}

0 commit comments

Comments
 (0)