linux同步工具

来源:互联网 发布:淘宝的 微淘动态 编辑:程序博客网 时间:2024/06/07 05:51

linux同步工具

项目源码

项目简介 :实现在linux环境下服务端和客户端同步文件、更新文件、一键部署环境

开发环境 :linux,c++, vim, g++, gdb, make

主要技术

1、正则表达式:关于正则表达式的元字符和在c++中使用正则表达式,我做了总结:正则表达式

2、守护进程:linux下,man 7 daemon会得到守护进程的标准创建过程。

 1. Close all open file descriptors except standard input, output, and error (i.e. the first three file descriptors 0, 1, 2). This ensures that no accidentally passed file descriptor stays around in the daemon process. On Linux, this is best implemented by iterating through /proc/self/fd, with a fallback of iterating from file descriptor 3 to the value returned by getrlimit() for RLIMIT_NOFILE.2. Reset all signal handlers to their default. This is best done by iterating through the available signals up to the limit of _NSIG and resetting them to SIG_DFL.3. Reset the signal mask using sigprocmask().4. Sanitize the environment block, removing or resetting environment variables that might negatively impact daemon runtime.5. Call fork(), to create a background process.6. In the child, call setsid() to detach from any terminal and create an independent session.7. In the child, call fork() again, to ensure that the daemon can never re-acquire a terminal again.8. Call exit() in the first child, so that only the second child (the actual daemon process) stays around. This ensures that the daemon process is re-parented to init/PID 1, as all daemons should be.9. In the daemon process, connect /dev/null to standard input, output, and error.10. In the daemon process, reset the umask to 0, so that the file modes passed to open(), mkdir() and suchlike directly control the access mode of the created files and directories.11. In the daemon process, change the current directory to the root directory (/), in order to avoid that the daemon involuntarily blocks mount points from being unmounted.12. In the daemon process, write the daemon PID (as returned by getpid()) to a PID file, for example /run/foobar.pid (for a hypothetical daemon "foobar") to ensure that the daemon cannot be started more than once. This must be implemented in race-free fashion so that the PID file is only updated when it is verified at the same time that the PID previously stored in the PID file no longer exists or belongs to a foreign process.13. In the daemon process, drop privileges, if possible and applicable.14. From the daemon process, notify the original process started that initialization is complete. This can be implemented via an unnamed pipe or similar communication channel that is created before the first fork() and hence available in both the original and the daemon process.15. Call exit() in the original process. The process that invoked the daemon must be able to rely on that this exit() happens after initialization is complete and all external communication channels are established and accessible.

3、配置文档:配置文档主要使用正则表达式进行处理,使用正则表达式提取要获取的关键字。

4、生产消费者模型:生产消费者模型

5、设计模式:单例模式、简单工厂模式、命令模式、中介者模式

项目特点:

  1. 符合语法规则的前提下,支持c注释与c++注释相互转换。
  2. 软件安装与升级:能触发多个主机通过apt或者yum安装和升级指定的软件包。
  3. 脚本执行:能远程控制客户端执行某个脚本文件,达到一键部署功能 。
  4. 整个系统拥有日志功能