// variables
const services = { start: {}, stop: {}, restart: {}, status: {} };
const serviceNames = ['mysql','websocket','logger','scheduler'];

// dynamic manager
['start', 'stop', 'status'].forEach(action => {
    serviceNames.forEach(name => {
        services[action][name] = async () => {
            const file = `./${name}/${action}.js`;
            const func = require(file);
            return await func();
        };
    });
});

// restart function
serviceNames.forEach(name => {
    services.restart[name] = async () => {
        await services.stop[name]();
        await services.start[name]();
    };
});

// function export
module.exports = services;