import { execSync } from 'child_process'

// Returns one of: off, installed, enabled, running, synced, error
export function nginxStatus() {
  try {
    const stdout = execSync('nginx -v 2>&1')
  } catch(err) {
    return 'off'
  }
  
  try {
    const stdout = execSync('systemctl status nginx')
    if(stdout.includes('Active: active (running)')) {
      return 'running'
    } else if(stdout.includes('Active: inactive (dead)')) {
      return 'installed'
    }
  } catch(err) {
    return 'installed'
  }
  
  return 'installed'
}

export default {
  description: 'host AO publicly over the world wide web',
  status: nginxStatus
}