Skip to content

Commit

Permalink
初步可用版本哇咔咔咔咔卡!!
Browse files Browse the repository at this point in the history
晚上回家完善一下提示文字啥的。。。然后继续优化
  • Loading branch information
xsir317 committed Dec 3, 2014
1 parent 851fafd commit 38d8646
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 45 deletions.
2 changes: 1 addition & 1 deletion publisher/app/commands/TaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct()
public function fire()
{
//启动之前先检查进程是否还活着,如果还活着咱就退
if(file_exists($this->filelock) && posix_kill(intval(file_get_contents($this->filelock)),0))
if(file_exists($this->filelock) && function_exists('posix_kill') && posix_kill(intval(file_get_contents($this->filelock)),0))
{
die("pid exists,exit");
}
Expand Down
10 changes: 10 additions & 0 deletions publisher/app/controllers/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ public function editServer()
return View::make('servers/edit',array('server'=>$server,'error' => $error,'project_id' => $project_id,'projects'=>$prj_list));
}

public function pingServer()
{
$id = intval(Input::get('id'));
$server = Server::find($id);
if($id && $server && Auth::user()->pj_is_mine($server->project_id))
{
return Response::json(Task::pingRsyncServer($server->ip));
}
return Response::json(false);
}
}
32 changes: 26 additions & 6 deletions publisher/app/lib/TaskHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,21 @@ private function _runDelete($task)
*/
private function _runRsync($task)
{
$current_dir = getcwd();
$server = \Server::find($task->server_id);
$pj_dir = \Project::getTempDir($server->project_id);
chdir($pj_dir);
//目前就记录个日志就得了
$rsync_cmd = sprintf("rsync -avzP publisher@%s::%s %s",$server->ip,$server->rsync_name,$pj_dir);
//忽略文件、 发布时要添加del选项 --delete --exclude
file_put_contents(app_path()."/storage/rsync.log",$rsync_cmd."\n",FILE_APPEND);
if(true)
$rsync_cmd = sprintf("rsync -az --delete %s %s::%s",'.',$server->ip,$server->rsync_name);
//file_put_contents(app_path()."/storage/rsync.log",$rsync_cmd."\n",FILE_APPEND);
exec($rsync_cmd,$output,$return_var);
if($return_var == 0)
{
$server->current_version = $this->get_dir_version($pj_dir);
$server->current_version = $this->get_dir_version('.');
$server->save();
}
return array('result'=>true,'output'=> '');
chdir($current_dir);
return array('result'=>true,'output'=> implode("\n", $output)." code {$return_var}");
}

/**
Expand Down Expand Up @@ -319,4 +322,21 @@ private function get_dir_version($src_path,$type='svn')
break;
}
}

// 测试服务器通迅
public function pingRsyncServer($ip)
{
$result = array();
if ($fp = @fsockopen($ip, 873, $errno, $errstr, 5))
{
fwrite($fp, "\n");
$ret = fread($fp, 8192);
fclose($fp);
if(preg_match('/RSYNCD:\s*\d+/',$ret))
{
return true;
}
}
return false;
}
}
29 changes: 0 additions & 29 deletions publisher/app/models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,4 @@ public function project()
{
return $this->belongsTo('Project','project_id');
}

// 测试服务器通迅
// public static function pingServers($ip)
// {
// $result = array();
// $fp = @fsockopen($ip, 873, $errno, $errstr, 5);
// if (!$fp)
// {
// $result['result'] = false;
// $result['msg'] = "failure: $errstr ($errno)";
// }
// else
// {
// fwrite($fp, "\n");
// $ret = fread($fp, 8192);
// if(preg_match('/RSYNCD:\s*\d+/',$ret))
// {
// $result['result'] = true;
// $result['msg'] = "success: ".$ret;
// }
// elseif (preg_match ("/@ERROR:/i", $ret))
// {
// $result['result'] = false;
// $result['msg'] = "error: ".$ret;
// }
// fclose($fp);
// }
// return $result;
// }
}
1 change: 1 addition & 0 deletions publisher/app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
//服务器
Route::any('servers/add',array('before' => 'auth', 'uses' => 'ServersController@editServer'));
Route::any('servers/edit',array('before' => 'auth', 'uses' => 'ServersController@editServer'));
Route::get('servers/ping',array('before' => 'auth', 'uses' => 'ServersController@pingServer'));

//用户
Route::get('users/index',array('before' => 'auth', 'uses' => 'UsersController@all'));
Expand Down
43 changes: 35 additions & 8 deletions publisher/app/views/hello.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
@stop

@section('content')
<article>
<h3>欢迎使用代码发布系统</h3>
<article class="uk-article">
<h1 class="uk-article-title">欢迎使用代码发布系统</h1>
<p>本系统暂时只支持SVN,以后将逐步支持GIT。您可在“项目”菜单中找到自己要发布的项目,通过页面浏览项目的SVN历史纪录,选择要发布的版本和要发布的服务器,系统将把您选择的代码版本发布到指定服务器。</p>
<p>权限由超级管理员管理,请向超级管理员联系获取您所在项目的权限。请注意,获得权限之后,您将对您的项目负责。</p>
<h3>一般配置、使用说明</h3>
<p>
<h4>项目配置选项说明</h4>
<h3>项目配置选项说明</h3>
<section>
<ul class="uk-list">
<li>项目id: 每个项目有唯一的ID。</li>
Expand All @@ -27,11 +27,38 @@
<li><strong>请注意,修改源码地址会导致发布服务器上check的代码完全清除并重新checkout,可能会消耗一些时间。</strong></li>
</ul>
</section>
<h4>服务器配置选项说明</h4>
<section></section>
<h4>rsync服务器端配置说明</h4>
<section></section>
<h4>发布操作</h4>
<h3>服务器配置选项说明</h3>
<section>
<ul class="uk-list">
<li>服务器id: 每个服务器有唯一的ID。</li>
<li>服务器名称:服务器名称,例如“XX项目测试环境”</li>
<li>所属项目:请选择此服务器属于哪个项目</li>
<li>服务器ip:请和运维确认好服务器和本发布系统的网络关系,确认填写内网还是外网IP。</li>
<li>rsync模块名:rsync配置的模块名</li>
</ul>
</section>
<h3>rsync服务器端配置说明</h3>
<section>
rsync配置要确认好服务器和本发布系统的网络关系,确认填写内网还是外网IP。<br />
一个典型的rsync配置文件如下
<pre>
uid = root
gid = root
port = 873
pid file = /tmp/rsyncd.pid
lock file = /tmp/rsync.lock
log file = /tmp/rsyncd.log

[xingyuntest]
path = /usr/local/nginx/html/xingyuntest
read only = false
host allow = 127.0.0.1,192.168.83.244
host deny = *
</pre>
本系统暂时只依赖指定IP安全性,不支持Rsync端指定帐号密码,所以请务必限制IP白名单。<br />
更详细的配置请搜索rsync配置相关文章,<a href="http://www.cnblogs.com/mchina/p/2829944.html" target="_blank">例</a>。
</section>
<h3>发布操作</h3>
<section></section>
</p>
</article>
Expand Down
23 changes: 22 additions & 1 deletion publisher/app/views/projects/publish.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
<th>服务器</th>
<th>IP</th>
<th>版本</th>
<th>同步状态</th>
<th>发布进度</th>
<th>操作</th>
<th>状态</th>
</tr>
</thead>
<tbody>
Expand All @@ -76,6 +77,9 @@
<td>
<a href="/servers/edit?id=<?php echo $row->id;?>" class="uk-button">修改</a>
</td>
<td>
<i class="uk-icon-question uk-icon-small" alt="状态未知"></i>
</td>
</tr>
<?php endforeach;?>
</tbody>
Expand Down Expand Up @@ -260,5 +264,22 @@
}
},'json');
}
$(".server_row").each(function(){
var _this = $(this);
$.getJSON('/servers/ping',{id:_this.find("input[name='publish_box[]']").val()},function(_data){
if(_data)
{
_alt = '服务器正常';
_class = 'uk-icon-check';
}
else
{
_alt = '服务器Rsync服务故障!';
_class = 'uk-icon-warning';
}
_this.find("td:last i").attr("alt",_alt).removeClass('uk-icon-question').addClass(_class);
});
});
</script>
@stop

0 comments on commit 38d8646

Please sign in to comment.