From 47560ba21c70c0b9c400473ce60de4dd5858b2b6 Mon Sep 17 00:00:00 2001 From: Darren Satkunas Date: Thu, 8 Dec 2022 06:51:10 -0800 Subject: [PATCH 1/5] feature(admin(js,vue)): add system service button, add rsyslog system service button to syslog forwarders, fixes #6532 --- .../new/BaseButtonSystemService.vue | 227 ++++++++++++++++++ .../root/src/components/new/index.js | 2 + .../root/src/store/modules/cluster.js | 93 ++++++- .../_components/AlertServices.vue | 42 ++++ .../syslogForwarders/_components/TheView.js | 27 ++- .../syslogForwarders/_components/index.js | 2 + .../_components/BaseSystemService.vue | 158 ++++++++++++ 7 files changed, 537 insertions(+), 14 deletions(-) create mode 100644 html/pfappserver/root/src/components/new/BaseButtonSystemService.vue create mode 100644 html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/AlertServices.vue create mode 100644 html/pfappserver/root/src/views/Status/services/_components/BaseSystemService.vue diff --git a/html/pfappserver/root/src/components/new/BaseButtonSystemService.vue b/html/pfappserver/root/src/components/new/BaseButtonSystemService.vue new file mode 100644 index 000000000000..508992fe124a --- /dev/null +++ b/html/pfappserver/root/src/components/new/BaseButtonSystemService.vue @@ -0,0 +1,227 @@ + + diff --git a/html/pfappserver/root/src/components/new/index.js b/html/pfappserver/root/src/components/new/index.js index 0b893f4359d2..e3ebc55a7a05 100644 --- a/html/pfappserver/root/src/components/new/index.js +++ b/html/pfappserver/root/src/components/new/index.js @@ -6,6 +6,7 @@ import BaseButtonRefresh from './BaseButtonRefresh' import BaseButtonSave from './BaseButtonSave' import BaseButtonSaveSearch from './BaseButtonSaveSearch' import BaseButtonService from './BaseButtonService' +import BaseButtonSystemService from './BaseButtonSystemService' import BaseButtonUpload from './BaseButtonUpload' import BaseContainerLoading from './BaseContainerLoading' import BaseCsvImport from './BaseCsvImport' @@ -150,6 +151,7 @@ export { BaseButtonSave, BaseButtonSaveSearch, BaseButtonService, + BaseButtonSystemService, BaseButtonUpload, // containers diff --git a/html/pfappserver/root/src/store/modules/cluster.js b/html/pfappserver/root/src/store/modules/cluster.js index 9839049161b3..af8f22c33b25 100644 --- a/html/pfappserver/root/src/store/modules/cluster.js +++ b/html/pfappserver/root/src/store/modules/cluster.js @@ -106,6 +106,17 @@ const api = (state, server = store.state.system.hostname) => { }) }) }, + systemService: id => { + return apiCall.getQuiet(['system_service', id, 'status'], { headers }).then(response => { + return response.data + }).catch(error => { + // 500 response error w/ not running + if (error.response && (!['ERR_BAD_RESPONSE'].includes(error.code) || ![500].includes(error.response.status))) { + throw error + } + return error.response.data + }) + }, restartSystem: id => { return apiCall.postQuiet(['system_service', id, 'restart'], { async: true }, { headers }) .then(response => { @@ -196,6 +207,33 @@ const getters = { } }, sorted) }, {}) + }, + systemServicesByServer: state => { + return Object.entries(state.servers).reduce((sorted, [server, {system_services = {}}]) => { + return Object.entries(system_services).reduce((sorted, [id, service]) => { + return { + ...sorted, + [id]: { + servers: { + ...((id in sorted) ? sorted[id].servers : {} ), + [server]: { + ...service, + isDisabling: service.status === types.DISABLING, + isEnabling: service.status === types.ENABLING, + isRestarting: service.status === types.RESTARTING, + isStarting: service.status === types.STARTING, + isStopping: service.status === types.STOPPING, + } + }, + hasAlive: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && service.alive && service.pid) > -1, + hasDead: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && !(service.alive || service.pid)) > -1, + hasEnabled: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && service.enabled) > -1, + hasDisabled: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && !service.enabled) > -1, + isProtected: !!protectedServices.find(listed => listed === id), + } + } + }, sorted) + }, {}) } } @@ -471,42 +509,68 @@ const actions = { }) }, - restartSystemService: ({ state, commit }, { id, server = store.state.system.hostname }) => { + getSystemService: ({ state, commit }, { server, id }) => { + commit('SYSTEM_SERVICE_REQUEST', { server, id }) + return api(state, server).systemService(id).then(service => { + commit('SYSTEM_SERVICE_SUCCESS', { server, id, service }) + return state.servers[server].services[id] + }).catch(err => { + const { response: { data: { message: error } = {} } = {} } = err + commit('SYSTEM_SERVICE_ERROR', { server, id, error }) + throw err + }) + }, + getSystemServiceCluster: ({ state, dispatch }, id) => { + return dispatch('getConfig').then(() => { + let promises = [] + Object.keys(state.servers).map(server => { + promises.push(dispatch('getSystemService', { server, id })) + }) + return Promise.all(promises).then(servers => { + return servers.reduce((assoc, service, index) => { + const server = Object.keys(state.servers)[index] + return { ...assoc, [server]: state.servers[server].system_services[id] } + }, {}) + }) + }) + }, + restartSystemService: ({ state, commit, dispatch }, { id, server = store.state.system.hostname }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) commit('SYSTEM_SERVICE_RESTARTING', { server, id }) return api(state, server).restartSystem(id).then(response => { commit('SYSTEM_SERVICE_RESTARTED', { server, id, response }) - return state.servers[server].services[id] + return state.servers[server].system_services[id] }).catch(err => { const { response: { data: error } = {} } = err commit('SYSTEM_SERVICE_ERROR', { server, id, error }) throw err - }) + }).finally(() => dispatch('getSystemService', { server, id })) }, - startSystemService: ({ state, commit }, { id, server = store.state.system.hostname }) => { + startSystemService: ({ state, commit, dispatch }, { id, server = store.state.system.hostname }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) commit('SYSTEM_SERVICE_STARTING', { server, id }) return api(state, server).startSystem(id).then(response => { commit('SYSTEM_SERVICE_STARTED', { server, id, response }) - return state.servers[server].services[id] + return state.servers[server].system_services[id] }).catch(err => { const { response: { data: error } = {} } = err commit('SYSTEM_SERVICE_ERROR', { server, id, error }) throw err - }) + }).finally(() => dispatch('getSystemService', { server, id })) }, - stopSystemService: ({ state, commit }, { id, server = store.state.system.hostname }) => { + stopSystemService: ({ state, commit, dispatch }, { id, server = store.state.system.hostname }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) commit('SYSTEM_SERVICE_STOPPING', { server, id }) return api(state, server).stopSystem(id).then(response => { commit('SYSTEM_SERVICE_STOPPED', { server, id, response }) - return state.servers[server].services[id] + return state.servers[server].system_services[id] }).catch(err => { const { response: { data: error } = {} } = err commit('SYSTEM_SERVICE_ERROR', { server, id, error }) throw err - }) + }).finally(() => dispatch('getSystemService', { server, id })) }, + updateSystemd: ({ state, commit }, { id, server = store.state.system.hostname }) => { commit('SYSTEMD_REQUEST', { server, id }) return api(state, server).updateSystemd(id).then(response => { @@ -640,9 +704,18 @@ const mutations = { SYSTEM_SERVICE_REQUEST: (state, { server, id }) => { state.status = types.LOADING Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {} }) - Vue.set(state.servers[server].system_services, id, state.servers[server].services[id] || {}) + Vue.set(state.servers[server].system_services, id, state.servers[server].system_services[id] || {}) Vue.set(state.servers[server].system_services[id], 'status', types.LOADING) }, + SYSTEM_SERVICE_SUCCESS: (state, { server, id, service }) => { + service.id = id + service.pid = parseInt(service.pid) + service.alive = !!(service.pid) + service.message = '' + state.status = types.SUCCESS + state.message = '' + Vue.set(state.servers[server].system_services, id, { ...state.servers[server].system_services[id], ...service, status: types.SUCCESS }) + }, SYSTEM_SERVICE_RESTARTING: (state, { server, id }) => { state.status = types.LOADING Vue.set(state.servers[server].system_services[id], 'status', types.RESTARTING) diff --git a/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/AlertServices.vue b/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/AlertServices.vue new file mode 100644 index 000000000000..da310eae01dd --- /dev/null +++ b/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/AlertServices.vue @@ -0,0 +1,42 @@ + + + diff --git a/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/TheView.js b/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/TheView.js index e35e28224e69..fc91f061b9e8 100644 --- a/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/TheView.js +++ b/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/TheView.js @@ -1,6 +1,6 @@ import { + AlertServices, BaseView, - FormButtonBar, TheForm } from './' @@ -10,6 +10,8 @@ const components = { TheForm } +import { computed } from '@vue/composition-api' +import { renderHOCWithScopedSlots } from '@/components/new/' import { useViewCollectionItem, useViewCollectionItemProps } from '../../_composables/useViewCollectionItem' import * as collection from '../_composables/useCollection' @@ -18,14 +20,31 @@ const props = { ...collection.useItemProps } -const setup = (props, context) => useViewCollectionItem(collection, props, context) +const setup = (props, context) => { + + const viewCollectionItem = useViewCollectionItem(collection, props, context) + const { + isLoading, + isModified + } = viewCollectionItem + + const scopedSlotProps = computed(() => ({ ...props, isLoading: isLoading.value, isModified: isModified.value })) + + return { + ...viewCollectionItem, + scopedSlotProps + } +} + +const render = renderHOCWithScopedSlots(BaseView, { components, props, setup }, { + buttonsPrepend: AlertServices +}) // @vue/component export default { name: 'the-view', extends: BaseView, inheritAttrs: false, - components, props, - setup + render } diff --git a/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/index.js b/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/index.js index 8239d1e1e07a..ec65549bc336 100644 --- a/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/index.js +++ b/html/pfappserver/root/src/views/Configuration/syslogForwarders/_components/index.js @@ -7,6 +7,7 @@ import { BaseFormGroupInputNumber, BaseFormGroupToggleDisabledEnabled } from '@/components/new/' +import AlertServices from './AlertServices' import TheForm from './TheForm' import TheView from './TheView' @@ -21,6 +22,7 @@ export { BaseFormGroupInputNumber as FormGroupPort, BaseFormGroupChosenOne as FormGroupProto, + AlertServices, TheForm, TheView } diff --git a/html/pfappserver/root/src/views/Status/services/_components/BaseSystemService.vue b/html/pfappserver/root/src/views/Status/services/_components/BaseSystemService.vue new file mode 100644 index 000000000000..2e8c3e46cd09 --- /dev/null +++ b/html/pfappserver/root/src/views/Status/services/_components/BaseSystemService.vue @@ -0,0 +1,158 @@ + + From f82d5de9d298c2a549065a1321fa02161d23f246 Mon Sep 17 00:00:00 2001 From: Darren Satkunas Date: Thu, 8 Dec 2022 07:09:57 -0800 Subject: [PATCH 2/5] add monit system service in monit configuration --- .../monit/_components/AlertServices.vue | 42 +++++++++++++++++++ .../monit/_components/TheForm.vue | 4 -- .../monit/_components/TheView.js | 30 ++++++++++--- .../Configuration/monit/_components/index.js | 4 +- 4 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 html/pfappserver/root/src/views/Configuration/monit/_components/AlertServices.vue diff --git a/html/pfappserver/root/src/views/Configuration/monit/_components/AlertServices.vue b/html/pfappserver/root/src/views/Configuration/monit/_components/AlertServices.vue new file mode 100644 index 000000000000..3a5d701e4113 --- /dev/null +++ b/html/pfappserver/root/src/views/Configuration/monit/_components/AlertServices.vue @@ -0,0 +1,42 @@ + + + diff --git a/html/pfappserver/root/src/views/Configuration/monit/_components/TheForm.vue b/html/pfappserver/root/src/views/Configuration/monit/_components/TheForm.vue index 94e6a0020ece..750a42d8a877 100644 --- a/html/pfappserver/root/src/views/Configuration/monit/_components/TheForm.vue +++ b/html/pfappserver/root/src/views/Configuration/monit/_components/TheForm.vue @@ -5,10 +5,6 @@ :schema="schema" :isLoading="isLoading" > -
{{ $t('Modifying this configuration requires to restart monit using the following command: `systemctl restart monit`') }}
- useViewResource(resource, props, context) + +const setup = (props, context) => { + + const viewResource = useViewResource(resource, props, context) + const { + isLoading, + isModified + } = viewResource + + const scopedSlotProps = computed(() => ({ ...props, isLoading: isLoading.value, isModified: isModified.value })) + + return { + ...viewResource, + scopedSlotProps + } +} + +const render = renderHOCWithScopedSlots(BaseView, { components, props, setup }, { + buttonsPrepend: AlertServices +}) // @vue/component export default { name: 'the-view', extends: BaseView, inheritAttrs: false, - components, props, - setup + render } - diff --git a/html/pfappserver/root/src/views/Configuration/monit/_components/index.js b/html/pfappserver/root/src/views/Configuration/monit/_components/index.js index a6eef0cbf351..0c769e1b0281 100644 --- a/html/pfappserver/root/src/views/Configuration/monit/_components/index.js +++ b/html/pfappserver/root/src/views/Configuration/monit/_components/index.js @@ -5,6 +5,7 @@ import { BaseFormGroupTextarea, BaseFormGroupToggleDisabledEnabled } from '@/components/new/' +import AlertServices from './AlertServices' import TheForm from './TheForm' import TheView from './TheView' @@ -18,7 +19,8 @@ export { BaseFormGroupToggleDisabledEnabled as FormGroupStatus, BaseFormGroupInput as FormGroupSubjectPrefix, - BaseViewResource as BaseView, + BaseViewResource as BaseView, + AlertServices, TheForm, TheView } From b5c93bbb841550bbb469d7482e383e426f74c6a4 Mon Sep 17 00:00:00 2001 From: Darren Satkunas Date: Thu, 8 Dec 2022 10:03:44 -0800 Subject: [PATCH 3/5] move services --- .../src/components/new/BaseButtonService.vue | 4 ++-- .../new/BaseButtonSystemService.vue | 4 ++-- .../new}/BaseService.vue | 2 +- .../new}/BaseSystemService.vue | 2 +- .../root/src/components/new/index.js | 6 +++++ .../pfappserver/root/src/globals/pfLocales.js | 22 ++++++++++++++++++- .../_components/BaseButtonBulkActions.vue | 2 +- .../Status/services/_components/TheView.vue | 4 ++-- .../root/src/views/Status/services/config.js | 19 ---------------- 9 files changed, 36 insertions(+), 29 deletions(-) rename html/pfappserver/root/src/{views/Status/services/_components => components/new}/BaseService.vue (99%) rename html/pfappserver/root/src/{views/Status/services/_components => components/new}/BaseSystemService.vue (99%) delete mode 100644 html/pfappserver/root/src/views/Status/services/config.js diff --git a/html/pfappserver/root/src/components/new/BaseButtonService.vue b/html/pfappserver/root/src/components/new/BaseButtonService.vue index 317dc0bfc600..f4539488b651 100644 --- a/html/pfappserver/root/src/components/new/BaseButtonService.vue +++ b/html/pfappserver/root/src/components/new/BaseButtonService.vue @@ -65,7 +65,7 @@ diff --git a/html/pfappserver/root/src/components/new/BaseSystemdUpdate.vue b/html/pfappserver/root/src/components/new/BaseSystemdUpdate.vue new file mode 100644 index 000000000000..a6c7ffa39f05 --- /dev/null +++ b/html/pfappserver/root/src/components/new/BaseSystemdUpdate.vue @@ -0,0 +1,96 @@ + + diff --git a/html/pfappserver/root/src/components/new/index.js b/html/pfappserver/root/src/components/new/index.js index 26f7400be800..4e057d938cc6 100644 --- a/html/pfappserver/root/src/components/new/index.js +++ b/html/pfappserver/root/src/components/new/index.js @@ -7,6 +7,7 @@ import BaseButtonSave from './BaseButtonSave' import BaseButtonSaveSearch from './BaseButtonSaveSearch' import BaseButtonService from './BaseButtonService' import BaseButtonSystemService from './BaseButtonSystemService' +import BaseButtonSystemdUpdate from './BaseButtonSystemdUpdate' import BaseButtonUpload from './BaseButtonUpload' import BaseContainerLoading from './BaseContainerLoading' import BaseCsvImport from './BaseCsvImport' @@ -154,6 +155,7 @@ export { BaseButtonSaveSearch, BaseButtonService, BaseButtonSystemService, + BaseButtonSystemdUpdate, BaseButtonUpload, // containers diff --git a/html/pfappserver/root/src/globals/pfLocales.js b/html/pfappserver/root/src/globals/pfLocales.js index 7b08ac0d9f39..ea01886eecbf 100644 --- a/html/pfappserver/root/src/globals/pfLocales.js +++ b/html/pfappserver/root/src/globals/pfLocales.js @@ -32,4 +32,7 @@ export const localeStrings = { SERVICES_STOPPED_SUCCESS: 'Stopped services {services}.', // i18n defer SERVICES_STOPPED_ERROR: 'Failed to stop services {services}. See the server error logs for more information.', // i18n defer + + SYSTEMD_UPDATED_SUCCESS: 'Updated systemd for {service}.', // i18n defer + SYSTEMD_UPDATED_ERROR: 'Failed to update systemd for {service}. See the server error logs for more information.', // i18n defer } diff --git a/html/pfappserver/root/src/store/modules/cluster.js b/html/pfappserver/root/src/store/modules/cluster.js index af8f22c33b25..26a583addeb7 100644 --- a/html/pfappserver/root/src/store/modules/cluster.js +++ b/html/pfappserver/root/src/store/modules/cluster.js @@ -155,6 +155,7 @@ const types = { RESTARTING: 'restarting', STARTING: 'starting', STOPPING: 'stopping', + UPDATING: 'updating', SUCCESS: 'success', ERROR: 'error' } @@ -227,14 +228,30 @@ const getters = { }, hasAlive: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && service.alive && service.pid) > -1, hasDead: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && !(service.alive || service.pid)) > -1, - hasEnabled: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && service.enabled) > -1, - hasDisabled: Object.values(state.servers).findIndex(({ services: { [id]: service } }) => service && !service.enabled) > -1, - isProtected: !!protectedServices.find(listed => listed === id), } } }, sorted) }, {}) - } + }, + systemdByServer: state => { + return Object.entries(state.servers).reduce((sorted, [server, {systemd = {}}]) => { + return Object.entries(systemd).reduce((sorted, [id, service]) => { + return { + ...sorted, + [id]: { + servers: { + ...((id in sorted) ? sorted[id].servers : {} ), + [server]: { + ...service, + isUpdating: service.status === types.UPDATING, + } + } + } + } + }, sorted) + }, {}) + }, + servers: state => Object.keys(state.servers), } const actions = { @@ -323,7 +340,7 @@ const actions = { disableServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -363,7 +380,7 @@ const actions = { enableServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -403,7 +420,7 @@ const actions = { restartServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -443,7 +460,7 @@ const actions = { startServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -483,7 +500,7 @@ const actions = { stopServiceCluster: ({ state, dispatch }, id) => { return new Promise((resolve, reject) => { dispatch('getConfig').then(() => { - // async requests + // serialize async requests const async = (idx = 0) => { const server = Object.keys(state.servers)[idx] const next = () => { @@ -509,6 +526,7 @@ const actions = { }) }, + getSystemService: ({ state, commit }, { server, id }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) return api(state, server).systemService(id).then(service => { @@ -546,6 +564,34 @@ const actions = { throw err }).finally(() => dispatch('getSystemService', { server, id })) }, + restartSystemServiceCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length-1) { + async(++idx) + } + else { + resolve() + } + } + const { [server]: { system_services: { [id]: { alive = false, pid = false } = {} } = {} } = {} } = state.servers + if (alive && pid) { + dispatch('restartSystemService', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + else { + next() + } + } + async() + }) + }) + }, startSystemService: ({ state, commit, dispatch }, { id, server = store.state.system.hostname }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) commit('SYSTEM_SERVICE_STARTING', { server, id }) @@ -558,6 +604,34 @@ const actions = { throw err }).finally(() => dispatch('getSystemService', { server, id })) }, + startSystemServiceCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length - 1) { + async(++idx) + } + else { + resolve() + } + } + const { [server]: { system_services: { [id]: { alive = false, pid = false } = {} } = {} } = {} } = state.servers + if (!(alive && pid)) { + dispatch('startSystemService', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + else { + next() + } + } + async() + }) + }) + }, stopSystemService: ({ state, commit, dispatch }, { id, server = store.state.system.hostname }) => { commit('SYSTEM_SERVICE_REQUEST', { server, id }) commit('SYSTEM_SERVICE_STOPPING', { server, id }) @@ -570,6 +644,35 @@ const actions = { throw err }).finally(() => dispatch('getSystemService', { server, id })) }, + stopSystemServiceCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length - 1) { + async(++idx) + } + else { + resolve() + } + } + const { [server]: { system_services: { [id]: { alive = false, pid = false } = {} } = {} } = {} } = state.servers + if (alive && pid) { + dispatch('stopSystemService', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + else { + next() + } + } + async() + }) + }) + }, + updateSystemd: ({ state, commit }, { id, server = store.state.system.hostname }) => { commit('SYSTEMD_REQUEST', { server, id }) @@ -582,6 +685,28 @@ const actions = { throw err }) }, + updateSystemdCluster: ({ state, dispatch }, id) => { + return new Promise((resolve, reject) => { + dispatch('getConfig').then(() => { + // serialize async requests + const async = (idx = 0) => { + const server = Object.keys(state.servers)[idx] + const next = () => { + if (idx < Object.keys(state.servers).length - 1) { + async(++idx) + } + else { + resolve() + } + } + dispatch('updateSystemd', { server, id }) + .catch(err => reject(err)) + .then(() => next()) + } + async() + }) + }) + }, } const mutations = { @@ -593,7 +718,7 @@ const mutations = { }, CONFIG_SUCCESS: (state, items) => { items.map(server => { - Vue.set(state.servers, server.host, { services: {}, system_services: {}, ...state.servers[server.host], ...server }) + Vue.set(state.servers, server.host, { services: {}, system_services: {}, systemd: {}, ...state.servers[server.host], ...server }) }) state.status = types.SUCCESS state.message = '' @@ -625,7 +750,7 @@ const mutations = { SERVICE_REQUEST: (state, { server, id }) => { state.status = types.LOADING - Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {} }) + Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {}, systemd: {} }) Vue.set(state.servers[server].services, id, state.servers[server].services[id] || {}) Vue.set(state.servers[server].services[id], 'status', types.LOADING) }, @@ -703,7 +828,7 @@ const mutations = { SYSTEM_SERVICE_REQUEST: (state, { server, id }) => { state.status = types.LOADING - Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {} }) + Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {}, systemd: {} }) Vue.set(state.servers[server].system_services, id, state.servers[server].system_services[id] || {}) Vue.set(state.servers[server].system_services[id], 'status', types.LOADING) }, @@ -746,17 +871,23 @@ const mutations = { Vue.set(state.servers[server].system_services[id], 'status', types.ERROR) }, - SYSTEMD_REQUEST: state => { + SYSTEMD_REQUEST: (state, { server, id }) => { state.status = types.LOADING + Vue.set(state.servers, server, state.servers[server] || { services: {}, system_services: {}, systemd: {} }) + Vue.set(state.servers[server].systemd, id, state.servers[server].systemd[id] || {}) + Vue.set(state.servers[server].systemd[id], 'status', types.UPDATING) }, - SYSTEMD_SUCCESS: state => { + SYSTEMD_SUCCESS: (state, { server, id }) => { state.status = types.SUCCESS state.message = '' + Vue.set(state.servers[server].systemd, id, { ...state.servers[server].systemd[id], status: types.SUCCESS }) }, - SYSTEMD_ERROR: (state, error) => { + SYSTEMD_ERROR: (state, { server, id, error }) => { state.status = types.ERROR state.message = error + Vue.set(state.servers[server].systemd[id], 'status', types.ERROR) }, + $RESET: (state) => { // eslint-disable-next-line no-unused-vars state = initialState() diff --git a/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue b/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue index a54d35166b55..425830dde0c6 100644 --- a/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue +++ b/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue @@ -13,6 +13,10 @@ :to="{ name: 'newEventLogger', params: { eventLoggerType: value } }" >{{ text }} + + Date: Fri, 9 Dec 2022 06:04:41 -0800 Subject: [PATCH 5/5] add systemd button to monit and services --- .../Configuration/eventLoggers/_components/TheSearch.vue | 6 ------ .../Configuration/monit/_components/AlertServices.vue | 9 ++++++--- .../src/views/Status/services/_components/TheView.vue | 5 +++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue b/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue index 425830dde0c6..9f113f1ff6c0 100644 --- a/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue +++ b/html/pfappserver/root/src/views/Configuration/eventLoggers/_components/TheSearch.vue @@ -4,9 +4,6 @@

{{ $t('Event Loggers') }}

-
{{ $t(`Creating, modifying or deleting an event logger entry requires to restart the packetfence-mariadb service using the following command: systemctl restart packetfence-mariadb`) }}
-

+ :disabled="isLoading" class="mr-1" size="sm" /> +