{"id":408,"date":"2023-08-04T17:54:20","date_gmt":"2023-08-04T09:54:20","guid":{"rendered":"http:\/\/idc.birk.cn\/?p=408"},"modified":"2023-08-04T17:54:20","modified_gmt":"2023-08-04T09:54:20","slug":"linux%e7%9a%84-serivice%e6%96%87%e4%bb%b6%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/idc.birk.cn\/?p=408","title":{"rendered":"Linux\u7684.serivice\u6587\u4ef6\u4ecb\u7ecd"},"content":{"rendered":"<p>\u4e00\u3001\u4ec0\u4e48\u662f.service\u6587\u4ef6\uff1f<\/p>\n<p>linux\u4e2d.servic\u6587\u4ef6\u662f\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u8fc7systemctl\u8fdb\u884c\u64cd\u4f5c\u3002<br \/>\n\u5b58\u653e\u4f4d\u7f6e\uff1a\/usr\/lib\/systemd\/system<\/p>\n<p>\u4e8c\u3001\u914d\u7f6e\u8bf4\u660e<\/p>\n<p>\u901a\u5e38\u5728\uff0cservice\u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u4e09\u4e2a\u90e8\u5206\uff0c\u5206\u522b\u4e3a\uff1a<br \/>\n\u4e00\u3001[Unit]:\u63a7\u5236\u90e8\u5206\uff0c\u8868\u793a\u542f\u52a8\u987a\u5e8f\u548c\u4f9d\u8d56\u5173\u7cfb<br \/>\n\u90e8\u5206\u5b57\u6bb5<br \/>\nDescription\uff1a\u7b80\u77ed\u63cf\u8ff0<br \/>\nDocumentation\uff1a\u6587\u6863\u5730\u5740<br \/>\nRequires\uff1a\u5f53\u524d Unit \u4f9d\u8d56\u7684\u5176\u4ed6 Unit\uff0c\u5982\u679c\u5b83\u4eec\u6ca1\u6709\u8fd0\u884c\uff0c\u5f53\u524d Unit \u4f1a\u542f\u52a8\u5931\u8d25<br \/>\nWants\uff1a\u4e0e\u5f53\u524d Unit \u914d\u5408\u7684\u5176\u4ed6 Unit\uff0c\u5982\u679c\u5b83\u4eec\u6ca1\u6709\u8fd0\u884c\uff0c\u5f53\u524d Unit \u4e0d\u4f1a\u542f\u52a8\u5931\u8d25<br \/>\nBindsTo\uff1a\u4e0eRequires\u7c7b\u4f3c\uff0c\u5b83\u6307\u5b9a\u7684 Unit \u5982\u679c\u9000\u51fa\uff0c\u4f1a\u5bfc\u81f4\u5f53\u524d Unit \u505c\u6b62\u8fd0\u884c<br \/>\nBefore\uff1a\u5982\u679c\u8be5\u5b57\u6bb5\u6307\u5b9a\u7684 Unit \u4e5f\u8981\u542f\u52a8\uff0c\u90a3\u4e48\u5fc5\u987b\u5728\u5f53\u524d Unit \u4e4b\u540e\u542f\u52a8<br \/>\nAfter\uff1a\u5982\u679c\u8be5\u5b57\u6bb5\u6307\u5b9a\u7684 Unit \u4e5f\u8981\u542f\u52a8\uff0c\u90a3\u4e48\u5fc5\u987b\u5728\u5f53\u524d Unit \u4e4b\u524d\u542f\u52a8<br \/>\nConflicts\uff1a\u8fd9\u91cc\u6307\u5b9a\u7684 Unit \u4e0d\u80fd\u4e0e\u5f53\u524d Unit \u540c\u65f6\u8fd0\u884c<br \/>\nCondition...\uff1a\u5f53\u524d Unit \u8fd0\u884c\u5fc5\u987b\u6ee1\u8db3\u7684\u6761\u4ef6\uff0c\u5426\u5219\u4e0d\u4f1a\u8fd0\u884c<br \/>\nAssert...\uff1a\u5f53\u524d Unit \u8fd0\u884c\u5fc5\u987b\u6ee1\u8db3\u7684\u6761\u4ef6\uff0c\u5426\u5219\u4f1a\u62a5\u542f\u52a8\u5931\u8d25<br \/>\n\u4e8c\u3001[Service]:\u670d\u52a1\u90e8\u5206\uff0c\u8868\u793a\u670d\u52a1\u7684\u5b9a\u4e49<br \/>\n\u90e8\u5206\u5b57\u6bb5\uff1a<br \/>\nType\uff1a\u5b9a\u4e49\u542f\u52a8\u65f6\u7684\u8fdb\u7a0b\u884c\u4e3a\u3002\u5b83\u6709\u4ee5\u4e0b\u51e0\u79cd\u503c\u3002<br \/>\nType=simple\uff1a\u9ed8\u8ba4\u503c\uff0c\u6267\u884cExecStart\u6307\u5b9a\u7684\u547d\u4ee4\uff0c\u542f\u52a8\u4e3b\u8fdb\u7a0b<br \/>\nType=forking\uff1a\u4ee5 fork \u65b9\u5f0f\u4ece\u7236\u8fdb\u7a0b\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u521b\u5efa\u540e\u7236\u8fdb\u7a0b\u4f1a\u7acb\u5373\u9000\u51fa<br \/>\nType=oneshot\uff1a\u4e00\u6b21\u6027\u8fdb\u7a0b\uff0cSystemd \u4f1a\u7b49\u5f53\u524d\u670d\u52a1\u9000\u51fa\uff0c\u518d\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c<br \/>\nType=dbus\uff1a\u5f53\u524d\u670d\u52a1\u901a\u8fc7D-Bus\u542f\u52a8<br \/>\nType=notify\uff1a\u5f53\u524d\u670d\u52a1\u542f\u52a8\u5b8c\u6bd5\uff0c\u4f1a\u901a\u77e5Systemd\uff0c\u518d\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c<br \/>\nType=idle\uff1a\u82e5\u6709\u5176\u4ed6\u4efb\u52a1\u6267\u884c\u5b8c\u6bd5\uff0c\u5f53\u524d\u670d\u52a1\u624d\u4f1a\u8fd0\u884c<br \/>\nExecStart\uff1a\u542f\u52a8\u5f53\u524d\u670d\u52a1\u7684\u547d\u4ee4<br \/>\nExecStartPre\uff1a\u542f\u52a8\u5f53\u524d\u670d\u52a1\u4e4b\u524d\u6267\u884c\u7684\u547d\u4ee4<br \/>\nExecStartPost\uff1a\u542f\u52a8\u5f53\u524d\u670d\u52a1\u4e4b\u540e\u6267\u884c\u7684\u547d\u4ee4<br \/>\nExecReload\uff1a\u91cd\u542f\u5f53\u524d\u670d\u52a1\u65f6\u6267\u884c\u7684\u547d\u4ee4<br \/>\nExecStop\uff1a\u505c\u6b62\u5f53\u524d\u670d\u52a1\u65f6\u6267\u884c\u7684\u547d\u4ee4<br \/>\nExecStopPost\uff1a\u505c\u6b62\u5f53\u5176\u670d\u52a1\u4e4b\u540e\u6267\u884c\u7684\u547d\u4ee4<br \/>\nRestartSec\uff1a\u81ea\u52a8\u91cd\u542f\u5f53\u524d\u670d\u52a1\u95f4\u9694\u7684\u79d2\u6570<br \/>\nRestart\uff1a\u5b9a\u4e49\u4f55\u79cd\u60c5\u51b5 Systemd \u4f1a\u81ea\u52a8\u91cd\u542f\u5f53\u524d\u670d\u52a1\uff0c\u53ef\u80fd\u7684\u503c\u5305\u62ecalways\uff08\u603b\u662f\u91cd\u542f\uff09\u3001on-success\u3001on-failure\u3001on-abnormal\u3001on-abort\u3001on-watchdog<br \/>\nTimeoutSec\uff1a\u5b9a\u4e49 Systemd \u505c\u6b62\u5f53\u524d\u670d\u52a1\u4e4b\u524d\u7b49\u5f85\u7684\u79d2\u6570<br \/>\nEnvironment\uff1a\u6307\u5b9a\u73af\u5883\u53d8\u91cf<br \/>\n\u4e09\u3001[Install]:\u5b89\u88c5\u90e8\u5206\uff0c\u8868\u793a\u600e\u4e48\u8fdb\u884c\u5b89\u88c5\u914d\u7f6e<br \/>\n\u90e8\u5206\u5b57\u6bb5<br \/>\nWantedBy\uff1a\u5b83\u7684\u503c\u662f\u4e00\u4e2a\u6216\u591a\u4e2a Target\uff0c\u5f53\u524d Unit \u6fc0\u6d3b\u65f6\uff08enable\uff09\u7b26\u53f7\u94fe\u63a5\u4f1a\u653e\u5165\/etc\/systemd\/system\u76ee\u5f55\u4e0b\u9762\u4ee5 Target \u540d + .wants\u540e\u7f00\u6784\u6210\u7684\u5b50\u76ee\u5f55\u4e2d<br \/>\nRequiredBy\uff1a\u5b83\u7684\u503c\u662f\u4e00\u4e2a\u6216\u591a\u4e2a Target\uff0c\u5f53\u524d Unit \u6fc0\u6d3b\u65f6\uff0c\u7b26\u53f7\u94fe\u63a5\u4f1a\u653e\u5165\/etc\/systemd\/system\u76ee\u5f55\u4e0b\u9762\u4ee5 Target \u540d + .required\u540e\u7f00\u6784\u6210\u7684\u5b50\u76ee\u5f55\u4e2d<br \/>\nAlias\uff1a\u5f53\u524d Unit \u53ef\u7528\u4e8e\u542f\u52a8\u7684\u522b\u540d<br \/>\nAlso\uff1a\u5f53\u524d Unit \u6fc0\u6d3b\uff08enable\uff09\u65f6\uff0c\u4f1a\u88ab\u540c\u65f6\u6fc0\u6d3b\u7684\u5176\u4ed6 Unit<br \/>\nDefaultInstance\uff1a\u5b9e\u4f8b\u5355\u5143\u7684\u9650\u5236\uff0c\u8fd9\u4e2a\u9009\u9879\u6307\u5b9a\u5982\u679c\u5355\u5143\u88ab\u5141\u8bb8\u8fd0\u884c\u9ed8\u8ba4\u7684\u5b9e\u4f8b<br \/>\nWantedBy\u5b57\u6bb5\uff1a\u8868\u793a\u8be5\u670d\u52a1\u6240\u5728\u7684 Target<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4ec0\u4e48\u662f.service\u6587\u4ef6\uff1f linux\u4e2d.servic\u6587\u4ef6\u662f\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u8fc7systemctl\u8fdb\u884c\u64cd\u4f5c\u3002 \u5b58\u653e\u4f4d\u7f6e\uff1a\/usr\/lib\/systemd\/system \u4e8c\u3001\u914d\u7f6e\u8bf4\u660e \u901a\u5e38\u5728\uff0cservice\u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u4e09\u4e2a\u90e8\u5206\uff0c\u5206\u522b\u4e3a [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,21],"tags":[6],"topic":[37],"class_list":["post-408","post","type-post","status-publish","format-standard","hentry","category-linux","category-21","tag-linux","topic-linux"],"_links":{"self":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts\/408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=408"}],"version-history":[{"count":1,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts\/408\/revisions"}],"predecessor-version":[{"id":409,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=\/wp\/v2\/posts\/408\/revisions\/409"}],"wp:attachment":[{"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=408"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/idc.birk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}