Merge pull request #316 from TeamPiped/disable-server

Allow disabling server on a node.
This commit is contained in:
Kavin 2022-07-19 14:20:06 +05:30 committed by GitHub
commit 66a9f27746
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View file

@ -25,6 +25,8 @@ DISABLE_TIMERS:false
RYD_PROXY_URL:https://ryd-proxy.kavin.rocks
# Disable the usage of RYD
DISABLE_RYD:false
# Disable API server (node just runs timers if enabled)
DISABLE_SERVER:false
# Hibernate properties
hibernate.connection.url:jdbc:postgresql://postgres:5432/piped
hibernate.connection.driver_class:org.postgresql.Driver

View file

@ -9,6 +9,7 @@ import me.kavin.piped.utils.obj.db.PlaylistVideo;
import me.kavin.piped.utils.obj.db.PubSub;
import me.kavin.piped.utils.obj.db.User;
import me.kavin.piped.utils.obj.db.Video;
import org.hibernate.Session;
import org.hibernate.StatelessSession;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.localization.Localization;
@ -40,6 +41,7 @@ public class Main {
}
}, 0, TimeUnit.MINUTES.toMillis(60));
if (!Constants.DISABLE_SERVER)
new Thread(() -> {
try {
new ServerLauncher().launch(args);
@ -48,6 +50,13 @@ public class Main {
}
}).start();
try (Session ignored = DatabaseSessionFactory.createSession()) {
System.out.println("Database connection is ready!");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
if (Constants.DISABLE_TIMERS)
return;

View file

@ -55,6 +55,8 @@ public class Constants {
public static final boolean DISABLE_RYD;
public static final boolean DISABLE_SERVER;
public static final String VERSION;
public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class);
@ -84,6 +86,7 @@ public class Constants {
DISABLE_TIMERS = Boolean.parseBoolean(getProperty(prop, "DISABLE_TIMERS", "false"));
RYD_PROXY_URL = getProperty(prop, "RYD_PROXY_URL", "https://ryd-proxy.kavin.rocks");
DISABLE_RYD = Boolean.parseBoolean(getProperty(prop, "DISABLE_RYD", "false"));
DISABLE_SERVER = Boolean.parseBoolean(getProperty(prop, "DISABLE_SERVER", "false"));
System.getenv().forEach((key, value) -> {
if (key.startsWith("hibernate"))
hibernateProperties.put(key, value);