Skip to content

Commit

Permalink
Revert "fix(radiusd): reimplement restart and reload"
Browse files Browse the repository at this point in the history
This reverts commit 4313214.
  • Loading branch information
amphineko committed Jan 28, 2024
1 parent 4313214 commit 35dbafe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 73 deletions.
5 changes: 0 additions & 5 deletions packages/supervisor/src/api/radiusd.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,4 @@ export class RadiusdController {
async reload(): Promise<void> {
await this.radiusd.reload()
}

@Post("/restart")
async restart(): Promise<void> {
await this.radiusd.restart()
}
}
23 changes: 1 addition & 22 deletions packages/supervisor/src/radiusd/radiusd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ class Process {
})

child.on("error", (error: Error | string) => {
if (this._process == child) {
this._lastExitCode = -1
this._process = null
}

this.logError(`Cannot spawn process ${this.executable}: ${error.toString()}`)
process.nextTick(() => this.autoRestart())
})
Expand All @@ -89,7 +84,7 @@ class Process {
}

this.logInfo(`Process ${this.executable} exited with code ${code} and signal ${signal}`)
process.nextTick(() => this.autoRestart())
this.autoRestart()
})

child.on("spawn", () => {
Expand Down Expand Up @@ -120,17 +115,6 @@ class Process {
return child
}

signal(signal: NodeJS.Signals): Promise<void> {
if (this._process) {
this._process.kill(signal)
return Promise.resolve()
} else {
const message = `Cannot send signal ${signal} to radiusd: not started`
this.logError(message)
return Promise.reject(new Error(message))
}
}

start(): Promise<void> {
this._lastRestart = null
this._restartEnabled = true
Expand Down Expand Up @@ -223,11 +207,6 @@ export class Radiusd {
}

async reload(): Promise<void> {
await this._regenerateFiles()
await this._process.signal("SIGHUP")
}

async restart(): Promise<void> {
await this.stop()
await this.start()
}
Expand Down
6 changes: 1 addition & 5 deletions packages/web/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ export async function getStatus(): Promise<GetStatusResponse> {
return await getTypedEndpoint(GetStatusResponseType, "api/v1/radiusd/status")
}

export async function reloadRadiusd(): Promise<void> {
export async function reload(): Promise<void> {
await postTypedEndpoint(t.any, t.any, "api/v1/radiusd/reload", null)
}

export async function restartRadiusd(): Promise<void> {
await postTypedEndpoint(t.any, t.any, "api/v1/radiusd/restart", null)
}
60 changes: 19 additions & 41 deletions packages/web/app/clientLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Lock,
Notes,
Password,
PowerSettingsNew,
Refresh,
StopCircle,
SvgIconComponent,
Expand All @@ -29,10 +28,10 @@ import CssBaseline from "@mui/material/CssBaseline"
import { ThemeProvider, createTheme } from "@mui/material/styles"
import Link from "next/link"
import { usePathname, useRouter } from "next/navigation"
import { ReactNode, useCallback, useEffect, useMemo, useState } from "react"
import { ReactNode, useEffect, useMemo, useState } from "react"
import { QueryClient, QueryClientProvider, useMutation, useQuery, useQueryClient } from "react-query"

import { getStatus, reloadRadiusd, restartRadiusd } from "./actions"
import { reload as doReload, getStatus } from "./actions"

const queryClient = new QueryClient()

Expand All @@ -50,48 +49,27 @@ function humanize(seconds: number) {
}
}

function RadiusdMenu(): JSX.Element {
function ReloadButton(): JSX.Element {
const queryClient = useQueryClient()
const onSuccess = useCallback(async () => {
await queryClient.invalidateQueries(["index", "radiusd", "status"])
}, [queryClient])

const { mutate: mutateReload } = useMutation({
mutationFn: reloadRadiusd,
const { mutate: reload } = useMutation({
mutationFn: doReload,
mutationKey: ["index", "radiusd", "reload"],
onSuccess,
})

const { mutate: mutateRestart } = useMutation({
mutationFn: restartRadiusd,
mutationKey: ["index", "radiusd", "restart"],
onSuccess,
onSuccess: async () => {
await queryClient.invalidateQueries(["index", "radiusd", "status"])
},
})

return (
<Box>
<IconButton
color="inherit"
onClick={() => {
mutateReload()
}}
>
<Tooltip title="Reload">
<Refresh />
</Tooltip>
</IconButton>

<IconButton
color="inherit"
onClick={() => {
mutateRestart()
}}
>
<Tooltip title="Restart">
<PowerSettingsNew />
</Tooltip>
</IconButton>
</Box>
<IconButton
color="inherit"
onClick={() => {
reload()
}}
>
<Tooltip title="Reload">
<Refresh />
</Tooltip>
</IconButton>
)
}

Expand Down Expand Up @@ -221,7 +199,7 @@ export function RootClientLayout({ children }: { children: React.ReactNode }): J
</FlexBox>
<FlexBox key="status" sx={{ alignItems: "center", gap: "0.5em" }}>
<StatusChip />
<RadiusdMenu />
<ReloadButton />
</FlexBox>
</Toolbar>
</AppBar>
Expand Down

0 comments on commit 35dbafe

Please sign in to comment.