mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
should fix the logs api
This commit is contained in:
@@ -31,8 +31,6 @@ import Control.Carrier.Lift ( runM )
|
|||||||
import System.Process
|
import System.Process
|
||||||
import qualified UnliftIO
|
import qualified UnliftIO
|
||||||
import System.FileLock
|
import System.FileLock
|
||||||
import Yesod.Core.Content ( typePlain )
|
|
||||||
import Conduit
|
|
||||||
|
|
||||||
getVersionR :: Handler AppVersionRes
|
getVersionR :: Handler AppVersionRes
|
||||||
getVersionR = pure . AppVersionRes $ agentVersion
|
getVersionR = pure . AppVersionRes $ agentVersion
|
||||||
@@ -52,7 +50,8 @@ getSpecsR = handleS9ErrT $ do
|
|||||||
specsDisk <- fmap show . metricDiskSize <$> getDfMetrics
|
specsDisk <- fmap show . metricDiskSize <$> getDfMetrics
|
||||||
specsNetworkId <- lift . runM . injectFilesystemBaseFromContext settings $ getStart9AgentHostname
|
specsNetworkId <- lift . runM . injectFilesystemBaseFromContext settings $ getStart9AgentHostname
|
||||||
specsTorAddress <- lift . runM . injectFilesystemBaseFromContext settings $ getAgentHiddenServiceUrl
|
specsTorAddress <- lift . runM . injectFilesystemBaseFromContext settings $ getAgentHiddenServiceUrl
|
||||||
specsLanAddress <- fmap ( <> ".local" ) . lift . runM . injectFilesystemBaseFromContext settings $ getStart9AgentHostname
|
specsLanAddress <-
|
||||||
|
fmap (<> ".local") . lift . runM . injectFilesystemBaseFromContext settings $ getStart9AgentHostname
|
||||||
|
|
||||||
let specsAgentVersion = agentVersion
|
let specsAgentVersion = agentVersion
|
||||||
returnJsonEncoding SpecsRes { .. }
|
returnJsonEncoding SpecsRes { .. }
|
||||||
@@ -74,9 +73,9 @@ patchServerR = do
|
|||||||
getGitR :: Handler Text
|
getGitR :: Handler Text
|
||||||
getGitR = pure $embedGitRevision
|
getGitR = pure $embedGitRevision
|
||||||
|
|
||||||
getLogsR :: Handler TypedContent
|
getLogsR :: Handler (JSONResponse [Text])
|
||||||
getLogsR = do
|
getLogsR = do
|
||||||
let debugLock = "/root/agent/tmp/debug.lock"
|
let debugLock = "/root/agent/tmp/debug.lock"
|
||||||
UnliftIO.bracket (liftIO $ lockFile debugLock Exclusive) (liftIO . unlockFile) $ const $ do
|
UnliftIO.bracket (liftIO $ lockFile debugLock Exclusive) (liftIO . unlockFile) $ const $ do
|
||||||
liftIO $ callCommand "journalctl -u agent --since \"1 hour ago\" > /root/agent/tmp/debug.log"
|
liftIO $ callCommand "journalctl -u agent --since \"1 hour ago\" > /root/agent/tmp/debug.log"
|
||||||
respondSource typePlain $ sourceFile "/root/agent/tmp/debug.log" .| awaitForever sendChunkBS
|
liftIO $ JSONResponse . lines <$> readFile "/root/agent/tmp/debug.log"
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ export abstract class ApiService {
|
|||||||
abstract getAppMetrics (appId: string): Promise<AppMetrics>
|
abstract getAppMetrics (appId: string): Promise<AppMetrics>
|
||||||
abstract getInstalledApps (): Promise<AppInstalledPreview[]>
|
abstract getInstalledApps (): Promise<AppInstalledPreview[]>
|
||||||
abstract getExternalDisks (): Promise<DiskInfo[]>
|
abstract getExternalDisks (): Promise<DiskInfo[]>
|
||||||
abstract getAppConfig (appId: string): Promise<{ spec: ConfigSpec, config: object, rules: Rules[]}>
|
abstract getAppConfig (appId: string): Promise<{ spec: ConfigSpec, config: object, rules: Rules[] }>
|
||||||
abstract getAppLogs (appId: string, params?: ReqRes.GetAppLogsReq): Promise<string[]>
|
abstract getAppLogs (appId: string, params?: ReqRes.GetAppLogsReq): Promise<string[]>
|
||||||
abstract getServerLogs (): Promise<string>
|
abstract getServerLogs (): Promise<string[]>
|
||||||
abstract installApp (appId: string, version: string, dryRun?: boolean): Promise<AppInstalledFull & { breakages: DependentBreakage[] } >
|
abstract installApp (appId: string, version: string, dryRun?: boolean): Promise<AppInstalledFull & { breakages: DependentBreakage[] }>
|
||||||
abstract uninstallApp (appId: string, dryRun?: boolean): Promise<{ breakages: DependentBreakage[] }>
|
abstract uninstallApp (appId: string, dryRun?: boolean): Promise<{ breakages: DependentBreakage[] }>
|
||||||
abstract startApp (appId: string): Promise<Unit>
|
abstract startApp (appId: string): Promise<Unit>
|
||||||
abstract stopApp (appId: string, dryRun?: boolean): Promise<{ breakages: DependentBreakage[] }>
|
abstract stopApp (appId: string, dryRun?: boolean): Promise<{ breakages: DependentBreakage[] }>
|
||||||
@@ -51,7 +51,7 @@ export abstract class ApiService {
|
|||||||
abstract restoreAppBackup (appId: string, logicalname: string, password?: string): Promise<Unit>
|
abstract restoreAppBackup (appId: string, logicalname: string, password?: string): Promise<Unit>
|
||||||
abstract stopAppBackup (appId: string): Promise<Unit>
|
abstract stopAppBackup (appId: string): Promise<Unit>
|
||||||
abstract patchAppConfig (app: AppInstalledPreview, config: object, dryRun?: boolean): Promise<{ breakages: DependentBreakage[] }>
|
abstract patchAppConfig (app: AppInstalledPreview, config: object, dryRun?: boolean): Promise<{ breakages: DependentBreakage[] }>
|
||||||
abstract postConfigureDependency (dependencyId: string, dependentId: string, dryRun?: boolean): Promise< { config: object, breakages: DependentBreakage[] }>
|
abstract postConfigureDependency (dependencyId: string, dependentId: string, dryRun?: boolean): Promise<{ config: object, breakages: DependentBreakage[] }>
|
||||||
abstract patchServerConfig (attr: string, value: any): Promise<Unit>
|
abstract patchServerConfig (attr: string, value: any): Promise<Unit>
|
||||||
abstract wipeAppData (app: AppInstalledPreview): Promise<Unit>
|
abstract wipeAppData (app: AppInstalledPreview): Promise<Unit>
|
||||||
abstract addSSHKey (sshKey: string): Promise<Unit>
|
abstract addSSHKey (sshKey: string): Promise<Unit>
|
||||||
@@ -66,11 +66,11 @@ export abstract class ApiService {
|
|||||||
abstract refreshLAN (): Promise<Unit>
|
abstract refreshLAN (): Promise<Unit>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isRpcFailure<Error, Result> (arg: { error: Error } | { result: Result}): arg is { error: Error } {
|
export function isRpcFailure<Error, Result> (arg: { error: Error } | { result: Result }): arg is { error: Error } {
|
||||||
return !!(arg as any).error
|
return !!(arg as any).error
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isRpcSuccess<Error, Result> (arg: { error: Error } | { result: Result}): arg is { result: Result } {
|
export function isRpcSuccess<Error, Result> (arg: { error: Error } | { result: Result }): arg is { result: Result } {
|
||||||
return !!(arg as any).result
|
return !!(arg as any).result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ export module ReqRes {
|
|||||||
export type ServiceActionResponse = {
|
export type ServiceActionResponse = {
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
id: string
|
id: string
|
||||||
} & ({ error: { code: number, message: string } } | { result : string })
|
} & ({ error: { code: number, message: string } } | { result: string })
|
||||||
export type GetCheckAuthRes = { }
|
export type GetCheckAuthRes = { }
|
||||||
export type GetServerRes = ApiServer
|
export type GetServerRes = ApiServer
|
||||||
export type GetVersionLatestRes = { versionLatest: string, releaseNotes: string }
|
export type GetVersionLatestRes = { versionLatest: string, releaseNotes: string }
|
||||||
@@ -100,7 +100,7 @@ export module ReqRes {
|
|||||||
export type GetAppLogsReq = { after?: string, before?: string, page?: string, perPage?: string }
|
export type GetAppLogsReq = { after?: string, before?: string, page?: string, perPage?: string }
|
||||||
export type GetServerLogsReq = { }
|
export type GetServerLogsReq = { }
|
||||||
export type GetAppLogsRes = string[]
|
export type GetAppLogsRes = string[]
|
||||||
export type GetServerLogsRes = string
|
export type GetServerLogsRes = string[]
|
||||||
export type GetAppMetricsRes = AppMetricsVersioned<number>
|
export type GetAppMetricsRes = AppMetricsVersioned<number>
|
||||||
export type GetAppsInstalledRes = AppInstalledPreview[]
|
export type GetAppsInstalledRes = AppInstalledPreview[]
|
||||||
export type PostInstallAppReq = { version: string }
|
export type PostInstallAppReq = { version: string }
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export class LiveApiService extends ApiService {
|
|||||||
return this.authRequest<ReqRes.GetAppLogsRes>({ method: Method.GET, url: `/apps/${appId}/logs`, params: params as any })
|
return this.authRequest<ReqRes.GetAppLogsRes>({ method: Method.GET, url: `/apps/${appId}/logs`, params: params as any })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getServerLogs(): Promise<string> {
|
async getServerLogs(): Promise<string[]> {
|
||||||
return this.authRequest<ReqRes.GetServerLogsRes>({ method: Method.GET, url: `/logs` })
|
return this.authRequest<ReqRes.GetServerLogsRes>({ method: Method.GET, url: `/logs` })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user