mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-21 23:08:46 +08:00
fix: Fix the restart panel exception (#8088)
This commit is contained in:
parent
dd66622be1
commit
f80dffd908
11 changed files with 90 additions and 26 deletions
|
|
@ -137,3 +137,24 @@ func (b *BaseApi) LoadDashboardCurrentInfo(c *gin.Context) {
|
||||||
data := dashboardService.LoadCurrentInfo(ioOption, netOption)
|
data := dashboardService.LoadCurrentInfo(ioOption, netOption)
|
||||||
helper.SuccessWithData(c, data)
|
helper.SuccessWithData(c, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Tags Dashboard
|
||||||
|
// @Summary System restart
|
||||||
|
// @Accept json
|
||||||
|
// @Param operation path string true "request"
|
||||||
|
// @Success 200
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @Security Timestamp
|
||||||
|
// @Router /dashboard/system/restart/:operation [post]
|
||||||
|
func (b *BaseApi) SystemRestart(c *gin.Context) {
|
||||||
|
operation, ok := c.Params.Get("operation")
|
||||||
|
if !ok {
|
||||||
|
helper.BadRequest(c, errors.New("error operation in path"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := dashboardService.Restart(operation); err != nil {
|
||||||
|
helper.InternalServer(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
helper.SuccessWithOutData(c)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,9 @@ func (u *AIToolService) Create(req dto.OllamaModelName) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, nil)
|
}, nil)
|
||||||
_ = taskItem.Execute()
|
if err := taskItem.Execute(); err != nil {
|
||||||
|
_ = aiRepo.Update(info.ID, map[string]interface{}{"status": constant.StatusFailed, "message": err.Error()})
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
network "net"
|
network "net"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -38,6 +39,7 @@ type IDashboardService interface {
|
||||||
|
|
||||||
LoadAppLauncher() ([]dto.AppLauncher, error)
|
LoadAppLauncher() ([]dto.AppLauncher, error)
|
||||||
ListLauncherOption(filter string) ([]dto.LauncherOption, error)
|
ListLauncherOption(filter string) ([]dto.LauncherOption, error)
|
||||||
|
Restart(operation string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIDashboardService() IDashboardService {
|
func NewIDashboardService() IDashboardService {
|
||||||
|
|
@ -52,6 +54,26 @@ func (u *DashboardService) Sync(req []dto.AppLauncherSync) error {
|
||||||
return launcherRepo.SyncAll(launchers)
|
return launcherRepo.SyncAll(launchers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *DashboardService) Restart(operation string) error {
|
||||||
|
if operation != "1panel" && operation != "system" && operation != "1panel-agent" {
|
||||||
|
return fmt.Errorf("handle restart operation %s failed, err: nonsupport such operation", operation)
|
||||||
|
}
|
||||||
|
itemCmd := fmt.Sprintf("%s systemctl restart 1panel-agent.service && %s systemctl restart 1panel-core.service", cmd.SudoHandleCmd(), cmd.SudoHandleCmd())
|
||||||
|
if operation == "system" {
|
||||||
|
itemCmd = fmt.Sprintf("%s reboot", cmd.SudoHandleCmd())
|
||||||
|
}
|
||||||
|
if operation == "1panel-agent" {
|
||||||
|
itemCmd = fmt.Sprintf("%s systemctl restart 1panel-agent.service", cmd.SudoHandleCmd())
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
stdout, err := cmd.Exec(itemCmd)
|
||||||
|
if err != nil {
|
||||||
|
global.LOG.Errorf("handle %s failed, err: %v", itemCmd, stdout)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (u *DashboardService) LoadOsInfo() (*dto.OsInfo, error) {
|
func (u *DashboardService) LoadOsInfo() (*dto.OsInfo, error) {
|
||||||
var baseInfo dto.OsInfo
|
var baseInfo dto.OsInfo
|
||||||
hostInfo, err := host.Info()
|
hostInfo, err := host.Info()
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,6 @@ func (s *DashboardRouter) InitRouter(Router *gin.RouterGroup) {
|
||||||
cmdRouter.GET("/base/:ioOption/:netOption", baseApi.LoadDashboardBaseInfo)
|
cmdRouter.GET("/base/:ioOption/:netOption", baseApi.LoadDashboardBaseInfo)
|
||||||
cmdRouter.GET("/current/node", baseApi.LoadCurrentInfoForNode)
|
cmdRouter.GET("/current/node", baseApi.LoadCurrentInfoForNode)
|
||||||
cmdRouter.GET("/current/:ioOption/:netOption", baseApi.LoadDashboardCurrentInfo)
|
cmdRouter.GET("/current/:ioOption/:netOption", baseApi.LoadDashboardCurrentInfo)
|
||||||
|
cmdRouter.POST("/system/restart/:operation", baseApi.SystemRestart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,8 +136,13 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
|
||||||
|
|
||||||
global.LOG.Info("backup original data successful, now start to upgrade!")
|
global.LOG.Info("backup original data successful, now start to upgrade!")
|
||||||
|
|
||||||
if err := files.CopyItem(false, true, path.Join(tmpDir, "1panel*"), "/usr/local/bin"); err != nil {
|
if err := files.CopyItem(false, true, path.Join(tmpDir, "1panel-core"), "/usr/local/bin"); err != nil {
|
||||||
global.LOG.Errorf("upgrade 1panel failed, err: %v", err)
|
global.LOG.Errorf("upgrade 1panel-core failed, err: %v", err)
|
||||||
|
u.handleRollback(originalDir, 1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := files.CopyItem(false, true, path.Join(tmpDir, "1panel-agent"), "/usr/local/bin"); err != nil {
|
||||||
|
global.LOG.Errorf("upgrade 1panel-agent failed, err: %v", err)
|
||||||
u.handleRollback(originalDir, 1)
|
u.handleRollback(originalDir, 1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ var WebUrlMap = map[string]struct{}{
|
||||||
"/ai/gpu": {},
|
"/ai/gpu": {},
|
||||||
|
|
||||||
"/containers": {},
|
"/containers": {},
|
||||||
|
"/containers/container/operate": {},
|
||||||
"/containers/container": {},
|
"/containers/container": {},
|
||||||
"/containers/image": {},
|
"/containers/image": {},
|
||||||
"/containers/network": {},
|
"/containers/network": {},
|
||||||
|
|
@ -148,7 +149,6 @@ var WebUrlMap = map[string]struct{}{
|
||||||
}
|
}
|
||||||
|
|
||||||
var DynamicRoutes = []string{
|
var DynamicRoutes = []string{
|
||||||
`^/containers/container/operate/[^?]+$`,
|
|
||||||
`^/containers/composeDetail/[^/]+$`,
|
`^/containers/composeDetail/[^/]+$`,
|
||||||
`^/databases/mysql/setting/[^/]+/[^/]+$`,
|
`^/databases/mysql/setting/[^/]+/[^/]+$`,
|
||||||
`^/databases/postgresql/setting/[^/]+/[^/]+$`,
|
`^/databases/postgresql/setting/[^/]+/[^/]+$`,
|
||||||
|
|
|
||||||
|
|
@ -77,19 +77,30 @@ const acceptParams = (props: WsProps) => {
|
||||||
const newTerm = () => {
|
const newTerm = () => {
|
||||||
const background = getComputedStyle(document.documentElement).getPropertyValue('--panel-terminal-bg-color').trim();
|
const background = getComputedStyle(document.documentElement).getPropertyValue('--panel-terminal-bg-color').trim();
|
||||||
term.value = new Terminal({
|
term.value = new Terminal({
|
||||||
lineHeight: 1.2,
|
lineHeight: terminalStore.lineHeight || 1.2,
|
||||||
fontSize: 12,
|
fontSize: terminalStore.fontSize || 12,
|
||||||
fontFamily: "Monaco, Menlo, Consolas, 'Courier New', monospace",
|
fontFamily: "Monaco, Menlo, Consolas, 'Courier New', monospace",
|
||||||
theme: {
|
theme: {
|
||||||
background: background,
|
background: background,
|
||||||
},
|
},
|
||||||
cursorBlink: true,
|
cursorBlink: terminalStore.cursorBlink ? terminalStore.cursorBlink === 'Enable' : true,
|
||||||
cursorStyle: 'underline',
|
cursorStyle: terminalStore.cursorStyle ? getStyle() : 'underline',
|
||||||
scrollback: 1000,
|
scrollback: terminalStore.scrollback || 1000,
|
||||||
scrollSensitivity: 15,
|
scrollSensitivity: terminalStore.scrollSensitivity || 15,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getStyle = (): 'underline' | 'block' | 'bar' => {
|
||||||
|
switch (terminalStore.cursorStyle) {
|
||||||
|
case 'bar':
|
||||||
|
return 'bar';
|
||||||
|
case 'block':
|
||||||
|
return 'block';
|
||||||
|
default:
|
||||||
|
return 'underline';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const init = (endpoint: string, args: string) => {
|
const init = (endpoint: string, args: string) => {
|
||||||
if (initTerminal(true)) {
|
if (initTerminal(true)) {
|
||||||
initWebSocket(endpoint, args);
|
initWebSocket(endpoint, args);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import { GlobalStore, MenuStore, TabsStore } from '@/store';
|
||||||
import { DeviceType } from '@/enums/app';
|
import { DeviceType } from '@/enums/app';
|
||||||
import { getSystemAvailable } from '@/api/modules/setting';
|
import { getSystemAvailable } from '@/api/modules/setting';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { loadMasterProductProFromDB, loadProductProFromDB, getXpackSettingForTheme } from '@/utils/xpack';
|
import { loadMasterProductProFromDB, loadProductProFromDB } from '@/utils/xpack';
|
||||||
import { useTheme } from '@/global/use-theme';
|
import { useTheme } from '@/global/use-theme';
|
||||||
import TaskList from '@/components/task-list/index.vue';
|
import TaskList from '@/components/task-list/index.vue';
|
||||||
const { switchTheme } = useTheme();
|
const { switchTheme } = useTheme();
|
||||||
|
|
@ -108,7 +108,6 @@ onMounted(() => {
|
||||||
loadStatus();
|
loadStatus();
|
||||||
loadProductProFromDB();
|
loadProductProFromDB();
|
||||||
loadMasterProductProFromDB();
|
loadMasterProductProFromDB();
|
||||||
getXpackSettingForTheme();
|
|
||||||
globalStore.isFullScreen = false;
|
globalStore.isFullScreen = false;
|
||||||
|
|
||||||
const mqList = window.matchMedia('(prefers-color-scheme: dark)');
|
const mqList = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ const loadDataFromDB = async () => {
|
||||||
const res = await getSettingInfo();
|
const res = await getSettingInfo();
|
||||||
document.title = res.data.panelName;
|
document.title = res.data.panelName;
|
||||||
globalStore.entrance = res.data.securityEntrance;
|
globalStore.entrance = res.data.securityEntrance;
|
||||||
globalStore.setOpenMenuTabs(res.data.menuTabs === 'enable');
|
globalStore.setOpenMenuTabs(res.data.menuTabs === 'Enable');
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function loadProductProFromDB() {
|
export async function loadProductProFromDB() {
|
||||||
|
|
@ -72,7 +72,6 @@ export async function loadProductProFromDB() {
|
||||||
globalStore.productProExpires = Number(res.data.productPro);
|
globalStore.productProExpires = Number(res.data.productPro);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadDataFromDB();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadMasterProductProFromDB() {
|
export async function loadMasterProductProFromDB() {
|
||||||
|
|
@ -84,6 +83,7 @@ export async function loadMasterProductProFromDB() {
|
||||||
}
|
}
|
||||||
switchTheme();
|
switchTheme();
|
||||||
initFavicon();
|
initFavicon();
|
||||||
|
loadDataFromDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getXpackSettingForTheme() {
|
export async function getXpackSettingForTheme() {
|
||||||
|
|
|
||||||
|
|
@ -58,12 +58,12 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!row.expand && row.sourceAccounts.length > 3">
|
<div v-if="!row.expand && row.sourceAccounts?.length > 3">
|
||||||
<el-button type="primary" link @click="row.expand = true">
|
<el-button type="primary" link @click="row.expand = true">
|
||||||
{{ $t('commons.button.expand') }}...
|
{{ $t('commons.button.expand') }}...
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="row.expand && row.sourceAccounts.length > 3">
|
<div v-if="row.expand && row.sourceAccounts?.length > 3">
|
||||||
<el-button type="primary" link @click="row.expand = false">
|
<el-button type="primary" link @click="row.expand = false">
|
||||||
{{ $t('commons.button.collapse') }}
|
{{ $t('commons.button.collapse') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ const confirmDialogRef = ref();
|
||||||
const globalStore = GlobalStore();
|
const globalStore = GlobalStore();
|
||||||
|
|
||||||
const onRestart = (type: string) => {
|
const onRestart = (type: string) => {
|
||||||
|
if (globalStore.currentNode != 'local' && type === '1panel') {
|
||||||
|
type = '1panel-agent';
|
||||||
|
}
|
||||||
restartType.value = type;
|
restartType.value = type;
|
||||||
let params = {
|
let params = {
|
||||||
header: i18n.global.t('home.restart_' + type),
|
header: i18n.global.t('home.restart_' + type),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue