Introduced StartWithBackend plugin
Change-Id: I3cbeaf9b44727637de7844966f964ac3488ede52
diff --git a/.gitignore b/.gitignore
index 910a8e6..cb2151b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@
/pm_to_blib
/t/kalamar_user_client.t
\#*
+adminToken
*.tar.gz
*~
*.sqlite
diff --git a/Changes b/Changes
index 8e24d05..faad100 100755
--- a/Changes
+++ b/Changes
@@ -14,6 +14,7 @@
- Add panel types. (diewald)
- Add textSigle as a plugin receivable information. (diewald)
- Introduce krill-indexer command via plugin. (diewald)
+ - Introduce start-with-backend command via plugin. (diewald)
0.47 2022-11-22
- Add command to generate super_client_info file. (diewald)
diff --git a/lib/Kalamar/Plugin/StartWithBackend.pm b/lib/Kalamar/Plugin/StartWithBackend.pm
new file mode 100644
index 0000000..5202a0b
--- /dev/null
+++ b/lib/Kalamar/Plugin/StartWithBackend.pm
@@ -0,0 +1,18 @@
+package Kalamar::Plugin::StartWithBackend;
+use Mojo::Base 'Mojolicious::Plugin';
+use Mojo::Base -strict;
+
+sub register {
+ my ($plugin, $mojo) = @_;
+ my $java = `sh -c 'command -v java'`;
+ chomp $java;
+ if ($java eq '') {
+ warn('No java executable found in PATH. ' . __PACKAGE__ . ' requires a JVM.');
+ return 0;
+ };
+ # Add additional command path
+ push(@{$mojo->commands->namespaces}, __PACKAGE__);
+ return 1;
+};
+
+1;
diff --git a/lib/Kalamar/Plugin/StartWithBackend/start_with_backend.pm b/lib/Kalamar/Plugin/StartWithBackend/start_with_backend.pm
new file mode 100644
index 0000000..af55d8b
--- /dev/null
+++ b/lib/Kalamar/Plugin/StartWithBackend/start_with_backend.pm
@@ -0,0 +1,26 @@
+package Kalamar::Plugin::StartWithBackend::start_with_backend;
+use Mojo::Base 'Mojolicious::Command';
+use Mojolicious::Command::daemon;
+
+has description => 'Start Kalamar and the Kustvakt service';
+has usage => sub {
+ my $kustvakt = $ENV{KUSTVAKT_PATH};
+ return "\n" . qx{java -jar $kustvakt --help} if $kustvakt;
+ return "\nThe jar file for Kustvakt can be set using\n" .
+ "the environment variable KUSTVAKT_PATH\n";
+};
+
+sub run {
+ my $kustvakt = $ENV{KUSTVAKT_PATH};
+ unless ($kustvakt) {
+ warn 'KUSTVAKT_PATH not set';
+ return 0;
+ };
+
+ system("java -jar $kustvakt &");
+
+ Mojolicious::Command::daemon::build_server(@_)->run;
+ return 1;
+};
+
+1;