{"id":176072,"date":"2020-04-21T11:49:17","date_gmt":"2020-04-21T03:49:17","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=176072"},"modified":"2020-04-09T09:25:55","modified_gmt":"2020-04-09T01:25:55","slug":"centos-system-v-init","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/centos-system-v-init.html","title":{"rendered":"CentOS\u7684System V init\u542f\u52a8\u811a\u672c"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nCentOS\u7cfb\u7edf\u672c\u8eab\u81ea\u5e26\u4e86\u8bf4\u660e\uff0c\u5728\/usr\/share\/doc\/initscripts-(*)\/sysvinitfiles\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a\u6240\u6709System V init\u811a\u672c\u90fd\u547d\u540d\u4e3a\/etc\/rc.d\/init.d\/<servicename>\uff0c\u5176\u4e2d<\/servicename><servicename>\u662f\u670d\u52a1\u7684\u540d\u79f0\u3002\u5fc5\u987b\u6ca1\u6709\u201c.init\u201d\u540e\u7f00\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u793a\u4f8b\u811a\u672c\uff1a<\/p>\n

\r\n#!\/bin\/bash\r\n#\r\n# \/etc\/rc.d\/init.d\/<servicename>\r\n#\r\n# <description of the *service*>\r\n# <any general comments about this init script>\r\n#\r\n# <tags -- see below for tag definitions. *Every line* from the top\r\n# of the file to the end of the tags section must begin with a #\r\n# character. After the tags section, there should be a blank line.\r\n# This keeps normal comments in the rest of the file from being\r\n# mistaken for tags, should they happen to fit the pattern.>\r\n\r\n# Source function library.\r\n. \/etc\/rc.d\/init.d\/functions\r\n\r\n<define any local shell functions used by the code that follows>\r\n\r\ncase \"$1\" in\r\n    start)\r\n        echo -n \"Starting <servicename> services: \"\r\n        <start daemons, perhaps with the daemon function>\r\n        touch \/var\/lock\/subsys\/<servicename>\r\n    ;;\r\n    stop)\r\n        echo -n \"Shutting down <servicename> services: \"\r\n        <stop daemons, perhaps with the killproc function>\r\n        rm -f \/var\/lock\/subsys\/<servicename>\r\n    ;;\r\n    status)\r\n        <report the status of the daemons in free-form format,\r\n        perhaps with the status function>\r\n    ;;\r\n    restart)\r\n        <restart the daemons, normally with $0 stop; $0 start>\r\n    ;;\r\n    reload)\r\n        <cause the service configuration to be reread, either with\r\n        kill -HUP or by restarting the daemons, possibly with\r\n        $0 stop; $0 start>\r\n    ;;\r\n    probe)\r\n        <optional. If it exists, then it should determine whether\r\n        or not the service needs to be restarted or reloaded (or\r\n        whatever) in order to activate any changes in the configuration\r\n        scripts. It should print out a list of commands to give to\r\n        $0; see the description under the probe tag below.>\r\n    ;;\r\n    *)\r\n        echo \"Usage: <servicename> {start|stop|status|reload|restart[|probe]\"\r\n        exit 1\r\n    ;;\r\nesac\r\n<\/pre>\n

\u6ce8\u610f\uff1a\u91cd\u542f\u548c\u91cd\u8f7d\u529f\u80fd\u53ef\u4ee5\uff08\u901a\u5e38\uff09\u7ec4\u5408\u6210\u4e00\u4e2a\u6d4b\u8bd5\uff0c<\/p>\n

vis\uff1a\r\n\r\nrestart|reload\uff09<\/pre>\n<\/p>\n

\u4e0d\u7981\u6b62\u60a8\u6dfb\u52a0\u5176\u4ed6\u547d\u4ee4; \u5217\u51fa\u60a8\u6253\u7b97\u4ee5\u4ea4\u4e92\u65b9\u5f0f\u4f7f\u7528\u5230\u4f7f\u7528\u6d88\u606f\u7684\u6240\u6709\u547d\u4ee4\u3002<\/p>\n

\/etc\/rc.d\/init.d\/functions\u51fd\u6570\r\n\r\ndaemon [+\/-nicelevel] program [arguments] [&]<\/pre>\n

\u5982\u679c\u5b88\u62a4\u7a0b\u5e8f\u5c1a\u672a\u8fd0\u884c\uff0c\u5219\u542f\u52a8\u8be5\u5b88\u62a4\u7a0b\u5e8f\u3002\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u6709\u7528\u7684\u4e1c\u897f\uff0c\u4f8b\u5982\uff0c\u5982\u679c\u5b88\u62a4\u8fdb\u7a0b\u610f\u5916\u7ec8\u6b62\uff0c\u5219\u4fdd\u7559\u5b88\u62a4\u8fdb\u7a0b\u3002<\/p>\n

killproc program [signal]<\/pre>\n

\u5411\u7a0b\u5e8f\u53d1\u9001\u4fe1\u53f7; \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b83\u53d1\u9001\u4e00\u4e2aSIGTERM\uff0c\u5982\u679c\u8fdb\u7a0b\u6ca1\u6709\u6b7b\uff0c\u5b83\u4f1a\u5728\u51e0\u79d2\u949f\u540e\u53d1\u9001\u4e00\u4e2aSIGKILL\u3002<\/p>\n

\u5982\u679c\u627e\u5230pid\u6587\u4ef6\uff0c\u5b83\u8fd8\u4f1a\u5c1d\u8bd5\u5220\u9664\u5b83\u3002<\/p>\n

pidofproc program<\/pre>\n

\u8bd5\u56fe\u627e\u5230\u4e00\u4e2a\u7a0b\u5e8f\u7684pid; \u68c0\u67e5\u53ef\u80fd\u7684pidfiles\uff0c\u4f7f\u7528pidof\u7a0b\u5e8f\uff0c\u751a\u81f3\u4f7f\u7528ps\u3002\u4e3b\u8981\u7528\u4e8e\u6b64\u6587\u4ef6\u4e2d\u7684\u5176\u4ed6\u51fd\u6570\uff0c\u4f46\u4e5f\u53ef\u7528\u4e8e\u811a\u672c\u3002<\/p>\n

status program<\/pre>\n

\u6253\u5370\u72b6\u6001\u4fe1\u606f\u3002\u5047\u8bbe\u7a0b\u5e8f\u540d\u79f0\u4e0eservicename\u76f8\u540c\u3002<\/p>\n

Tags.\r\n\r\n# chkconfig: <startlevellist> <startpriority> <endpriority><\/pre>\n

\u5fc5\u987b\u3002\u662f\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5e94\u542f\u52a8\u670d\u52a1\u7684\u7ea7\u522b\u5217\u8868\u3002\u548c\u662f\u4f18\u5148\u7ea7\u7f16\u53f7\u3002\u4f8b\u5982\uff1a<\/endpriority><\/startpriority><\/startlevellist><\/p>\n

# chkconfig\uff1a2345 20 80\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u9605\u8bfb\u201cman chkconfig\u201d\u3002<\/pre>\n

\u9664\u975e\u6709\u4e00\u4e2a\u975e\u5e38\u597d\u7684\uff0c\u663e\u6027\u76f8\u53cd\u7684\u539f\u56e0\uff0c<endpriority>\u5e94\u8be5\u7b49\u4e8e 100 - <startpriority><\/p>\n

\uff03 description: <multi-line description of service><\/pre>\n

\u5fc5\u987b\u3002\u51e0\u884c\u63cf\u8ff0\uff0c\u7ee7\u7eed\u4f7f\u7528'\\'\u5b57\u7b26\u3002\u4ee5\u4e0b\u884c\u4e2d\u7684\u521d\u59cb\u6ce8\u91ca\u548c\u540e\u7eed\u7a7a\u683c\u5c06\u88ab\u5ffd\u7565\u3002<\/p>\n

# description[ln]: <multi-line description of service in the language \\ # ln, whatever that is><\/pre>\n

\u53ef\u9009\u3002\u5e94\u5c06\u63cf\u8ff0\u7ffb\u8bd1\u6210\u6307\u5b9a\u7684\u8bed\u8a00\u3002<\/p>\n

# processname:<\/pre>\n

\u53ef\u9009\uff0c\u5141\u8bb8\u591a\u4e2a\u6761\u76ee\u3002\u5bf9\u4e8e\u811a\u672c\u542f\u52a8\u7684\u6bcf\u4e2a\u8fdb\u7a0b\u540d\u79f0\uff0c\u5e94\u8be5\u6709\u4e00\u4e2a\u8fdb\u7a0b\u540d\u79f0\u6761\u76ee\u3002\u4f8b\u5982\uff0csamba\u670d\u52a1\u542f\u52a8\u4e24\u4e2a\u5b88\u62a4\u8fdb\u7a0b\uff1a<\/p>\n

#processname\uff1asmdb \r\n\u3000\u3000#processname\uff1anmdb\r\n\r\n# config:<\/pre>\n

\u53ef\u9009\uff0c\u5141\u8bb8\u591a\u4e2a\u6761\u76ee\u3002\u5bf9\u4e8e\u5b88\u62a4\u7a0b\u5e8f\u4f7f\u7528\u7684\u6bcf\u4e2a\u9759\u6001\u914d\u7f6e\u6587\u4ef6\uff0c\u8bf7\u4f7f\u7528\u5355\u4e2a\u6761\u76ee\u3002\u4f8b\u5982\uff1a<\/p>\n

# config: \/etc\/httpd\/conf\/httpd.conf\r\n\u3000\u3000# config: \/etc\/httpd\/conf\/srm.conf<\/pre>\n

\u53ef\u9009\uff09\u5982\u679c\u670d\u52a1\u5668\u5c06\u81ea\u52a8\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\uff08\u5982\u679c\u5df2\u66f4\u6539\uff09\uff0c\u5219\u53ef\u4ee5\u5728\u884c\u4e2d\u9644\u52a0\u201cautoreload\u201d\u4e00\u8bcd\uff1a<\/p>\n

# config: \/etc\/foobar.conf autoreload<\/pre>\n

#pidfile\uff1a<\/p>\n

\u53ef\u9009\uff0c\u5141\u8bb8\u591a\u4e2a\u6761\u76ee\u3002\u4f7f\u7528\u5c31\u50cf\u914d\u7f6e\u6761\u76ee\u4e00\u6837\uff0c\u9664\u4e86\u5b83\u6307\u5411pidfiles\u3002\u5047\u8bbepidfiles\u4ec5\u5728\u8fdb\u7a0b\u521b\u5efa\u65f6\u66f4\u65b0\uff0c\u800c\u4e0d\u662f\u66f4\u665a\u3002\u8be5\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\u5e94\u8be5\u662fPID\u7684ASCII\u8868\u793a; \u7ec8\u6b62\u6362\u884c\u7b26\u662f\u53ef\u9009\u7684\u3002\u4e0d\u68c0\u67e5\u9664\u7b2c\u4e00\u884c\u4ee5\u5916\u7684\u4efb\u4f55\u884c\u3002<\/p>\n

#project: true<\/pre>\n

\u53ef\u9009\uff0c\u4f7f\u7528IN PLACE\u7684processname\uff0cconfig\u548cpidfile\u3002\u5982\u679c\u5b58\u5728\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b9e\u73b0\u6b63\u786e\u7684\u91cd\u65b0\u52a0\u8f7d - \u5982\u679c\u5fc5\u8981\u7684\u5faa\u73af\uff1a<\/p>\n

command = $\uff08\/ etc \/ rd.d \/ init.d \/ SCRIPT probe\uff09\r\n[ -  n\u201c$ command\u201d] && \/etc\/rc.d\/init.d\/SCRIPT $ command<\/pre>\n

\u5176\u4e2dSCRIPT\u662f\u670d\u52a1\u7684sysv init\u811a\u672c\u7684\u540d\u79f0\u3002<\/p>\n

\u4f5c\u4e3a\u793a\u4f8b\uff0c\u9700\u8981\u6267\u884c\u590d\u6742\u5904\u7406\u7684\u811a\u672c\u53ef\u4ee5\u8fd4\u56de\u201crun \/var\/tmp\/<servicename.probe.$$\u201d\u5e76\u5b9e\u73b0\u201crun\u201d\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u5c06\u6267\u884c\u547d\u540d\u811a\u672c\u7136\u540e\u5c06\u5176\u5220\u9664\u3002<\/p>\n

\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u4e0d\u9700\u8981\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\u4f7f\u670d\u52a1\u4e0e\u5176\u914d\u7f6e\u6587\u4ef6\u540c\u6b65\uff0c\u5219probe\u547d\u4ee4\u5e94\u8be5\u53ea\u662f\u201cexit 0\u201d\u3002<\/p>\n

\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n

1\u3001# chkconfig\u548c# description\u4e0d\u80fd\u5c11\uff0c\u5fc5\u987b\u5199\u3002<\/p>\n

2\u3001chkconfig\u7684<startpriority> <endpriority>\u4e3a\u542f\u52a8\u4f18\u5148\u7ea7\uff0c\u5728man\u4e2d\u67e5\u8be2\u4e0d\u5230\uff0c\u4e00\u822cend...\u4e0d\u7528\u7406\u89e3\uff0c\u76f4\u63a5100-start...\u5373\u53ef\u3002start\u4e3a\u5f00\u59cb\u7684\u987a\u5e8f\uff0c\u4e00\u822c\u7cfb\u7edf\u4ece\u5c0f\u6267\u884c\u5230\u5927\uff0c\u6570\u503c\u4efb\u610f\uff0c\u8fd9\u4e2a\u5bf9\u4e8e\u4f9d\u8d56\u542f\u52a8\u6709\u5f88\u5927\u7684\u5e2e\u52a9\uff0c\u6bd4\u5982\u63a7\u5236\u5148\u542f\u52a8\u67d0\u4e2a\u670d\u52a1\uff0c\u518d\u542f\u52a8\u67d0\u4e2a\u670d\u52a1\u3002\u4ee5\u4e0b\u662f\u67e5\u8be2\u8bbe\u7f6e\u540e\u7684\u547d\u4ee4\uff1a<\/p>\n

# \u67e5\u8be2\u542f\u52a8\u7ea7\u522b\r\nchkconfig --list <servicename>\r\n# \u67e5\u8be2\u542f\u52a8\u987a\u5e8f\r\ngrep chkconfig \/etc\/rc.d\/init.d\/<servicenaem><\/pre>\n","protected":false},"excerpt":{"rendered":"

\u793a\u4f8b\u811a\u672c\uff1a #!\/bin\/bash # # \/etc\/rc.d\/init.d\/<servicename& […]<\/p>\n","protected":false},"author":310,"featured_media":176397,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-176072","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/176072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=176072"}],"version-history":[{"count":24,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/176072\/revisions"}],"predecessor-version":[{"id":176459,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/176072\/revisions\/176459"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/176397"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=176072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=176072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=176072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}