<?php
require_once("guiconfig.inc");

define('DDNSGO_PID_FILE', '/var/run/ddnsgo.pid');

function isServiceRunning()
{
    $pid = @file_get_contents(DDNSGO_PID_FILE);
    if ($pid === false || !is_numeric($pid)) {
        return false;
    }
    exec("ps -p " . escapeshellarg((int) $pid), $output, $return_var);
    return $return_var === 0;
}

header('Content-Type: application/json');
echo json_encode(['status' => isServiceRunning() ? "running" : "stopped"]);