adds log fetch feature to agent

This commit is contained in:
Keagan McClelland
2021-02-03 19:11:46 -07:00
committed by Aiden McClelland
parent 97a85d6e01
commit 18df87b8f5
2 changed files with 12 additions and 0 deletions

View File

@@ -13,6 +13,7 @@
/v0/specs SpecsR GET
/v0/metrics MetricsR GET
/v0/logs LogsR GET
/v0/sshKeys SshKeysR GET POST
/v0/sshKeys/#Text SshKeyByFingerprintR DELETE
/v0/password PasswordR PATCH

View File

@@ -28,6 +28,11 @@ import Lib.SystemPaths hiding ( (</>) )
import Lib.Tor
import Settings
import Control.Carrier.Lift ( runM )
import System.Process
import qualified UnliftIO
import System.FileLock
import Yesod.Core.Content ( typePlain )
import Conduit
getVersionR :: Handler AppVersionRes
getVersionR = pure . AppVersionRes $ agentVersion
@@ -69,3 +74,9 @@ patchServerR = do
getGitR :: Handler Text
getGitR = pure $embedGitRevision
getLogsR :: Handler TypedContent
getLogsR = do
let debugLock = "/root/agent/tmp/debug.lock"
UnliftIO.bracket (liftIO $ lockFile debugLock Exclusive) (liftIO . unlockFile) $ const $ do
liftIO $ callCommand "journalctl -u agent --since \"1 hour ago\" > /root/agent/tmp/debug.log"
respondSource typePlain $ sourceFile "/root/agent/tmp/debug.log" .| awaitForever sendChunkBS