"use strict";
/**
 /**
 * penguins-eggs
 * class: systemctl.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * Presa da https://github.com/VolantisDev/node-systemctl
 * license: MIT
 */
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const utils_1 = require("../lib/utils");
const utils_2 = tslib_1.__importDefault(require("./utils"));
class SistemdCtl {
    constructor(verbose = false) {
        this.echo = {};
        this.echo = utils_2.default.setEcho(verbose);
    }
    /**
     *
     */
    async reload(service) {
        await (0, utils_1.exec)(`systemctl reload ${service}`, this.echo);
    }
    /**
     *
     */
    async disable(service, chroot = '/', report = false) {
        await (0, utils_1.exec)(`chroot ${chroot}} systemctl disable ${service}`, this.echo);
        if (report) {
            console.log(`systemctl: disabled ${service} on ${chroot}`);
        }
    }
    /**
     *
     */
    async enable(service) {
        await (0, utils_1.exec)(`systemctl enable ${service}`, this.echo);
    }
    /**
     *
     */
    async restart(service) {
        await (0, utils_1.exec)(`systemctl restart ${service}`, this.echo);
    }
    /**
     *
     */
    async start(service) {
        await (0, utils_1.exec)(`systemctl start ${service}`, this.echo);
    }
    /**
     *
     */
    async stop(service) {
        await (0, utils_1.exec)(`systemctl stop ${service}`, this.echo);
    }
    /**
     *
     * @param service
     * @returns
     */
    async isActive(service) {
        return new Promise((resolve, reject) => {
            (0, utils_1.exec)(`systemctl is-active ${service}`, this.echo)
                .then(result => {
                resolve(!result.data.includes('inactive'));
            })
                .catch(function (error) {
                resolve(false);
            });
        });
    }
    /**
     *
     */
    async isEnabled(service) {
        return new Promise((resolve, reject) => {
            (0, utils_1.exec)(`systemctl is-enabled ${service}`, this.echo)
                .then(result => {
                resolve(result.data.includes('enabled'));
            })
                .catch(function (error) {
                resolve(false);
            });
        });
    }
}
exports.default = SistemdCtl;
