[Fix] tmux based systemd service
This commit is contained in:
parent
b7f6ccf8a7
commit
e18e8d1151
1 changed files with 11 additions and 12 deletions
23
flake.nix
23
flake.nix
|
|
@ -169,30 +169,29 @@
|
||||||
description = descriptionText;
|
description = descriptionText;
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
|
path = [ pkgs.tmux pkgs.bash pkgs.coreutils pkgs.systemd ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = if cfg.useTmux then "forking" else "simple";
|
||||||
User = "iota";
|
User = "iota";
|
||||||
Group = "iota";
|
Group = "iota";
|
||||||
WorkingDirectory = cfg.dataDir;
|
WorkingDirectory = cfg.dataDir;
|
||||||
|
|
||||||
ExecStart = if cfg.useTmux then
|
ExecStart = if cfg.useTmux then
|
||||||
pkgs.writeShellScript "iota-start" ''
|
pkgs.writeShellScript "iota-start" ''
|
||||||
${pkgs.tmux}/bin/tmux -S ${cfg.dataDir}/tmux.sock new-session -d -s iota '
|
${pkgs.tmux}/bin/tmux -S ${cfg.dataDir}/tmux.sock new-session -d -s iota \
|
||||||
echo "debug: starting iota..."
|
"${pkgs.bash}/bin/bash -lc 'exec > >(${pkgs.coreutils}/bin/tee -a ${cfg.dataDir}/iota-output.log >(${pkgs.systemd}/bin/systemd-cat -t iota-daemon)) 2>&1; ${cfg.package}/bin/iota; status=$?; printf \"\nProcess exited with status %s. Press any key to close this tmux session...\" \"\$status\"; read -r -n 1; exit \"\$status\"'"
|
||||||
${cfg.package}/bin/iota 2>&1 | ${pkgs.coreutils}/bin/tee ${cfg.dataDir}/iota-output.log
|
|
||||||
EXIT_CODE=$?
|
|
||||||
echo "Output saved to: ${cfg.dataDir}/iota-output.log"
|
|
||||||
echo "Press ENTER to close this session..."
|
|
||||||
read -r
|
|
||||||
'
|
|
||||||
while ${pkgs.tmux}/bin/tmux -S ${cfg.dataDir}/tmux.sock has-session -t iota 2>/dev/null; do
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
"${cfg.package}/bin/iota";
|
"${cfg.package}/bin/iota";
|
||||||
|
|
||||||
|
ExecStop = if cfg.useTmux then
|
||||||
|
(pkgs.writeShellScript "iota-stop" ''
|
||||||
|
${pkgs.tmux}/bin/tmux -S ${cfg.dataDir}/tmux.sock kill-session -t iota 2>/dev/null || true
|
||||||
|
'')
|
||||||
|
else
|
||||||
|
null;
|
||||||
|
|
||||||
ExecStartPre = [
|
ExecStartPre = [
|
||||||
("+" + pkgs.writeShellScript "iota-setup" ''
|
("+" + pkgs.writeShellScript "iota-setup" ''
|
||||||
mkdir -p ${cfg.dataDir}/certs
|
mkdir -p ${cfg.dataDir}/certs
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue