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} */ 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} */ 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} */ 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(); } }); }); };