{"id":5116,"date":"2019-09-16T22:12:21","date_gmt":"2019-09-16T14:12:21","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=5116"},"modified":"2019-10-12T15:23:57","modified_gmt":"2019-10-12T07:23:57","slug":"%e4%bd%bf%e7%94%a8-qdac-%e5%88%9b%e5%bb%balinux-%e5%ae%88%e6%8a%a4%e8%bf%9b%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=5116","title":{"rendered":"\u4f7f\u7528 QDAC \u521b\u5efa Linux \u5b88\u62a4\u8fdb\u7a0b"},"content":{"rendered":"\n<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728 Delphi \u4e2d\u521b\u5efa  Linux \u5b88\u62a4\u8fdb\u7a0b\uff0c\u800c\u8fd9\u7bc7\u6587\u7ae0\u5219\u8bd5\u56fe\u5c06\u4e0a\u6587\u7684\u64cd\u4f5c\u7b80\u5355\u5316\uff0c\u4e0d\u8981\u518d\u53bb\u8003\u8651\u90a3\u4e48\u591a\u4e8b\u4e8b\u975e\u975e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u3010\u57fa\u7840\u5165\u95e8\u3011<\/strong><\/h4>\n\n\n\n<p>1\u3001\u5f15\u5165 qconsole_looper.pas \u5355\u5143\uff0c\u8fd9\u4e2a\u5355\u5143\u672c\u8eab\u539f\u6765\u662f\u4e3a\u4e86\u80fd\u591f\u5728\u63a7\u5236\u53f0\u7a0b\u5e8f\u4e2d\u8fd0\u884c\u4e3b\u7ebf\u7a0b\u51fd\u6570\u800c\u5f15\u5165\u7684\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u5f15\u7528\u5b83\u540e\u53ef\u4ee5\u4fdd\u8bc1 QWorker \u5728\u63a7\u5236\u53f0\u7a0b\u5e8f\u4e2d\u6b63\u5e38\u8fd0\u884c\u3002\u540c\u65f6\uff0c\u5b83\u52a0\u5165\u4e86\u7b49\u5f85\u5faa\u73af\uff0c\u8fd9\u6837\u5c31\u50cf Application.Run \u4e00\u6837\uff0c\u5177\u4f53\u7684\u5b9e\u73b0\u8bf7\u81ea\u884c\u53c2\u8003\u76f8\u5173\u7684\u5b9e\u73b0\u4ee3\u7801\u3002\u5f53\u7136\u4e86\uff0c\u63a7\u5236\u53f0\u7a0b\u5e8f\u5728\u7b49\u5f85\u8f93\u5165\u65f6\uff0c\u7531\u4e8e  ReadLn \u7b49\u51fd\u6570\u662f\u963b\u585e\u7684\uff0c\u6240\u4ee5\u5bf9\u5e94\u7684\u4e3b\u7ebf\u7a0b\u8c03\u7528\u4f1a\u88ab\u6302\u8d77\uff0c\u5728\u4f7f\u7528\u65f6\u8981\u6ce8\u610f\u3002\u5f53\u7136\uff0c\u6700\u540e\u5c31\u662f\u52a0\u5165\u4e86\u5bf9 POSIX \u7cfb\u7684\u4fe1\u53f7\u5904\u7406\u548c\u5b88\u62a4\u8fdb\u7a0b\u7684\u76f8\u5173\u5c5e\u6027\u652f\u6301\u3002<\/p>\n\n\n\n<p>2\u3001\u5982\u679c\u8981\u521b\u5efa\u5b88\u62a4\u8fdb\u7a0b\uff0c\u6267\u884c\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>TQConsoleLooper.Current.IsDaemon := true;<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u8981\u4e3a\u5b88\u62a4\u8fdb\u7a0b\u6307\u5b9a\u4e00\u4e2a PID \u4fe1\u606f\u6587\u4ef6\uff08\u4e00\u822c\u8fd9\u4e2a\u5728 Linux \u7b49\u7cfb\u7edf\u4e2d\u7528\u4e8e\u83b7\u53d6\u5f53\u524d\u670d\u52a1\u7684\u4e3b\u8fdb\u7a0bID\uff0c\u4ee5\u4fbf\u7ed3\u675f\u670d\u52a1\u8fdb\u7a0b\uff09\uff0c\u5219\u8bbe\u7f6e PidFile \u4e3a\u5bf9\u5e94\u7684\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\uff0c\u5fc5\u9700\u786e\u4fdd\u5bf9\u5e94\u7684\u76ee\u5f55\u6709\u5199\u5165\u6743\u9650\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>TQConsoleLooper.Current.PidFile :='\/var\/qdac\/test.pid';<\/code><\/pre>\n\n\n\n<p>3\u3001\u8c03\u7528 TQConsoleLooper.Current.Run \u542f\u52a8\u63a7\u5236\u53f0\u5faa\u73af\u3002<\/p>\n\n\n\n<p>\u5b8c\u6210\u4e0a\u8ff0\u57fa\u672c\u8fc7\u7a0b\u540e\uff0c\u4e00\u4e2a\u7b80\u5355\u7684\u63a7\u5236\u53f0\u670d\u52a1\u5c31\u53ef\u4ee5\u4e86\u3002\u5f53\u4f60\u5728\u7cfb\u7edf\u4e2d\u6253\u5f00\u7a0b\u5e8f\u65f6\uff0c\u5c31\u4f1a\u53d1\u73b0\u7a0b\u5e8f\u521b\u5efa\u4e86\u5b50\u670d\u52a1\u8fdb\u7a0b\u540e\uff0c\u76f4\u63a5\u9000\u51fa\u4e86\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010POSIX \u4fe1\u53f7\u54cd\u5e94\u3011<\/h4>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7a0b\u5e8f\u5728\u6536\u5230 QUIT \u3001 ABRT\u3001TERM \u4fe1\u53f7\u65f6\uff0c\u4e5f\u4f1a\u9000\u51fa\u7a0b\u5e8f\uff0c\u5982\u679c\u60a8\u60f3\u81ea\u5df1\u63a7\u5236\u4fe1\u53f7\u7684\u884c\u4e3a\uff0c\u54cd\u5e94 OnSignal \u4e8b\u4ef6\u3002\u5728 OnSignal \u4e8b\u4ef6\u4e2d\uff0c\u5982\u679c\u8bbe\u7f6e AHandled \u53c2\u6570\u4e3a true\uff0c\u5c31\u4e0d\u4f1a\u89e6\u53d1\u9ed8\u8ba4\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u54cd\u5e94\u81ea\u5b9a\u4e49\u7684\u4e8b\u4ef6\uff0c\u9996\u5148\u8981\u8c03\u7528 HandleSignal \u4f20\u5165\u81ea\u5df1\u8981\u54cd\u5e94\u7684\u4fe1\u53f7ID\uff0c\u7136\u540e\u5728 OnSignal \u4e2d\u5c31\u53ef\u4ee5\u5f97\u5230\u5177\u4f53\u7684\u4fe1\u53f7\u54cd\u5e94\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u670d\u52a1\u5b89\u88c5\u4e0e\u5378\u8f7d\u3011<\/h4>\n\n\n\n<p>TQConsoleLooper \u5728 Linux \u4e0a\u63d0\u4f9b\u4e86\u670d\u52a1\u7684\u5b89\u88c5\u548c\u5378\u8f7d\u529f\u80fd\u3002\u7528\u6237\u8fd0\u884c\u65f6\uff0c\u901a\u8fc7\u547d\u4ee4\u884c\u53c2\u6570 -install \u5b89\u88c5\u670d\u52a1\uff0c-uninstall \u6765\u5378\u8f7d\u670d\u52a1\u3002\u5982\u679c\u8981\u505a\u4e3a\u670d\u52a1\uff0c\u4f60\u9700\u8981\u4e3a\u5176\u63d0\u4f9b\u4ee5\u4e0b\u989d\u5916\u5c5e\u6027\u7684\u503c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Name \uff1a\u670d\u52a1\u7684\u540d\u79f0\uff0c\u5728 Linux \u4e2d systemctl \u6216 service \u5bf9\u670d\u52a1\u63a7\u5236\u65f6\u9700\u8981\u3002<\/li><li>Title : \u670d\u52a1\u7684\u6807\u9898\u63cf\u8ff0\uff0c\u7528\u6765\u8bf4\u660e\u670d\u52a1\u662f\u5e72\u4ec0\u4e48\u7684\uff0c\u6ce8\u518c\u670d\u52a1\u65f6\u4f1a\u5bf9\u5e94\u4e8e\u670d\u52a1\u63cf\u8ff0<\/li><li>BeforeInstall\/AfterInstall\uff1a\u5982\u679c\u4f60\u9700\u8981\u4e3a\u670d\u52a1\u5b89\u88c5\u6dfb\u52a0\u989d\u5916\u7684\u5c5e\u6027\u63a7\u5236\uff0c\u6bd4\u5982\u4f9d\u8d56\u5173\u7cfb\u7b49\uff0c\u9700\u8981\u5728 BeforeInstall \u91cc\u5bf9\u53c2\u6570\u8fdb\u884c\u63a7\u5236\u3002\u5f53\u670d\u52a1\u5b89\u88c5\u5b8c\u6210\u542f\u52a8\u540e\uff0c\u4f1a\u89e6\u53d1 AfterInstall \u4e8b\u4ef6\u3002<\/li><li>BeforeUninstall\/AfterUninstall\uff1a\u5378\u8f7d\u670d\u52a1\u65f6\u89e6\u53d1\uff0c\u9ed8\u8ba4\u5378\u8f7d\u53ea\u662f\u505c\u6b62\u670d\u52a1\uff0c\u5e76\u4e14\u5220\u9664\u670d\u52a1\u6ce8\u518c\u5355\u5143\u81ea\u8eab\uff0c\u4f60\u9700\u8981\u989d\u5916\u5904\u7406\u4ee5\u5220\u9664\u670d\u52a1\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684\u5176\u5b83\u6587\u4ef6\u3002<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u989d\u5916\u7684\u4e8b\u4ef6\u53ca\u5c5e\u6027\u3011<\/h4>\n\n\n\n<p>1\u3001 \u5982\u679c\u5728\u5916\u90e8\u8981\u7ed3\u675f\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u5411\u8fdb\u7a0b\u53d1\u9001 KILL\/QUIT\/ABRT \u4fe1\u53f7\uff08\u524d\u63d0\u672a\u91cd\u8f7d\uff09\u3002 \u5982\u679c\u7a0b\u5e8f\u5185\u7ed3\u675f\u81ea\u8eab\uff0c\u5219\u8c03\u7528 Terminate \u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u80fd\u591f\u8ba9\u7a0b\u5e8f\u201c\u4f18\u96c5\u201d\u7684\u9000\u51fa<\/p>\n\n\n\n<p>2\u3001\u5728\u7528\u6237\u8c03\u7528 Terminate \u65f6\uff0cTerminated \u5c5e\u6027\u4f1a\u88ab\u8bbe\u7f6e\u4e3a true\u3002<\/p>\n\n\n\n<p>3\u3001TerminateOnException \u5c5e\u6027\u7528\u4e8e\u5728\u53d1\u751f\u672a\u6355\u83b7\u7684\u5f02\u5e38\u65f6\uff0c\u81ea\u52a8\u4e2d\u6b62\u7a0b\u5e8f\u7684\u6267\u884c\u3002<\/p>\n\n\n\n<p>4\u3001BeforeRun \u4e8b\u4ef6\u5728\u8c03\u7528 Run \u6267\u884c\u76f8\u5173\u4ee3\u7801\u4e4b\u524d\u89e6\u53d1\u3002\u5b83\u662f Run \u51fd\u6570\u7684\u7b2c\u4e00\u53e5\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>5\u3001OnTerminate \u4e8b\u4ef6\u5728\u5e94\u7528\u5373\u5c06\u9000\u51fa\u65f6\u89e6\u53d1\u3002<\/p>\n\n\n\n<p>6\u3001DaemonProcessId \u662f\u5b88\u62a4\u5b50\u8fdb\u7a0b\u7684\u8fdb\u7a0bID\uff0c\u5982\u679c\u5f53\u524d\u8fdb\u7a0b\u662f\u521d\u59cb\u5316\u521b\u5efa\u7684\u7236\u8fdb\u7a0b\u5219\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684ID\uff0c\u5426\u5219\uff0c\u8fd4\u56de\u5f53\u524d\u8fdb\u7a0bID\u3002\u5982\u679c IsDaemon \u5c5e\u6027\u4e0d\u4e3a true\uff0c\u5219\u59cb\u7ec8\u8fd4\u56de 0\u3002<\/p>\n\n\n\n<p>7\u3001Current \u7c7b\u5c5e\u6027\uff0c\u8be5\u5c5e\u6027\u7528\u6765\u8bbf\u95ee\u5168\u5c40\u552f\u4e00\u7684 TQConsoleLooper \u5b9e\u4f8b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u591a\u7ebf\u7a0b\u5b88\u62a4\u8fdb\u7a0b\u3011<\/h4>\n\n\n\n<p>\u7531\u4e8e\u5b88\u62a4\u8fdb\u7a0b\u662f\u901a\u8fc7 fork \u6a21\u5f0f\u521b\u5efa\u7684\u3002\u800c fork \u7684\u9650\u5236\u8981\u6c42\u5f53\u524d\u7236\u8fdb\u7a0b\u5904\u4e8e\u5355\u7ebf\u7a0b\u6a21\u5f0f\uff0c\u6240\u4ee5\u5fc5\u9700\u4fdd\u8bc1fork\u6267\u884c\u65f6\uff0c\u6ca1\u6709\u989d\u5916\u7684\u7ebf\u7a0b\u5728\u6267\u884c\u3002QLog\/QWorker \u5df2\u7ecf\u9488\u5bf9\u8fd9\u79cd\u9700\u6c42\u505a\u4e86\u9488\u5bf9\u6027\u7684\u8c03\u6574\uff0c\u4f46\u4ecd\u8981\u4fdd\u8bc1\u4e0d\u8981\u6ce8\u518c\u65f6\u63d0\u4ea4\u4f5c\u4e1a\uff0c\u5426\u5219\u5b88\u62a4\u8fdb\u7a0b\u91cc\u8fd9\u4e9b\u7ebf\u7a0b\u90fd\u5c06\u5931\u6548\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u7528\u6237\u81ea\u5df1\u7684\u5b88\u62a4\u5bf9\u8c61\u7c7b\u578b\uff0c\u5e94\u7ee7\u627f\u81ea TQBaseConsoleWorker \u5e76\u4e14\u8c03\u7528 RegisterWorker \u6ce8\u518c\u7528\u6237\u81ea\u5df1\u7684\u7c7b\u578b\u3002\u7528\u6237\u81ea\u5df1\u7684\u7c7b\u578b\u5728\u5bf9\u5e94\u7684 Startup \u5b8c\u6210\u521d\u59cb\u5316\uff0c\u5728 Cleanup \u91cc\u5b8c\u6210\u6e05\u7406\u3002TQConsoleLooper \u7684 Run \u65b9\u6cd5\u5c06\u4f1a\u89e6\u53d1\u5b83\u4eec\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u5176\u5b83\u3011<\/h4>\n\n\n\n<p>\u6ca1\u60f3\u5230\uff0c\u6709\u5565\u8865\u5145\u7684\u5c06\u6765\u518d\u8bf4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728 Delphi  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,9],"tags":[132,774,393],"class_list":["post-5116","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","tag-linux","tag-774","tag-393"],"views":3498,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5116"}],"version-history":[{"count":3,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5116\/revisions"}],"predecessor-version":[{"id":5132,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5116\/revisions\/5132"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}