1
1
Fork 0

Get inquisitor service to run

This commit is contained in:
Jaculabilis 2020-12-29 10:21:21 -08:00
parent 8865d590c3
commit 83deceef1b
2 changed files with 39 additions and 26 deletions

View File

@ -39,6 +39,7 @@
wget vimHugeX curl git htop tmux manpages wget vimHugeX curl git htop tmux manpages
zip unzip zip unzip
tinc_pre tinc_pre
python37
]; ];
# SSH config. Change passwordAuthentication if you want to log in with a password. # SSH config. Change passwordAuthentication if you want to log in with a password.

View File

@ -2,22 +2,46 @@
let let
# Import the inquisitor package # Import the inquisitor package
inquisitorSource = fetchFromGitHub { inquisitorSource = pkgs.fetchFromGitHub {
owner = "Jaculabilis"; owner = "Jaculabilis";
repo = "Inquisitor"; repo = "Inquisitor";
rev = "9001bd8f920cc120f38e998d63a8134969a00032"; rev = "9001bd8f920cc120f38e998d63a8134969a00032";
sha256 = "0nx1dszvmn6a86jhj3c9607jqy0bmijjjz3jb3v5lsnpwwkjs5w6"; sha256 = "0nx1dszvmn6a86jhj3c9607jqy0bmijjjz3jb3v5lsnpwwkjs5w6";
}; };
inquisitor = callPackage inquisitorSource {}; inquisitor = pkgs.callPackage inquisitorSource {};
# Create the inquisitor config file in the nix store # Create the inquisitor config file in the nix store
inquisitorConfig = pkgs.writeTextFile "inquisitor.conf" '' inquisitorConfig = pkgs.writeTextFile {
name = "inquisitor.conf";
text = ''
DataPath = /var/lib/inquisitor/data/ DataPath = /var/lib/inquisitor/data/
SourcePath = /var/lib/inquisitor/sources/ SourcePath = /var/lib/inquisitor/sources/
CachePath = /var/lib/inquisitor/cache/ CachePath = /var/lib/inquisitor/cache/
Verbose = false Verbose = false
LogFile = /var/log/inquisitor.log LogFile = /var/log/inquisitor.log
''; '';
};
# Create the inquisitor run script
# TODO gunicorn
inquisitorRun = pkgs.writeShellScriptBin "run.sh" ''
# Ensure inquisitor directories and inquisitor source folder
${pkgs.coreutils}/bin/mkdir -p /var/lib/inquisitor/data/inquisitor/ || exit
${pkgs.coreutils}/bin/mkdir -p /var/lib/inquisitor/sources/
${pkgs.coreutils}/bin/mkdir -p /var/lib/inquisitor/cache/
if [ ! -f /var/lib/inquisitor/data/inquisitor/state ]; then
${pkgs.coreutils}/bin/echo "{}" > /var/lib/inquisitor/data/inquisitor/state
fi
# Run inquisitor
cd /var/lib/inquisitor/
INQUISITOR_CONFIG=${inquisitorConfig} ${inquisitor}/bin/inquisitor run
'';
# Create a wrapper script to let users call into inquisitor safely
inquisitorWrapper = pkgs.writeShellScriptBin "inq" ''
INQUISITOR_CONFIG=${inquisitorConfig} ${inquisitor}/bin/inquisitor "$@"
'';
in in
{ {
# Create a user for the service # Create a user for the service
@ -27,35 +51,23 @@ in
packages = [ inquisitor ]; packages = [ inquisitor ];
}; };
# TODO replace with wrapper that sets envvar # Give all users the inq wrapper
environment.systemPackages = [ inquisitor ]; environment.systemPackages = [ inquisitorWrapper ];
# Set up the inquisitor service # Set up the inquisitor service
systemd.services.inquisitor = systemd.services.inquisitor =
let let
# Inquisitor needs some state set up to work properly
inquisitorSetup = pkgs.writeShellScriptBin "setup.sh" '' inquisitorSetup = pkgs.writeShellScriptBin "setup.sh" ''
mkdir -p /var/lib/inquisitor/data/inquisitor/ ${pkgs.coreutils}/bin/mkdir -p /var/lib/inquisitor &&
mkdir -p /var/lib/inquisitor/sources/ ${pkgs.coreutils}/bin/chown inquisitor /var/lib/inquisitor
mkdir -p /var/lib/inquisitor/cache/
echo "{}" > /var/lib/inquisitor/data/inquisitor/state
'';
# Set up server invocation
#inquisitorRun = pkgs.writeShellScriptBin "run.sh" ''
# ${pkgs.gunicorn}/bin/gunicorn
#''; TODO
inquisitorRun = pkgs.writeShellScriptBin "run.sh" ''
${inquisitor}/bin/inquisitor run
''; '';
in { in {
description = "Inquisitor server"; description = "Inquisitor server";
environment = { INQUISITOR_CONFIG = $"{inquisitorConfig}"; }; # TODO gunicorn -e script = "${inquisitorRun}/bin/run.sh";
preStart = "${inquisitorSetup}/bin/setup.sh";
script = $"${inquisitorRun}/bin/run.sh";
serviceConfig = { serviceConfig = {
User = "inquisitor"; User = "inquisitor";
Type = "simple"; Type = "simple";
WorkingDirectory = "/var/lib/inquisitor/"; ExecStartPre = "+${inquisitorSetup}/bin/setup.sh";
}; };
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network.target" ]; after = [ "network.target" ];