1、IcePatch2是一个用来同步文件系统的ICE工具集,可以用来进行应用程序发布包的升级发布。
A、构建应用程序发布目录
B、将应用程序发布包,非zip格式安装到发布目录
C、执行icepatch2calc来计算安装目录下的校验和
D、执行icepatch2server来运行patch服务器
E、在待同步的目标服务器上运行patch2的客户端程序(可以是icepatch2client也可以是自行编写的client)
F、在更新应用程序时,将新的发布包安装到发布目录
G、重启icepatch2server
H、在待同步的目标服务器上运行patch2的客户端程序,如果是自行的client,也可以自行定时更新
2、程序的配置文件样例
IcePatch2.InstanceName=PatchServer # 服务器实例名称
IcePatch2.Endpoints=tcp -h localhost -p 5555 # 监听的客户端endpoint
IcePatch2.Admin.Endpoints=tcp -h localhost -p 5556 # 监听的管理端endpoint,可以通过管理端shutdown server
IcePatch2.Directory=/home/mossp/data # 数据存储根目录
IcePatch2.ChunkSize=10 # 传输数据包的大小
IcePatch2.Thorough=1 # 是否每次重新计算校验和
IcePatch2.Remove=1 # 客户端是否删除和服务器端不匹配的文件
3、启动icepatch2server后在服务器端会存在两个object:InstanceName/server和InstanceName/admin
4、编写自定义行为的icepatch2client:包含头文件"IcePatch2/ClientUtil.h"和链接库"libIcePatch2.so"
Ice::CommunicatorPtr communicator = ...;
IcePatch2::PatcherFeedbackPtr feedback = new MyPatcherFeedbackI;
IcePatch2::PatcherPtr patcher = new IcePatch2::Patcher(communicator, feedback);
try {
bool aborted = !patcher->prepare();
if(!aborted)
aborted = !patcher->patch("");
if(!aborted)
patcher->finish();
if(aborted)
cerr << "Patch aborted" << endl;
} catch(const string& reason) {
cerr << "Patch error: " << reason << endl;
}
5、编写自定义的同步回调结构对象:该对象的所有虚方法如果返回false表示失败,将会中断patcher的执行,如果返回true标示成功继续
class MyPatcherFeedback : public IcePatch2::PatcherFeedback
{
// 如下方法在prepare方法调用时回调
// 找不到本地校验和文件时调用
virtual bool noFileSummary(const std::string& reason);
// 计算校验和回调接口
virtual bool checksumStart();
virtual bool checksumProgress(const std::string& path);
virtual bool checksumEnd();
// 收集本地的文件列表,其中percent标示收集的进度
virtual bool fileListStart();
virtual bool fileListProgress(Ice::Int percent);
virtual bool fileListEnd();
// 如下方法在patch方法调用时回调
// 在更新每个文件时回调,path为路径,size为文件大小,pos为已经更新大小,updated为累计大小,total为总大小
virtual bool patchStart(const std::string& path, Ice::Long size,Ice::Long updated, Ice::Long total);
virtual bool patchProgress(Ice::Long pos, Ice::Long size,Ice::Long updated, Ice::Long total);
virtual bool patchEnd();
}
A、构建应用程序发布目录
B、将应用程序发布包,非zip格式安装到发布目录
C、执行icepatch2calc来计算安装目录下的校验和
D、执行icepatch2server来运行patch服务器
E、在待同步的目标服务器上运行patch2的客户端程序(可以是icepatch2client也可以是自行编写的client)
F、在更新应用程序时,将新的发布包安装到发布目录
G、重启icepatch2server
H、在待同步的目标服务器上运行patch2的客户端程序,如果是自行的client,也可以自行定时更新
2、程序的配置文件样例
IcePatch2.InstanceName=PatchServer # 服务器实例名称
IcePatch2.Endpoints=tcp -h localhost -p 5555 # 监听的客户端endpoint
IcePatch2.Admin.Endpoints=tcp -h localhost -p 5556 # 监听的管理端endpoint,可以通过管理端shutdown server
IcePatch2.Directory=/home/mossp/data # 数据存储根目录
IcePatch2.ChunkSize=10 # 传输数据包的大小
IcePatch2.Thorough=1 # 是否每次重新计算校验和
IcePatch2.Remove=1 # 客户端是否删除和服务器端不匹配的文件
3、启动icepatch2server后在服务器端会存在两个object:InstanceName/server和InstanceName/admin
4、编写自定义行为的icepatch2client:包含头文件"IcePatch2/ClientUtil.h"和链接库"libIcePatch2.so"
Ice::CommunicatorPtr communicator = ...;
IcePatch2::PatcherFeedbackPtr feedback = new MyPatcherFeedbackI;
IcePatch2::PatcherPtr patcher = new IcePatch2::Patcher(communicator, feedback);
try {
bool aborted = !patcher->prepare();
if(!aborted)
aborted = !patcher->patch("");
if(!aborted)
patcher->finish();
if(aborted)
cerr << "Patch aborted" << endl;
} catch(const string& reason) {
cerr << "Patch error: " << reason << endl;
}
5、编写自定义的同步回调结构对象:该对象的所有虚方法如果返回false表示失败,将会中断patcher的执行,如果返回true标示成功继续
class MyPatcherFeedback : public IcePatch2::PatcherFeedback
{
// 如下方法在prepare方法调用时回调
// 找不到本地校验和文件时调用
virtual bool noFileSummary(const std::string& reason);
// 计算校验和回调接口
virtual bool checksumStart();
virtual bool checksumProgress(const std::string& path);
virtual bool checksumEnd();
// 收集本地的文件列表,其中percent标示收集的进度
virtual bool fileListStart();
virtual bool fileListProgress(Ice::Int percent);
virtual bool fileListEnd();
// 如下方法在patch方法调用时回调
// 在更新每个文件时回调,path为路径,size为文件大小,pos为已经更新大小,updated为累计大小,total为总大小
virtual bool patchStart(const std::string& path, Ice::Long size,Ice::Long updated, Ice::Long total);
virtual bool patchProgress(Ice::Long pos, Ice::Long size,Ice::Long updated, Ice::Long total);
virtual bool patchEnd();
}