{"id":965,"date":"2019-10-19T14:04:29","date_gmt":"2019-10-19T06:04:29","guid":{"rendered":"http:\/\/iqotom.com\/?p=965"},"modified":"2019-10-19T14:04:31","modified_gmt":"2019-10-19T06:04:31","slug":"ubuntu-18-04-rc-local-systemd%e5%bc%80%e6%9c%ba%e5%90%af%e5%8a%a8%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"http:\/\/iqotom.com\/?p=965","title":{"rendered":"Ubuntu 18.04 rc.local systemd\u5f00\u673a\u542f\u52a8\u8bbe\u7f6e"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u524d\u8a00<\/h2>\n\n\n\n<p>Ubuntu18.04\u4e0d\u518d\u4f7f\u7528initd\u7ba1\u7406\u7cfb\u7edf\uff0c\u6539\u7528<a href=\"https:\/\/www.centos.bz\/tag\/systemd\/\">systemd<\/a>\uff0c\u73b0\u5728\u5df2\u6210\u4e3a\u5927\u591a\u6570\u53d1\u884c\u7248\u7684\u6807\u51c6\u914d\u7f6e\u3002 <\/p>\n\n\n\n<p> \u4ee5\u524dLinux\u542f\u52a8\u4e00\u76f4\u91c7\u7528init\u8fdb\u7a0b\uff0c\u4f8b\u5982\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/etc\/init.d\/apache2 start\nservice apache2 start<\/code><\/pre>\n\n\n\n<p> \u8fd9\u79cd\u65b9\u6cd5\u6709\u4e24\u4e2a\u7f3a\u70b9\uff1a <\/p>\n\n\n\n<ol><li> \u542f\u52a8\u65f6\u95f4\u957f\u3002<code>init<\/code>\u8fdb\u7a0b\u662f\u4e32\u884c\u542f\u52a8\uff0c\u53ea\u6709\u524d\u4e00\u4e2a\u8fdb\u7a0b\u542f\u52a8\u5b8c\uff0c\u624d\u4f1a\u542f\u52a8\u4e0b\u4e00\u4e2a\u8fdb\u7a0b <\/li><li> \u542f\u52a8\u811a\u672c\u590d\u6742\u3002<code>init<\/code>\u8fdb\u7a0b\u53ea\u662f\u6267\u884c\u542f\u52a8\u811a\u672c\uff0c\u4e0d\u7ba1\u5176\u4ed6\u4e8b\u60c5\u3002\u811a\u672c\u9700\u8981\u81ea\u5df1\u5904\u7406\u5404\u79cd\u60c5\u51b5\uff0c\u8fd9\u5f80\u5f80\u4f7f\u5f97\u811a\u672c\u53d8\u5f97\u5f88\u957f <\/li><\/ol>\n\n\n\n<p> Systemd \u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u8bde\u751f\u7684\u3002\u5b83\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\uff0c\u4e3a\u7cfb\u7edf\u7684\u542f\u52a8\u548c\u7ba1\u7406\u63d0\u4f9b\u4e00\u5957\u5b8c\u6574\u7684\u89e3\u51b3\u65b9\u6848\u3002 <\/p>\n\n\n\n<p> \u6839\u636e Linux \u60ef\u4f8b\uff0c\u5b57\u6bcd<code>d<\/code>\u662f\u5b88\u62a4\u8fdb\u7a0b\uff08daemon\uff09\u7684\u7f29\u5199\u3002 Systemd \u8fd9\u4e2a\u540d\u5b57\u7684\u542b\u4e49\uff0c\u5c31\u662f\u5b83\u8981\u5b88\u62a4\u6574\u4e2a\u7cfb\u7edf\u3002  Systemd \u7684\u4f18\u70b9\u662f\u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u662f\u7f3a\u70b9\u4e5f\u5f88\u660e\u663e\uff0c\u4f53\u7cfb\u5e9e\u5927\uff0c\u975e\u5e38\u590d\u6742\u3002\u4e8b\u5b9e\u4e0a\uff0c\u73b0\u5728\u8fd8\u6709\u5f88\u591a\u4eba\u53cd\u5bf9\u4f7f\u7528 \u3002 <\/p>\n\n\n\n<p> \u8fd9\u91cc\u8bb0\u5f55\u4e0b\u600e\u4e48\u8ddf\u4ee5\u524d\u4e00\u6837\u5728\/etc\/rc.local\u8bbe\u7f6e\u5f00\u673a\u81ea\u52a8\u8fd0\u884c\u811a\u672c\u3001\u542f\u52a8\u7a0b\u5e8f\u3001\u52a0\u8f7d\u9a71\u52a8\u7b49&#8230;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"> Setp.1 <\/h3>\n\n\n\n<p> systemd\u9ed8\u8ba4\u8bfb\u53d6\/etc\/systemd\/system\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u8be5\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u4f1a\u94fe\u63a5\/lib\/systemd\/system\/\u4e0b\u7684\u6587\u4ef6\u3002\u4e00\u822c\u7cfb\u7edf\u5b89\u88c5\u5b8c\/lib\/systemd\/system\/\u4e0b\u4f1a\u6709rc-local.service\u6587\u4ef6\uff0c\u5373\u6211\u4eec\u9700\u8981\u7684\u914d\u7f6e\u6587\u4ef6\u3002 <\/p>\n\n\n\n<p><strong> \u94fe\u63a5\u8fc7\u6765\uff1a <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/lib\/systemd\/system\nln -fs \/lib\/systemd\/system\/rc-local.service \/etc\/systemd\/system\/rc-local.service\ncd \/etc\/systemd\/system\ncat rc-local.service<\/code><\/pre>\n\n\n\n<p><strong> rc-local.service\u5185\u5bb9\uff1a <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#  SPDX-License-Identifier: LGPL-2.1+\n#\n#  This file is part of systemd.\n#\n#  systemd is free software; you can redistribute it and\/or modify it\n#  under the terms of the GNU Lesser General Public License as published by\n#  the Free Software Foundation; either version 2.1 of the License, or\n#  (at your option) any later version.\n\n# This unit gets pulled automatically into multi-user.target by\n# systemd-rc-local-generator if \/etc\/rc.local is executable.\n[Unit]\nDescription=\/etc\/rc.local Compatibility\nDocumentation=man:systemd-rc-local-generator(8)\nConditionFileIsExecutable=\/etc\/rc.local\nAfter=network.target\n\n[Service]\nType=forking\nExecStart=\/etc\/rc.local start\nTimeoutSec=0\nRemainAfterExit=yes\nGuessMainPID=no<\/code><\/pre>\n\n\n\n<p><strong>[Unit] \u533a\u5757<\/strong>\uff1a\u542f\u52a8\u987a\u5e8f\u4e0e\u4f9d\u8d56\u5173\u7cfb\u3002 <br><strong>[Service] \u533a\u5757<\/strong>\uff1a\u542f\u52a8\u884c\u4e3a,\u5982\u4f55\u542f\u52a8\uff0c\u542f\u52a8\u7c7b\u578b\u3002 <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setp.2<\/h3>\n\n\n\n<p><strong>1. \u521b\u5efa\/etc\/rc.local\u6587\u4ef6 <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch \/etc\/rc.local<\/code><\/pre>\n\n\n\n<p><strong>2. \u8d4b\u4e88\u53ef\u6267\u884c\u6743\u9650 <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 755 rc.local<\/code><\/pre>\n\n\n\n<p><strong>3. \u7f16\u8f91rc.local\uff0c\u6dfb\u52a0\u9700\u8981\u5f00\u673a\u542f\u52a8\u7684\u4efb\u52a1 <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\necho \"test rc!!!\" > \/var\/test_rc.log<\/code><\/pre>\n\n\n\n<p><strong>4. reboot\u91cd\u542f\u7cfb\u7edf\uff0c\u67e5\u770b\/var\u76ee\u5f55\u5df2\u7ecf\u6210\u4e86test_rc.log <\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 Ubuntu18.04\u4e0d\u518d\u4f7f\u7528initd\u7ba1\u7406\u7cfb\u7edf\uff0c\u6539\u7528systemd\uff0c\u73b0\u5728\u5df2\u6210\u4e3a\u5927\u591a\u6570\u53d1\u884c\u7248\u7684\u6807\u51c6\u914d\u7f6e\u3002\u2026 <span class=\"read-more\"><a href=\"http:\/\/iqotom.com\/?p=965\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":966,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[84],"_links":{"self":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/965"}],"collection":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=965"}],"version-history":[{"count":2,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/965\/revisions"}],"predecessor-version":[{"id":968,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/965\/revisions\/968"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/media\/966"}],"wp:attachment":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=965"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}