Skip to content

Commit

Permalink
Adds restart support for wallet_not_responding status
Browse files Browse the repository at this point in the history
  • Loading branch information
johnalotoski committed Jul 2, 2020
1 parent 150db4f commit cec0790
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion nix/nixos/cardano-faucet-service.nix
Expand Up @@ -202,6 +202,10 @@ in {
pkgs.jq
];

security.sudo.extraConfig = ''
cardano-node ALL = NOPASSWD: /run/current-system/sw/bin/systemctl restart cardano-wallet.service
'';

environment.variables = {
CARDANO_NODE_SOCKET_PATH = config.services.cardano-node.socketPath;
};
Expand Down Expand Up @@ -329,7 +333,11 @@ in {
fi
'';

path = [ defaultPkgs.cardano-wallet-byron defaultPkgs.cardano-wallet-shelley ];
path = [
defaultPkgs.cardano-wallet-byron
defaultPkgs.cardano-wallet-shelley
pkgs.sudo
];
};
};
}
18 changes: 16 additions & 2 deletions src/cardano-module.cr
Expand Up @@ -46,8 +46,13 @@ module Cardano

def self.apiRaise(error)
begin
if JSON.parse(error) && JSON.parse(error)["message"]?
msg = JSON.parse(error)["message"]
if blob = JSON.parse(error)
code = blob["code"]? || error
msg = blob["message"]? || error
Log.debug { "Code: #{code}, message: #{msg}" }
if code.to_s =~ /^wallet_not_responding$/
restartWallet
end
else
msg = error
end
Expand All @@ -56,6 +61,15 @@ module Cardano
end
raise msg.to_s
end

def self.restartWallet
IO_CMD_OUT.clear
IO_CMD_ERR.clear
Log.debug { "Found a cardano-wallet code event requiring cardano-wallet systemd service restart -- restarting..." }
cmd = "/run/wrappers/bin/sudo /run/current-system/sw/bin/systemctl restart cardano-wallet.service"
result = Process.run(cmd, output: IO_CMD_OUT, error: IO_CMD_ERR, shell: true)
Log.debug { "Cardano-wallet restart result:\nRestart success: #{result.success?}\nSTDOUT: #{IO_CMD_OUT}\nSTDERR: #{IO_CMD_ERR}" }
end
end

class Account
Expand Down
3 changes: 3 additions & 0 deletions src/setup.cr
Expand Up @@ -34,3 +34,6 @@ MIN_METRICS_PERIOD = 10_u8

STDOUT.sync = true
Log.setup_from_env

IO_CMD_OUT = IO::Memory.new
IO_CMD_ERR = IO::Memory.new

0 comments on commit cec0790

Please sign in to comment.