diff --git a/config.properties b/config.properties index 9e85cf3..f30c78b 100644 --- a/config.properties +++ b/config.properties @@ -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 diff --git a/src/main/java/me/kavin/piped/Main.java b/src/main/java/me/kavin/piped/Main.java index d823bc0..77a361c 100644 --- a/src/main/java/me/kavin/piped/Main.java +++ b/src/main/java/me/kavin/piped/Main.java @@ -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,13 +41,21 @@ public class Main { } }, 0, TimeUnit.MINUTES.toMillis(60)); - new Thread(() -> { - try { - new ServerLauncher().launch(args); - } catch (Exception e) { - throw new RuntimeException(e); - } - }).start(); + if (!Constants.DISABLE_SERVER) + new Thread(() -> { + try { + new ServerLauncher().launch(args); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).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; diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index ddef6e1..3ef5f81 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -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);