{"id":273,"date":"2020-05-19T10:57:22","date_gmt":"2020-05-19T02:57:22","guid":{"rendered":"http:\/\/wp.vicds.com\/?p=273"},"modified":"2020-12-03T14:37:43","modified_gmt":"2020-12-03T06:37:43","slug":"debian-systemd","status":"publish","type":"post","link":"https:\/\/wp.vicds.com\/?p=273","title":{"rendered":"Debian systemd"},"content":{"rendered":"\n<p>jessie\u5f8c\u53d6\u6d88\u4e86init, \u6539\u7528\u4e86systemd, \u56e0\u6b64\u6c92\u6709rc.local. \u7db2\u8def\u4e0a\u4e0d\u5c11\u4f7f\u7528rc.local\u7684\u65b9\u5f0f, \u7562\u7adf\u5b98\u65b9\u90fd\u4e0d\u7528\u4e86, \u7e3d\u662f\u8981\u5b78\u7fd2\u65b0\u65b9\u5f0f.(crontab?)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5728 \/etc\/system\/systemd\/ \u5efa\u4e00\u500b FileName.target \u7684\u6a94\u6848, \u4e26\u5206\u70ba\u4ee5\u4e0b\u5340\u584a.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;Unit]\nDescription=A description for this service unit.\nAfter=network.target\n \n&#091;Service]\ntype=simple\n# User=user\n# Group=group\n# WorkingDirectory=\/path\/to\/folder\nExecStart=\/path\/to\/program &#091;arguments]\nRestart=always\nExecStop\nRestartSec=3s\n \n# Environment=&quot;VARIABLE_1=VALUE_1&quot; &quot;VARIABLE_2=VALUE_2&quot;\n# Environment=&quot;VARIABLE_3=VALUE_3&quot; &quot;VARIABLE_4=VALUE_4&quot;\n \n&#091;Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>[Unit]<\/p>\n\n\n\n<p>before\/after: \u95dc\u65bc\u9019\u500b, \u9700\u8981\u4e86\u89e3systemd\u555f\u52d5\u7684\u9806\u5e8f.<\/p>\n\n\n\n<p>\u7531\u4ee5\u4e0b\u7684\u6307\u4ee4\u53ef\u4ee5\u67e5\u5230\u9019\u500b\u670d\u52d9\u555f\u52d5\u82b1\u4e86\u591a\u5c11\u6642\u9593<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemd-analyze blame\n\nsystemd-analyze plot &gt; boot.svg \nsystemd-analyze plot &gt; boot.html\n\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>type:\nType=simple\uff08\u9810\u8a2d\u503c\uff09\uff1asystemd\u8a8d\u70ba\u8a72\u670d\u52d9\u5c07\u7acb\u5373\u555f\u52d5\u3002\u670d\u52d9\u7a0b\u5e8f\u4e0d\u6703fork\u3002\u5982\u679c\u8a72\u670d\u52d9\u8981\u555f\u52d5\u5176\u4ed6\u670d\u52d9\uff0c\u4e0d\u8981\u4f7f\u7528\u6b64\u985e\u578b\u555f\u52d5\uff0c\u9664\u975e\u8a72\u670d\u52d9\u662fsocket\u6fc0\u6d3b\u578b\u3002\nType=forking\uff1asystemd\u8a8d\u70ba\u7576\u8a72\u670d\u52d9\u7a0b\u5e8ffork\uff0c\u4e14\u7236\u7a0b\u5e8f\u9000\u51fa\u5f8c\u670d\u52d9\u555f\u52d5\u6210\u529f\u3002\u5c0d\u65bc\u5e38\u898f\u7684\u5b88\u8b77\u7a0b\u5e8f\uff08daemon\uff09\uff0c\u9664\u975e\u4f60\u78ba\u5b9a\u6b64\u555f\u52d5\u65b9\u5f0f\u7121\u6cd5\u6eff\u8db3\u9700\u6c42\uff0c\u4f7f\u7528\u6b64\u985e\u578b\u555f\u52d5\u5373\u53ef\u3002\u4f7f\u7528\u6b64\u555f\u52d5\u985e\u578b\u61c9\u8a72\u540c\u6642\u6307\u5b9a PIDFile=\uff0c\u4ee5\u4fbfsystemd\u80fd\u5920\u8ddf\u8e64\u670d\u52d9\u7684\u4e3b\u7a0b\u5e8f\u3002\nType=oneshot\uff1a\u9019\u4e00\u9078\u9805\u9069\u7528\u65bc\u53ea\u57f7\u884c\u4e00\u9805\u4efb\u52d9\u3001\u96a8\u5f8c\u7acb\u5373\u9000\u51fa\u7684\u670d\u52d9\u3002\u53ef\u80fd\u9700\u8981\u540c\u6642\u8a2d\u5b9a RemainAfterExit=yes \u4f7f\u5f97 systemd \u5728\u670d\u52d9\u7a0b\u5e8f\u9000\u51fa\u4e4b\u5f8c\u4ecd\u7136\u8a8d\u70ba\u670d\u52d9\u8655\u65bc\u6fc0\u6d3b\u72c0\u614b\u3002\nType=notify\uff1a\u8207 Type=simple \u76f8\u540c\uff0c\u4f46\u7d04\u5b9a\u670d\u52d9\u6703\u5728\u5c31\u7dd2\u5f8c\u5411 systemd \u767c\u9001\u4e00\u500b\u4fe1\u865f\u3002\u9019\u4e00\u901a\u77e5\u7684\u5be6\u73fe\u7531 libsystemd-daemon.so \u63d0\u4f9b\u3002\nType=dbus\uff1a\u82e5\u4ee5\u6b64\u65b9\u5f0f\u555f\u52d5\uff0c\u7576\u6307\u5b9a\u7684 BusName \u51fa\u73fe\u5728D-Bus\u7cfb\u7d71\u7e3d\u7dda\u4e0a\u6642\uff0csystemd\u8a8d\u70ba\u670d\u52d9\u5c31\u7dd2\u3002\nType=idle: systemd\u6703\u7b49\u5f85\u6240\u6709\u5de5\u4f5c\u8655\u7406\u5b8c\u6210\u5f8c\uff0c\u624d\u958b\u59cb\u57f7\u884cidle\u985e\u578b\u7684\u55ae\u5143\u3002\u5176\u4ed6\u884c\u70ba\u548cType=simple \u985e\u4f3c\u3002<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># systemctl daemon-reload\n# \u5982\u679c\u8981\u958b\u6a5f\u81ea\u52d5\u555f\u52d5\n# systemctl enable FileName.service\n# \u5982\u679c\u53ea\u662f\u624b\u52d5\u555f\u52d5\n# systemctl start FileName.service<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6aa2\u67e5\u72c0\u614b\n# systemctl status\n# journalctl -u Filename.service\n# journalctl -u FileName.server -p log\u6a94level<\/code><\/pre>\n\n\n\n<p> \u6709\u7684\u6642\u5019\u6703\u4e0d\u6210\u529f<\/p>\n\n\n\n<p><a href=\"http:\/\/felix-lin.com\/linux\/debianubuntu-%E6%96%B0%E5%A2%9E%E9%96%8B%E6%A9%9F%E8%87%AA%E5%8B%95%E5%9F%B7%E8%A1%8C%E7%A8%8B%E5%BC%8F\/\">http:\/\/felix-lin.com\/linux\/debianubuntu-%E6%96%B0%E5%A2%9E%E9%96%8B%E6%A9%9F%E8%87%AA%E5%8B%95%E5%9F%B7%E8%A1%8C%E7%A8%8B%E5%BC%8F\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-g-t-wang\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"jBG5VkCbOM\"><a href=\"https:\/\/blog.gtwang.org\/linux\/auto-execute-linux-scripts-during-boot-login-logout\/\">Linux \u5982\u4f55\u8a2d\u5b9a\u958b\u6a5f\u3001\u767b\u5165\u8207\u767b\u51fa\u81ea\u52d5\u57f7\u884c\u7684\u6307\u4ee4\u6216\u7a0b\u5f0f\uff1f<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"Linux \u5982\u4f55\u8a2d\u5b9a\u958b\u6a5f\u3001\u767b\u5165\u8207\u767b\u51fa\u81ea\u52d5\u57f7\u884c\u7684\u6307\u4ee4\u6216\u7a0b\u5f0f\uff1f &#8212; G. T. Wang\" src=\"https:\/\/blog.gtwang.org\/linux\/auto-execute-linux-scripts-during-boot-login-logout\/embed\/#?secret=jBG5VkCbOM\" data-secret=\"jBG5VkCbOM\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>jessie\u5f8c\u53d6\u6d88\u4e86init, \u6539\u7528\u4e86sys [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-273","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273"}],"version-history":[{"count":6,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":711,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions\/711"}],"wp:attachment":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}