{"id":381,"date":"2023-11-26T21:45:32","date_gmt":"2023-11-26T13:45:32","guid":{"rendered":"http:\/\/8.141.4.74\/?p=381"},"modified":"2024-03-28T13:39:11","modified_gmt":"2024-03-28T05:39:11","slug":"linux%e6%9c%8d%e5%8a%a1%e6%96%87%e4%bb%b6%e7%9a%84%e7%bc%96%e5%86%99","status":"publish","type":"post","link":"http:\/\/8.141.4.74\/?p=381","title":{"rendered":"Linux\u670d\u52a1\u6587\u4ef6\u7684\u7f16\u5199"},"content":{"rendered":"<h1>Service\u6587\u4ef6<\/h1>\n<p>\u670d\u52a1\u6587\u4ef6\u662fSystemd\u7528\u4e8e\u63a7\u5236\u548c\u7ba1\u7406\u7cfb\u7edf\u670d\u52a1\u7684\u4e00\u79cd\u65b9\u5f0f\u3002\u670d\u52a1\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e<code>\/etc\/systemd\/system<\/code>\u6216<code>\/usr\/lib\/systemd\/system<\/code>\u76ee\u5f55\u4e0b\uff0c\u5e76\u4e14\u5176\u6587\u4ef6\u6269\u5c55\u540d\u4e3a<code>.service<\/code>\u3002\u4e0b\u9762\u6211\u5c06\u5c55\u793a\u4e00\u4e2a\u57fa\u672c\u7684\u670d\u52a1\u6587\u4ef6\u6a21\u677f\uff0c\u5e76\u5bf9\u5176\u7ec4\u6210\u90e8\u5206\u8fdb\u884c\u89e3\u91ca\uff1a<\/p>\n<pre><code class=\"language-bash\">[Unit]\nDescription=My Sample Service\nAfter=network.target\n\n[Service]\nType=simple\nExecStart=\/usr\/bin\/mydaemon\nRestart=on-failure\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<ol>\n<li><code>[Unit]<\/code> \u90e8\u5206\uff1a\u8fd9\u4e2a\u90e8\u5206\u5305\u542b\u4e86\u670d\u52a1\u7684\u63cf\u8ff0\u548c\u4f9d\u8d56\u5173\u7cfb\u3002\n<ul>\n<li><code>Description<\/code>: \u8fd9\u662f\u5bf9\u670d\u52a1\u7684\u7b80\u5355\u63cf\u8ff0\u3002<\/li>\n<li><code>After<\/code>: \u8fd9\u662f\u4e00\u4e2a\u5b9a\u4e49\u4e86\u670d\u52a1\u542f\u52a8\u987a\u5e8f\u7684\u9009\u9879\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u7684\u670d\u52a1\u5c06\u5728\u7f51\u7edc\u76ee\u6807\uff08<code>network.target<\/code>\uff09\u4e4b\u540e\u542f\u52a8\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u7684\u670d\u52a1\u9700\u8981\u7f51\u7edc\u6b63\u5e38\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>[Service]<\/code> \u90e8\u5206\uff1a\u8fd9\u4e2a\u90e8\u5206\u63cf\u8ff0\u4e86\u670d\u52a1\u7684\u8fd0\u884c\u53c2\u6570\u3002\n<ul>\n<li><code>Type<\/code>: \u8fd9\u4e2a\u9009\u9879\u5b9a\u4e49\u4e86\u670d\u52a1\u7684\u542f\u52a8\u7c7b\u578b\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u9009\u62e9\u4e86<code>simple<\/code>\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u7684\u8fdb\u7a0b\u5c06\u4f1a\u5728<code>ExecStart<\/code>\u6307\u5b9a\u7684\u547d\u4ee4\u540e\u53f0\u8fd0\u884c\uff0c\u5e76\u4e14\u8fd9\u4e2a\u547d\u4ee4\u5c06\u4f1a\u7acb\u5373\u8fd4\u56de\uff0c\u800c\u4e0d\u9700\u8981\u7b49\u5f85\u3002<\/li>\n<li><code>ExecStart<\/code>: \u8fd9\u4e2a\u9009\u9879\u6307\u5b9a\u4e86\u542f\u52a8\u670d\u52a1\u65f6\u8981\u8fd0\u884c\u7684\u547d\u4ee4\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u542f\u52a8\u4e86\u4e00\u4e2a\u540d\u4e3a<code>mydaemon<\/code>\u7684\u7a0b\u5e8f\u3002<\/li>\n<li><code>Restart<\/code>: \u8fd9\u4e2a\u9009\u9879\u6307\u5b9a\u4e86\u5728\u670d\u52a1\u51fa\u73b0\u6545\u969c\u65f6\u662f\u5426\u81ea\u52a8\u91cd\u542f\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u9009\u62e9\u4e86<code>on-failure<\/code>\uff0c\u8fd9\u610f\u5473\u7740\u53ea\u6709\u5f53\u670d\u52a1\u56e0\u975e\u6b63\u5e38\u539f\u56e0\u9000\u51fa\uff08\u4f8b\u5982\uff0c\u8fdb\u7a0b\u5d29\u6e83\u6216\u8005\u88ab\u6740\u6b7b\uff09\u65f6\uff0c\u670d\u52a1\u624d\u4f1a\u88ab\u81ea\u52a8\u91cd\u542f\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>[Install]<\/code> \u90e8\u5206\uff1a\u8fd9\u4e2a\u90e8\u5206\u5b9a\u4e49\u4e86\u670d\u52a1\u5982\u4f55\u88ab&quot;\u5b89\u88c5&quot;\uff0c\u5373\u5982\u4f55\u88ab\u5173\u8054\u5230\u67d0\u4e2a\u76ee\u6807\u3002\n<ul>\n<li><code>WantedBy<\/code>: \u8fd9\u4e2a\u9009\u9879\u5b9a\u4e49\u4e86\u670d\u52a1\u5e94\u88ab\u54ea\u4e2a\u76ee\u6807\u9700\u8981\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u9009\u62e9\u4e86<code>multi-user.target<\/code>\uff0c\u8fd9\u610f\u5473\u7740\u5728\u591a\u7528\u6237\u6a21\u5f0f\u4e0b\uff0c\u6211\u4eec\u7684\u670d\u52a1\u5c06\u88ab\u542f\u52a8\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u6ce8\u610f\uff0c\u4ee5\u4e0a\u53ea\u662f\u57fa\u672c\u6a21\u677f\u3002\u6839\u636e\u670d\u52a1\u7684\u5177\u4f53\u9700\u6c42\uff0c\u53ef\u80fd\u9700\u8981\u66f4\u590d\u6742\u7684\u914d\u7f6e\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5b9a\u4e49\u66f4\u591a\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u6216\u8005\u8bbe\u7f6e\u7279\u5b9a\u7684\u7528\u6237\u6216\u7ec4\u6765\u8fd0\u884c\u670d\u52a1\uff0c\u7b49\u7b49\u3002\u4f60\u53ef\u4ee5\u5728<code>man systemd.service<\/code>\u4e2d\u67e5\u770b\u66f4\u591a\u5173\u4e8e\u670d\u52a1\u6587\u4ef6\u7684\u9009\u9879\u548c\u914d\u7f6e\u4fe1\u606f\u3002<\/p>\n<p>\u521b\u5efa\u6216\u4fee\u6539\u4e86\u670d\u52a1\u6587\u4ef6\u540e\uff0c\u9700\u8981\u8fd0\u884c<code>systemctl daemon-reload<\/code>\u547d\u4ee4\uff0c\u8ba9Systemd\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>systemctl start<\/code>\u3001<code>systemctl stop<\/code>\u3001<code>systemctl restart<\/code>\u3001<code>systemctl status<\/code>\u7b49\u547d\u4ee4\u6765\u63a7\u5236\u670d\u52a1\u3002\u5982\u679c\u4f60\u60f3\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8\u670d\u52a1\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>systemctl enable<\/code>\u547d\u4ee4\u3002<\/p>\n<p>\u670d\u52a1\u6587\u4ef6\u7684\u914d\u7f6e\u9009\u9879\u975e\u5e38\u591a\uff0c\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u53c2\u6570\uff1a<\/p>\n<ol>\n<li>\n<p><code>[Unit]<\/code> \u90e8\u5206\uff1a<\/p>\n<ul>\n<li><code>Description<\/code>: \u670d\u52a1\u7684\u7b80\u8981\u63cf\u8ff0\u3002<\/li>\n<li><code>Documentation<\/code>: \u670d\u52a1\u7684\u6587\u6863\u94fe\u63a5\uff0c\u53ef\u4ee5\u662fman\u9875\u9762\u6216\u8005http\u94fe\u63a5\u3002<\/li>\n<li><code>After<\/code>, <code>Before<\/code>: \u7528\u4e8e\u5b9a\u4e49\u670d\u52a1\u542f\u52a8\u7684\u987a\u5e8f\u3002<\/li>\n<li><code>Requires<\/code>, <code>Wants<\/code>: \u5b9a\u4e49\u670d\u52a1\u542f\u52a8\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<code>Requires<\/code>\u5b9a\u4e49\u4e86\u5f3a\u4f9d\u8d56\uff0c\u5982\u679c\u4f9d\u8d56\u7684\u670d\u52a1\u672a\u542f\u52a8\uff0c\u5f53\u524d\u670d\u52a1\u5c31\u4e0d\u4f1a\u542f\u52a8\uff1b<code>Wants<\/code>\u5b9a\u4e49\u4e86\u5f31\u4f9d\u8d56\uff0c\u5982\u679c\u4f9d\u8d56\u7684\u670d\u52a1\u672a\u542f\u52a8\uff0c\u5f53\u524d\u670d\u52a1\u4ecd\u7136\u4f1a\u5c1d\u8bd5\u542f\u52a8\u3002<\/li>\n<li><code>Conflicts<\/code>: \u6307\u5b9a\u4e0e\u5f53\u524d\u670d\u52a1\u51b2\u7a81\u7684\u670d\u52a1\uff0c\u5982\u679c\u6307\u5b9a\u7684\u670d\u52a1\u6b63\u5728\u8fd0\u884c\uff0c\u90a3\u4e48\u5f53\u524d\u670d\u52a1\u5c06\u65e0\u6cd5\u542f\u52a8\u3002<\/li>\n<li><code>ConditionPathExists<\/code>, <code>ConditionPathIsDirectory<\/code>, <code>ConditionFileNotEmpty<\/code>, <code>ConditionDirectoryNotEmpty<\/code>, <code>ConditionPathIsSymbolicLink<\/code>, <code>ConditionPathIsMountPoint<\/code>, <code>ConditionPathIsReadWrite<\/code>: \u8fd9\u4e9b\u6761\u4ef6\u9009\u9879\u5141\u8bb8\u5728\u5404\u79cd\u6587\u4ef6\u6216\u76ee\u5f55\u6761\u4ef6\u6210\u7acb\u65f6\u542f\u52a8\u670d\u52a1\u3002<\/li>\n<li><code>ConditionKernelCommandLine<\/code>, <code>ConditionArchitecture<\/code>, <code>ConditionVirtualization<\/code>, <code>ConditionSecurity<\/code>, <code>ConditionCapability<\/code>, <code>ConditionACPower<\/code>, <code>ConditionNeedsUpdate<\/code>, <code>ConditionFirstBoot<\/code>, <code>ConditionPathExistsGlob<\/code>: \u8fd9\u4e9b\u6761\u4ef6\u9009\u9879\u5141\u8bb8\u5728\u5404\u79cd\u7cfb\u7edf\u548c\u73af\u5883\u6761\u4ef6\u6210\u7acb\u65f6\u542f\u52a8\u670d\u52a1\u3002<\/li>\n<li><code>DefaultDependencies<\/code>: \u8bbe\u7f6e\u662f\u5426\u4e3a\u670d\u52a1\u81ea\u52a8\u751f\u6210\u9ed8\u8ba4\u4f9d\u8d56\u5173\u7cfb\u3002<\/li>\n<li><code>RequiresMountsFor<\/code>: \u6307\u5b9a\u670d\u52a1\u6240\u9700\u7684\u6302\u8f7d\u70b9.<\/li>\n<li><code>Requires<\/code>: \u5217\u51fa\u5728\u542f\u52a8\u6b64\u670d\u52a1\u4e4b\u524d\u9700\u8981\u542f\u52a8\u7684\u5176\u4ed6\u670d\u52a1\u6216\u5957\u63a5\u5b57\u3002<\/li>\n<li><code>Wants<\/code>: \u5217\u51fa\u5728\u542f\u52a8\u6b64\u670d\u52a1\u4e4b\u524d\u6700\u597d\u542f\u52a8\u7684\u5176\u4ed6\u670d\u52a1\uff0c\u4f46\u5373\u4f7f\u8fd9\u4e9b\u670d\u52a1\u6ca1\u6709\u542f\u52a8\uff0c\u6b64\u670d\u52a1\u4e5f\u53ef\u4ee5\u8fd0\u884c\u3002<\/li>\n<li><code>After<\/code>: \u6307\u5b9a\u6b64\u670d\u52a1\u5e94\u5728\u54ea\u4e9b\u670d\u52a1\u4e4b\u540e\u542f\u52a8\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code>[Service]<\/code> \u90e8\u5206\uff1a<\/p>\n<ul>\n<li>\n<p><code>Type<\/code>: \u5b9a\u4e49\u670d\u52a1\u7684\u7c7b\u578b\u3002\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\n<p><code>simple<\/code>: \u9ed8\u8ba4\u503c\uff0c\u4e3b\u8fdb\u7a0b\u4f1a\u7acb\u5373\u542f\u52a8\u5e76\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p><code>forking<\/code>: \u4e3b\u8fdb\u7a0b\u4f1a\u542f\u52a8\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u7136\u540e\u81ea\u5df1\u9000\u51fa\u3002<\/p>\n<\/li>\n<li>\n<p><code>oneshot<\/code>: \u4e3b\u8fdb\u7a0b\u4f1a\u8fd0\u884c\uff0c\u5b8c\u6210\u4efb\u52a1\u540e\u9000\u51fa\u3002\u901a\u5e38\u7528\u4e8e\u4e00\u6b21\u6027\u4efb\u52a1\u3002<\/p>\n<\/li>\n<li>\n<p><code>notify<\/code>: \u4e3b\u8fdb\u7a0b\u4f1a\u542f\u52a8\u5e76\u901a\u77e5systemd\u4f55\u65f6\u5176\u5b9e\u9645\u4e0a\u5df2\u7ecf\u5b8c\u6210\u4e86\u542f\u52a8\u8fc7\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p><code>idle<\/code>: \u4e0esimple\u7c7b\u578b\u7c7b\u4f3c\uff0c\u4f46\u53ea\u6709\u5728\u5176\u4ed6\u4efb\u52a1\u90fd\u5b8c\u6210\u540e\u624d\u4f1a\u542f\u52a8\u670d\u52a1\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code>ExecStart<\/code>: \u5b9a\u4e49\u542f\u52a8\u670d\u52a1\u65f6\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/p>\n<\/li>\n<li>\n<p><code>ExecStop<\/code>: \u5b9a\u4e49\u505c\u6b62\u670d\u52a1\u65f6\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/p>\n<\/li>\n<li>\n<p><code>ExecReload<\/code>: \u5b9a\u4e49\u91cd\u65b0\u52a0\u8f7d\u670d\u52a1\u914d\u7f6e\u65f6\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/p>\n<\/li>\n<li>\n<p><code>Restart<\/code>: \u5b9a\u4e49\u670d\u52a1\u4f55\u65f6\u81ea\u52a8\u91cd\u542f\u3002\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u9009\u9879\uff1a<\/p>\n<ul>\n<li><code>no<\/code>: \u9ed8\u8ba4\u503c\uff0c\u4e0d\u81ea\u52a8\u91cd\u542f\u3002<\/li>\n<li><code>on-success<\/code>: \u5f53\u670d\u52a1\u8fdb\u7a0b\u6b63\u5e38\u7ed3\u675f\u65f6\u91cd\u542f\u3002<\/li>\n<li><code>on-failure<\/code>: \u5f53\u670d\u52a1\u8fdb\u7a0b\u5f02\u5e38\u7ed3\u675f\u65f6\u91cd\u542f\u3002<\/li>\n<li><code>on-abnormal<\/code>: \u5728\u8fdb\u7a0b\u8d85\u65f6\u3001\u88ab\u4fe1\u53f7\u6740\u6b7b\u6216\u8005\u6838\u5fc3\u8f6c\u50a8\u65f6\u91cd\u542f\u3002<\/li>\n<li><code>on-abort<\/code>: \u5728\u8fdb\u7a0b\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\u88ab\u7cfb\u7edf\u6740\u6b7b\u65f6\u91cd\u542f\u3002<\/li>\n<li><code>always<\/code>: \u65e0\u8bba\u4f55\u79cd\u60c5\u51b5\u90fd\u91cd\u542f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code>User<\/code>, <code>Group<\/code>: \u6307\u5b9a\u8fd0\u884c\u670d\u52a1\u7684\u7528\u6237\u548c\u7ec4\u3002<\/p>\n<\/li>\n<li>\n<p><code>Environment<\/code>, <code>EnvironmentFile<\/code>: \u5b9a\u4e49\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p><code>WorkingDirectory<\/code>: \u6307\u5b9a\u670d\u52a1\u542f\u52a8\u65f6\u7684\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n<\/li>\n<li>\n<p><code>Nice<\/code>: \u8bbe\u7f6e\u670d\u52a1\u7684\u4f18\u5148\u7ea7\u3002\u8fd9\u4e2a\u503c\u4ece -20\uff08\u6700\u9ad8\u4f18\u5148\u7ea7\uff09\u5230 19\uff08\u6700\u4f4e\u4f18\u5148\u7ea7\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>LimitNOFILE<\/code>: \u8bbe\u7f6e\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6700\u5927\u6570\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p><code>LimitNPROC<\/code>: \u8bbe\u7f6e\u8fdb\u7a0b\u53ef\u4ee5\u4f7f\u7528\u7684\u6700\u5927\u6570\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p><code>StandardOutput<\/code>, <code>StandardError<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u63a7\u5236\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u7684\u5904\u7406\u65b9\u5f0f\u3002\u53ef\u4ee5\u8bbe\u7f6e\u4e3a <code>inherit<\/code>\uff08\u9ed8\u8ba4\u503c\uff0c\u4f7f\u7528\u7cfb\u7edf\u9ed8\u8ba4\u8bbe\u7f6e\uff09\uff0c<code>null<\/code>\uff08\u4e22\u5f03\u8f93\u51fa\uff09\uff0c<code>tty<\/code>\uff08\u8f93\u51fa\u5230tty\uff0c\u5982\u679c\u6709\u7684\u8bdd\uff09\uff0c<code>journal<\/code>\uff08\u8f93\u51fa\u5230\u7cfb\u7edf\u65e5\u5fd7\uff09\uff0c<code>syslog<\/code>\uff08\u8f93\u51fa\u5230syslog\uff09\uff0c<code>kmsg<\/code>\uff08\u8f93\u51fa\u5230\u5185\u6838\u6d88\u606f\u7f13\u51b2\u533a\uff09\uff0c\u6216\u8005 <code>file:path<\/code>\uff08\u8f93\u51fa\u5230\u6307\u5b9a\u7684\u6587\u4ef6\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>TimeoutStartSec<\/code>, <code>TimeoutStopSec<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u8bbe\u7f6e\u670d\u52a1\u542f\u52a8\u548c\u505c\u6b62\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p><code>ExecStartPre<\/code>, <code>ExecStartPost<\/code>: \u8fd9\u4e9b\u9009\u9879\u6307\u5b9a\u5728<code>ExecStart<\/code>\u547d\u4ee4\u6267\u884c\u524d\u540e\u8fd0\u884c\u7684\u547d\u4ee4\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>ExecStartPre<\/code>\u6765\u68c0\u67e5\u914d\u7f6e\u6587\u4ef6\u7684\u6709\u6548\u6027\u6216\u521b\u5efa\u5fc5\u8981\u7684\u4e34\u65f6\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p><code>OOMScoreAdjust<\/code>: \u8c03\u6574\u670d\u52a1\u8fdb\u7a0b\u7684OOM\uff08Out Of Memory\uff0c\u5185\u5b58\u4e0d\u8db3\uff09\u5f97\u5206\u3002\u8fd9\u4e2a\u503c\u7684\u8303\u56f4\u662f-1000\uff08\u6c38\u8fdc\u4e0d\u88ab\u6740\u6b7b\uff09\u52301000\uff08\u9996\u5148\u88ab\u6740\u6b7b\uff09\u3002\u9ed8\u8ba4\u503c\u662f0\u3002<\/p>\n<\/li>\n<li>\n<p><code>LimitCPU<\/code>, <code>LimitFSIZE<\/code>, <code>LimitDATA<\/code>, <code>LimitSTACK<\/code>, <code>LimitCORE<\/code>, <code>LimitRSS<\/code>, <code>LimitNPROC<\/code>, <code>LimitNOFILE<\/code>, <code>LimitAS<\/code>, <code>LimitLOCKS<\/code>, <code>LimitSIGPENDING<\/code>, <code>LimitMSGQUEUE<\/code>, <code>LimitNICE<\/code>, <code>LimitRTPRIO<\/code>, <code>LimitRTTIME<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u9650\u5236\u670d\u52a1\u8fdb\u7a0b\u53ef\u4ee5\u4f7f\u7528\u7684\u5404\u79cd\u8d44\u6e90\u7684\u6570\u91cf\u6216\u5927\u5c0f\u3002<\/p>\n<\/li>\n<li>\n<p><code>IOSchedulingClass<\/code>, <code>IOSchedulingPriority<\/code>, <code>CPUSchedulingPolicy<\/code>, <code>CPUSchedulingPriority<\/code>, <code>CPUSchedulingResetOnFork<\/code>, <code>CPUAffinity<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u63a7\u5236\u670d\u52a1\u8fdb\u7a0b\u7684I\/O\u548cCPU\u8c03\u5ea6\u3002<\/p>\n<\/li>\n<li>\n<p><code>ProtectSystem<\/code>, <code>ProtectHome<\/code>, <code>PrivateTmp<\/code>, <code>PrivateDevices<\/code>, <code>PrivateNetwork<\/code>, <code>InaccessibleDirectories<\/code>, <code>ReadOnlyDirectories<\/code>, <code>ReadWriteDirectories<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u63d0\u9ad8\u670d\u52a1\u8fdb\u7a0b\u7684\u5b89\u5168\u6027\uff0c\u901a\u8fc7\u9650\u5236\u8fdb\u7a0b\u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\u3001\u8bbe\u5907\u3001\u7f51\u7edc\u7b49\u8d44\u6e90\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code>[Install]<\/code> \u90e8\u5206\uff1a<\/p>\n<ul>\n<li><code>WantedBy<\/code>, <code>RequiredBy<\/code>: \u5b9a\u4e49\u670d\u52a1\u5b89\u88c5\u7684\u76ee\u6807\u3002<\/li>\n<li><code>Also<\/code>: \u5b9a\u4e49\u4e0e\u6b64\u670d\u52a1\u4e00\u8d77\u5b89\u88c5\u7684\u5176\u4ed6\u5355\u4f4d\u3002<\/li>\n<li><code>Alias<\/code>: \u5b9a\u4e49\u670d\u52a1\u7684\u522b\u540d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u5728 <code>[Socket]<\/code> \u90e8\u5206\uff08\u5982\u679c\u670d\u52a1\u4f7f\u7528socket\u6fc0\u6d3b\uff09\uff1a<\/p>\n<ul>\n<li><code>ListenStream<\/code>, <code>ListenDatagram<\/code>, <code>ListenSequentialPacket<\/code>, <code>ListenFIFO<\/code>, <code>ListenSpecial<\/code>, <code>ListenNetlink<\/code>, <code>ListenMessageQueue<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u670d\u52a1\u5e94\u76d1\u542c\u7684\u5404\u79cd\u7c7b\u578b\u7684socket\u3002<\/li>\n<li><code>SocketUser<\/code>, <code>SocketGroup<\/code>, <code>SocketMode<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u8bbe\u7f6esocket\u7684\u6240\u6709\u8005\u3001\u7ec4\u548c\u6743\u9650\u3002<\/li>\n<li><code>Accept<\/code>: \u8fd9\u4e2a\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u662f\u5426\u5e94\u4e3a\u6bcf\u4e2a\u8fde\u63a5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u670d\u52a1\u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<p>\u5728 <code>[Device]<\/code> \u90e8\u5206\uff08\u5982\u679c\u670d\u52a1\u9700\u8981\u8bbf\u95ee\u7279\u5b9a\u8bbe\u5907\uff09\uff1a<\/p>\n<ul>\n<li><code>DeviceAllow<\/code>, <code>DevicePolicy<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u63a7\u5236\u670d\u52a1\u8fdb\u7a0b\u8bbf\u95ee\u8bbe\u5907\u7684\u6743\u9650\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u9009\u9879\u7684\u8be6\u7ec6\u8bf4\u660e\u53ef\u4ee5\u5728 <code>man systemd.exec<\/code>\uff0c<code>man systemd.resource-control<\/code>\uff0c<code>man systemd.socket<\/code>\uff0c<code>man systemd.device<\/code> \u7b49\u624b\u518c\u9875\u4e2d\u627e\u5230\u3002<\/p>\n<p>\u5728Systemd\u7684\u670d\u52a1\u5355\u5143\u6587\u4ef6\u4e2d\uff0c\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u90e8\u5206\u4ee5\u53ca\u76f8\u5173\u9009\u9879\uff1a<\/p>\n<ol>\n<li><code>[Timer]<\/code> \u90e8\u5206\uff1a\u5982\u679c\u4f60\u7684\u670d\u52a1\u9700\u8981\u5b9a\u65f6\u8fd0\u884c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u90e8\u5206\u6765\u8bbe\u7f6e\u5b9a\u65f6\u5668\u3002\n<ul>\n<li><code>OnActiveSec<\/code>, <code>OnBootSec<\/code>, <code>OnStartupSec<\/code>, <code>OnUnitActiveSec<\/code>, <code>OnUnitInactiveSec<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u8bbe\u7f6e\u5b9a\u65f6\u5668\u5728\u7279\u5b9a\u7684\u65f6\u95f4\u70b9\u6fc0\u6d3b\u3002<\/li>\n<li><code>OnCalendar<\/code>: \u8fd9\u4e2a\u9009\u9879\u7528\u4e8e\u8bbe\u7f6e\u5b9a\u65f6\u5668\u5728\u67d0\u4e2a\u65e5\u5386\u65f6\u95f4\u6fc0\u6d3b\uff0c\u6bd4\u5982&quot;\u661f\u671f\u4e00\u81f3\u661f\u671f\u4e94\u7684\u4e0a\u53489\u70b9&quot;\u3002<\/li>\n<li><code>AccuracySec<\/code>: \u8fd9\u4e2a\u9009\u9879\u7528\u4e8e\u8bbe\u7f6e\u5b9a\u65f6\u5668\u7684\u51c6\u786e\u5ea6\u3002\u5982\u679c\u8bbe\u7f6e\u4e3a\u8f83\u5927\u7684\u503c\uff0c\u5b9a\u65f6\u5668\u7684\u89e6\u53d1\u65f6\u95f4\u53ef\u80fd\u4f1a\u6709\u6240\u504f\u5dee\uff0c\u4f46\u53ef\u4ee5\u51cf\u5c11\u7cfb\u7edf\u5524\u9192\u7684\u9891\u7387\uff0c\u4ece\u800c\u8282\u7701\u80fd\u6e90\u3002<\/li>\n<li><code>Persistent<\/code>: \u8fd9\u4e2a\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u662f\u5426\u5728\u7cfb\u7edf\u91cd\u542f\u540e\u4fdd\u6301\u5b9a\u65f6\u5668\u7684\u72b6\u6001\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>[Path]<\/code> \u90e8\u5206\uff1a\u5982\u679c\u4f60\u7684\u670d\u52a1\u9700\u8981\u5728\u6587\u4ef6\u6216\u76ee\u5f55\u53d1\u751f\u53d8\u5316\u65f6\u8fd0\u884c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u90e8\u5206\u6765\u8bbe\u7f6e\u8def\u5f84\u76d1\u89c6\u5668\u3002\n<ul>\n<li><code>PathExists<\/code>, <code>PathExistsGlob<\/code>, <code>PathChanged<\/code>, <code>PathModified<\/code>, <code>DirectoryNotEmpty<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u8bbe\u7f6e\u89e6\u53d1\u670d\u52a1\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u53d8\u5316\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>[Slice]<\/code> \u90e8\u5206\uff1a\u5982\u679c\u4f60\u7684\u670d\u52a1\u9700\u8981\u5728\u7279\u5b9a\u7684cgroup\u5207\u7247\u4e2d\u8fd0\u884c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u90e8\u5206\u6765\u8bbe\u7f6e\u5207\u7247\u3002\n<ul>\n<li><code>MemoryLimit<\/code>, <code>CPUShares<\/code>, <code>BlockIOWeight<\/code>: \u8fd9\u4e9b\u9009\u9879\u7528\u4e8e\u8bbe\u7f6e\u5207\u7247\u7684\u8d44\u6e90\u9650\u5236\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>[Automount]<\/code> \u90e8\u5206\uff1a\u5982\u679c\u4f60\u7684\u670d\u52a1\u9700\u8981\u5728\u6587\u4ef6\u7cfb\u7edf\u88ab\u81ea\u52a8\u6302\u8f7d\u65f6\u8fd0\u884c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u90e8\u5206\u6765\u8bbe\u7f6e\u81ea\u52a8\u6302\u8f7d\u70b9\u3002\n<ul>\n<li><code>Where<\/code>: \u8fd9\u4e2a\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u81ea\u52a8\u6302\u8f7d\u70b9\u7684\u8def\u5f84\u3002<\/li>\n<li><code>DirectoryMode<\/code>: \u8fd9\u4e2a\u9009\u9879\u7528\u4e8e\u8bbe\u7f6e\u81ea\u52a8\u6302\u8f7d\u70b9\u7684\u6743\u9650\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u8fd9\u4e9b\u9009\u9879\u7684\u8be6\u7ec6\u8bf4\u660e\u53ef\u4ee5\u5728 <code>man systemd.timer<\/code>\uff0c<code>man systemd.path<\/code>\uff0c<code>man systemd.slice<\/code>\uff0c<code>man systemd.automount<\/code> \u7b49\u624b\u518c\u9875\u4e2d\u627e\u5230\u3002<\/p>\n<p><code>[Timer]<\/code>\u548c<code>[Socket]<\/code>\u90e8\u5206\u5b9e\u9645\u4e0a\u662f\u5728\u72ec\u7acb\u7684<code>.timer<\/code>\u548c<code>.socket<\/code>\u5355\u5143\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\uff0c\u800c\u4e0d\u662f\u5728<code>.service<\/code>\u5355\u5143\u6587\u4ef6\u4e2d\u3002\u5b83\u4eec\u901a\u5e38\u7528\u4e8e\u542f\u52a8<code>.service<\/code>\u5355\u5143\u3002<\/p>\n<ul>\n<li><code>.timer<\/code>\u5355\u5143\u7528\u4e8e\u5b9a\u65f6\u542f\u52a8\u670d\u52a1\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a<code>.timer<\/code>\u5355\u5143\u6765\u5b9a\u65f6\u8fd0\u884c\u4e00\u4e2a\u5907\u4efd\u670d\u52a1\u3002<\/li>\n<li><code>.socket<\/code>\u5355\u5143\u7528\u4e8e\u57fa\u4e8esocket\u6fc0\u6d3b\u7684\u670d\u52a1\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a<code>.socket<\/code>\u5355\u5143\u6765\u76d1\u542c\u4e00\u4e2a\u7279\u5b9a\u7684\u7aef\u53e3\uff0c\u5e76\u5728\u6709\u8fde\u63a5\u5230\u8fbe\u65f6\u542f\u52a8\u670d\u52a1\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b<code>.timer<\/code>\u548c<code>.socket<\/code>\u5355\u5143\u9700\u8981\u4e0e\u4e00\u4e2a<code>.service<\/code>\u5355\u5143\u5173\u8054\uff0c\u901a\u5e38\u5b83\u4eec\u7684\u540d\u5b57\u662f\u76f8\u540c\u7684\u3002\u4f8b\u5982\uff0c<code>foo.timer<\/code>\u4f1a\u542f\u52a8<code>foo.service<\/code>\uff0c<code>bar.socket<\/code>\u4f1a\u542f\u52a8<code>bar.service<\/code>\u3002<\/p>\n<p>\u867d\u7136\u8fd9\u4e9b\u5355\u5143\u7c7b\u578b\u6709\u4e0d\u540c\u7684\u7528\u9014\u548c\u914d\u7f6e\u9009\u9879\uff0c\u4f46\u5b83\u4eec\u7684\u57fa\u672c\u7ed3\u6784\u662f\u76f8\u540c\u7684\uff0c\u5305\u62ec<code>[Unit]<\/code>\u90e8\u5206\u548c<code>[Install]<\/code>\u90e8\u5206\u3002\u5728<code>[Unit]<\/code>\u90e8\u5206\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u5355\u5143\u7684\u63cf\u8ff0\u548c\u4f9d\u8d56\u5173\u7cfb\uff1b\u5728<code>[Install]<\/code>\u90e8\u5206\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u5355\u5143\u7684\u5b89\u88c5\u76ee\u6807\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Service\u6587\u4ef6 \u670d\u52a1\u6587\u4ef6\u662fSystemd\u7528\u4e8e\u63a7\u5236\u548c\u7ba1\u7406\u7cfb\u7edf\u670d\u52a1\u7684\u4e00\u79cd\u65b9\u5f0f\u3002\u670d\u52a1\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e\/et [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[63],"views":200,"_links":{"self":[{"href":"http:\/\/8.141.4.74\/index.php?rest_route=\/wp\/v2\/posts\/381"}],"collection":[{"href":"http:\/\/8.141.4.74\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/8.141.4.74\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/8.141.4.74\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/8.141.4.74\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=381"}],"version-history":[{"count":1,"href":"http:\/\/8.141.4.74\/index.php?rest_route=\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":382,"href":"http:\/\/8.141.4.74\/index.php?rest_route=\/wp\/v2\/posts\/381\/revisions\/382"}],"wp:attachment":[{"href":"http:\/\/8.141.4.74\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/8.141.4.74\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/8.141.4.74\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}