Stirling-PDF/src/main/java/stirling/software/SPDF/config/PostStartupProcesses.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.5 KiB
Java
Raw Normal View History

2024-01-09 22:39:21 +00:00
package stirling.software.SPDF.config;
import java.io.IOException;
2024-01-10 00:37:55 +00:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
2024-01-09 22:39:21 +00:00
2024-01-10 00:37:55 +00:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2024-01-09 22:39:21 +00:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import jakarta.annotation.PostConstruct;
import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.utils.ProcessExecutor;
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
@Component
public class PostStartupProcesses {
@Autowired ApplicationProperties applicationProperties;
@Autowired
@Qualifier("RunningInDocker")
private boolean runningInDocker;
@Autowired
@Qualifier("bookFormatsInstalled")
private boolean bookFormatsInstalled;
@Autowired
@Qualifier("htmlFormatsInstalled")
private boolean htmlFormatsInstalled;
2024-01-10 00:37:55 +00:00
private static final Logger logger = LoggerFactory.getLogger(PostStartupProcesses.class);
2024-01-09 22:39:21 +00:00
@PostConstruct
public void runInstallCommandBasedOnEnvironment() throws IOException, InterruptedException {
List<List<String>> commands = new ArrayList<>();
// Checking for DOCKER_INSTALL_BOOK_FORMATS environment variable
if (bookFormatsInstalled) {
List<String> tmpList = new ArrayList<>();
tmpList = new ArrayList<>();
2024-02-09 23:24:25 +00:00
tmpList.addAll(Arrays.asList("whoami"));
2024-01-09 22:39:21 +00:00
commands.add(tmpList);
2024-02-09 23:24:25 +00:00
tmpList = new ArrayList<>();
tmpList.addAll(Arrays.asList("id"));
2024-01-09 22:39:21 +00:00
commands.add(tmpList);
}
if (!commands.isEmpty()) {
// Run the command
if (runningInDocker) {
List<String> tmpList = new ArrayList<>();
for (List<String> list : commands) {
ProcessExecutorResult returnCode =
ProcessExecutor.getInstance(ProcessExecutor.Processes.INSTALL_APP, true)
.runCommandWithOutputHandling(list);
2024-01-10 00:37:55 +00:00
logger.info("RC for app installs {}", returnCode.getRc());
2024-01-09 22:39:21 +00:00
}
} else {
2024-01-10 00:37:55 +00:00
logger.info(
"Not running inside Docker so skipping automated install process with command.");
2024-01-09 22:39:21 +00:00
}
} else {
if (runningInDocker) {
2024-01-10 00:37:55 +00:00
logger.info("No custom apps to install.");
2024-01-09 22:39:21 +00:00
}
}
}
}