Finalizing #9
- Added service handler for system services - Control OP25 from service handler - Generate and save OP25 config file - Handlers for OP25
This commit is contained in:
52
client/modules/serviceHandler.mjs
Normal file
52
client/modules/serviceHandler.mjs
Normal file
@@ -0,0 +1,52 @@
|
||||
import { exec } from 'child_process';
|
||||
|
||||
/**
|
||||
* Starts the given service from the command line.
|
||||
* @param {string} serviceName The service name to be started. Ex: ... start "{serviceName}.service"
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const startService = async (serviceName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`sudo systemctl start ${serviceName}.service`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Restarts the given service from the command line.
|
||||
* @param {string} serviceName The service name to be restarted. Ex: ... restart "{serviceName}.service"
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const restartService = async (serviceName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`sudo systemctl restart ${serviceName}.service`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the given service from the command line.
|
||||
* @param {string} serviceName The service name to be stopped. Ex: ... stop "{serviceName}.service"
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const stopService = async (serviceName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`sudo systemctl stop ${serviceName}.service`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user