Exemple #1
0
/**
 * Function to stop a node.
 *
 * @param   Node    $n                  Node
 * @return  int                         0 means ok
 */
function stop($n)
{
    if ($n->getStatus() != 0) {
        if ($n->getNType() == 'docker') {
            $cmd = 'docker stop ' . $n->getUuid();
        } else {
            $cmd = 'fuser -n tcp -k -TERM ' . $n->getPort() . ' > /dev/null 2>&1';
        }
        error_log('INFO: stopping ' . $cmd);
        exec($cmd, $o, $rc);
        sleep(1);
        // Need to wait a few
        if ($n->getStatus() == 0) {
            return 0;
        } else {
            // Node is still running
            error_log('ERROR: ' . $GLOBALS['messages'][80035]);
            error_log(implode("\n", $o));
            return 80035;
        }
    } else {
        return 0;
    }
}
Exemple #2
0
/**
 * Function to stop a node.
 *
 * @param   Node    $n                  Node
 * @return  int                         0 means ok
 */
function stop($n)
{
    if ($n->getStatus() != 0) {
        if ($n->getNType() == 'docker') {
            $cmd = 'docker -H=tcp://127.0.0.1:4243 stop ' . $n->getUuid();
        } else {
            $cmd = 'fuser -n tcp -k -TERM ' . $n->getPort() . ' > /dev/null 2>&1';
        }
        error_log(date('M d H:i:s ') . 'INFO: stopping ' . $cmd);
        exec($cmd, $o, $rc);
        if ($rc == 0) {
            return 0;
        } else {
            // Node is still running
            error_log(date('M d H:i:s ') . 'ERROR: ' . $GLOBALS['messages'][80035]);
            error_log(date('M d H:i:s ') . implode("\n", $o));
            return 80035;
        }
    } else {
        return 0;
    }
}
Exemple #3
0
/**
 * Function to stop a node.
 *
 * @param   Node    $n                  Node
 * @return  int                         0 means ok
 */
function stop($n)
{
    if ($n->getStatus() == 1) {
        $cmd = 'kill -s TERM $(fuser -n tcp ' . $n->getPort() . ' 2> /dev/null | sed "s/^.* \\([0-9]\\+\\)$/\\1/g")';
        exec($cmd, $o, $rc);
        error_log('INFO: stopping ' . $cmd);
        sleep(1);
        // Need to wait a few
        if ($n->getStatus() == 0) {
            return 0;
        } else {
            // Node is still running
            error_log('ERROR: ' . $GLOBALS['messages'][80035]);
            error_log(implode("\n", $o));
            return 80035;
        }
    } else {
        return 0;
    }
}
 /**
  * action 'add'
  * @param Request $request
  * @param Response $response
  */
 public function add(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $nid = $request->post('nid', 0);
         $ntype = $request->post('ntype');
         $title = $request->post('title', '');
         $thumb_url = $request->post('thumb_url', '');
         $match_type = $request->post('match_type', '');
         $start_date = $request->post('start_date', '');
         $end_date = $request->post('end_date', '');
         $keyword = $request->post('keyword', '');
         $slogan = $request->post('slogan', '');
         $content = $request->post('content', '');
         $content_dt = $request->post('content_detail', '');
         $status = $request->post('status', 'R');
         $ret = ['flag' => 'ERR', 'msg' => ''];
         if ('match' == $ntype) {
             if ('' == $title) {
                 $ret['msg'] = '标题不能为空';
                 $response->sendJSON($ret);
             } elseif ('' == $thumb_url) {
                 $ret['msg'] = '主图片不能为空';
                 $response->sendJSON($ret);
             }
             $match_types = Node::getMatchTypes();
             if (!in_array($match_type, array_keys($match_types))) {
                 $match_type = 'bs';
             }
         }
         $status_set = Node::getStatus();
         if (!in_array($status, array_keys($status_set))) {
             $status = 'R';
         }
         $ninfo = [];
         if ($nid) {
             $ninfo = Node::getInfo($nid);
             if (empty($ninfo)) {
                 $ret['msg'] = "Node(nid={$nid})不存在";
                 $response->sendJSON($ret);
             }
         }
         $uid = $_SESSION['logined_uid'];
         if (empty($uid)) {
             $ret['msg'] = "未登录,请重新登录";
             $response->sendJSON($ret);
         }
         $now = simphp_time();
         $params = ['ntype' => $ntype, 'title' => $title, 'content' => $content, 'keyword' => $keyword, 'createdby' => $uid, 'created' => $now, 'changedby' => $uid, 'changed' => $now, 'status' => $status];
         $allowed_ntypes = C('env.allowed_nodetypes');
         if (empty($ninfo)) {
             // new insert
             $ninfo['nid'] = D()->insert('node', $params);
             if ($ninfo['nid'] && in_array($ntype, $allowed_ntypes) && 'base' != $ntype) {
                 $params_ext = ['enid' => $ninfo['nid']];
                 switch ($ntype) {
                     case 'match':
                         $params_ext['match_type'] = $match_type;
                         $params_ext['thumb_url'] = $thumb_url;
                         $params_ext['slogan'] = $slogan;
                         $params_ext['start_date'] = $start_date;
                         $params_ext['end_date'] = $end_date;
                         $params_ext['content_detail'] = $content_dt;
                         break;
                 }
                 D()->insert('node_' . $ntype, $params_ext);
             }
             $ret['flag'] = 'OK';
             $ret['msg'] = '添加成功!';
             $response->sendJSON($ret);
         } else {
             // edit
             unset($params['createdby'], $params['created']);
             D()->update('node', $params, ['nid' => $nid]);
             if (D()->affected_rows() && in_array($ntype, $allowed_ntypes) && 'base' != $ntype) {
                 $params_ext = [];
                 switch ($ntype) {
                     case 'match':
                         $params_ext['match_type'] = $match_type;
                         $params_ext['thumb_url'] = $thumb_url;
                         $params_ext['slogan'] = $slogan;
                         $params_ext['start_date'] = $start_date;
                         $params_ext['end_date'] = $end_date;
                         $params_ext['content_detail'] = $content_dt;
                         break;
                 }
                 D()->update('node_' . $ntype, $params_ext, ['enid' => $nid]);
             }
             $ret['flag'] = 'OK';
             $ret['msg'] = '编辑成功!';
             $response->sendJSON($ret);
         }
     } else {
         // GET request
         // Node Info
         $nid = $request->arg(1);
         $nid = intval($nid);
         $is_edit = $nid ? TRUE : FALSE;
         $ninfo = $is_edit ? Node::getInfo($nid) : [];
         // Node Type
         $node_type = '';
         if (!$is_edit) {
             $node_type = $request->arg(2);
             $allowed_ntypes = C('env.allowed_nodetypes');
             if (!in_array($node_type, $allowed_ntypes)) {
                 $node_type = 'base';
             }
         } else {
             $node_type = $ninfo['ntype'];
         }
         $this->v->assign('node_type', $node_type);
         $this->v->assign('nav_second', $node_type);
         // Node status
         $status_set = Node::getStatus();
         $this->v->assign('status_set', $status_set);
         // Extra node info
         switch ($node_type) {
             case 'match':
                 $match_types = Node::getMatchTypes();
                 $this->v->assign('match_types', $match_types);
                 break;
         }
         $this->v->set_tplname('mod_node_add');
         $this->v->assign('ninfo', $ninfo)->assign('is_edit', $is_edit);
         $response->send($this->v);
     }
 }
Exemple #5
0
 static function show_status($params)
 {
     $key = isset($params['key']) ? $params['key'] : '';
     $status_set = Node::getStatus();
     return isset($status_set[$key]) ? $status_set[$key] : '未知状态';
 }