/**
 * penguins-eggs-v7
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 * gestione systemd
 * Presa da https://github.com/VolantisDev/node-systemctl
 */ import { exec } from '../lib/utils' ; export default class SistemdCtl { async daemonReload ( ) { return run ( 'daemon-reload' ) ; } async disable ( serviceName ) { return run ( 'disable' , serviceName ) ; } async enable ( serviceName ) { return run ( 'enable' , serviceName ) ; } async isEnabled ( serviceName ) { return new Promise ( ( resolve , reject ) => { run ( 'is-enabled' , serviceName ) . then ( ( result ) => { resolve ( result . data . includes ( 'enabled' ) ) ; } ) . catch ( function ( error ) { resolve ( false ) ; } ) ; } ) ; } async restart ( serviceName ) { return run ( 'restart' , serviceName ) ; } start ( serviceName ) { return run ( 'start' , serviceName ) ; } stop ( serviceName ) { return run ( 'stop' , serviceName ) ; } } /**
 *
 */ async function run ( cmd , serviceName = '' ) { let command = 'systemctl ' + cmd ; if ( serviceName !== '' ) { command = command + ' ' + serviceName ; } console . log ( command ) ; return exec ( command ) ; }