diff --git a/build.sbt b/build.sbt index 09bd57e..55dcc26 100644 --- a/build.sbt +++ b/build.sbt @@ -16,7 +16,7 @@ val env = sys.props.getOrElse("env", default = "local") val buildVersion = sys.props.getOrElse("version", default = "0.0.1") val buildName = "btc-hotspot" -val akkaVersion = "2.4.20" +val akkaVersion = "2.5.11" val akkaHttpVersion = "10.+" val json4sVersion = "3.+" @@ -44,7 +44,7 @@ lazy val btc_hotspot = (project in file(".")). //JSON4S "org.json4s" %% "json4s-native" % json4sVersion, "org.json4s" %% "json4s-ext" % json4sVersion, - "de.heikoseeberger" %% "akka-http-json4s" % "1.+", + "de.heikoseeberger" %% "akka-http-json4s" % "1.20.1", //LOGGING "ch.qos.logback" % "logback-classic" % "1.2.3", @@ -106,7 +106,9 @@ lazy val universalPluginSettings = Seq( confFileMapping.value, logbackConfMapping.value ) - } + }, + databaseDirectory, + databaseDirSymlink ) @@ -126,6 +128,18 @@ lazy val confFileMapping = Def.setting { conf -> "conf/application.conf" } +lazy val databaseDirectory = { + linuxPackageMappings += packageTemplateMapping( + s"/opt/$buildName/database" + )().withUser((daemonUser in Linux).value) + .withGroup((daemonGroup in Linux).value) + .withPerms("755") +} + + +lazy val databaseDirSymlink = linuxPackageSymlinks += { + LinuxSymlink(s"$targetDirectory/database", s"/opt/$buildName/database") +} lazy val scalariformPref = Def.setting { ScalariformKeys.preferences.value diff --git a/src/main/resources/hotspot.conf b/src/main/resources/hotspot.conf index b7b7ce4..eafaf39 100644 --- a/src/main/resources/hotspot.conf +++ b/src/main/resources/hotspot.conf @@ -44,7 +44,7 @@ database { webUI = true profile = "slick.jdbc.H2Profile$" db { - url = "jdbc:h2::~/:btc-hotspot-db;DB_CLOSE_DELAY=-1" + url = "jdbc:h2:./database/files:btc-hotspot-db;DB_CLOSE_DELAY=-1" driver = org.h2.Driver connectionPool = disabled keepAliveConnection = true diff --git a/src/main/scala/services/SessionServiceImpl.scala b/src/main/scala/services/SessionServiceImpl.scala index 3cc7665..476154a 100644 --- a/src/main/scala/services/SessionServiceImpl.scala +++ b/src/main/scala/services/SessionServiceImpl.scala @@ -87,12 +87,17 @@ class SessionServiceImpl(dependencies: { def disableSession(session: Session): FutureOption[Unit] = { logger.info(s"Disabling session ${session}") + val stopWatch = sessionIdToStopwatch.get(session.id).getOrElse { + throw new IllegalArgumentException(s"session ${session.id} has no stopwatch attached") + } + for { - _ <- sessionRepository.upsert(session.copy(offerId = None)) - stopWatch <- FutureOption(Future.successful(sessionIdToStopwatch.get(session.id))) + stopped <- stopWatch.stop() + upserted <- sessionRepository.upsert(session.copy(offerId = None)) orFailWith s"Error upserting session ${session.id}" } yield { - stopWatch.stop() + sessionIdToStopwatch.remove(session.id) + Some(()) } } diff --git a/src/main/scala/watchdog/StopWatch.scala b/src/main/scala/watchdog/StopWatch.scala index 4533a23..89d2265 100644 --- a/src/main/scala/watchdog/StopWatch.scala +++ b/src/main/scala/watchdog/StopWatch.scala @@ -66,6 +66,7 @@ class TimebasedStopWatch(val dependencies: { } override def stop(): Future[Unit] = { + logger.info(s"stopwatch for session ${session.id} is stopping") ipTablesService.disableClient(session.clientMac) map { ipTablesOut => // abort scheduled task if (isPending) {