{"id":154,"date":"2024-02-24T12:43:31","date_gmt":"2024-02-24T04:43:31","guid":{"rendered":"https:\/\/669082.xyz\/?p=154"},"modified":"2024-02-24T12:53:04","modified_gmt":"2024-02-24T04:53:04","slug":"centos%e6%8a%8a%e5%8f%af%e6%89%a7%e8%a1%8c%e8%84%9a%e6%9c%ac%e5%8a%a0%e5%85%a5%e6%9c%8d%e5%8a%a1%e5%b9%b6%e4%bd%bf%e7%94%a8%e5%ae%9a%e6%97%b6%e5%99%a8shell%e7%9b%91%e6%8e%a7%e5%b9%b6%e9%87%8d","status":"publish","type":"post","link":"https:\/\/669082.xyz\/index.php\/2024\/02\/24\/centos%e6%8a%8a%e5%8f%af%e6%89%a7%e8%a1%8c%e8%84%9a%e6%9c%ac%e5%8a%a0%e5%85%a5%e6%9c%8d%e5%8a%a1%e5%b9%b6%e4%bd%bf%e7%94%a8%e5%ae%9a%e6%97%b6%e5%99%a8shell%e7%9b%91%e6%8e%a7%e5%b9%b6%e9%87%8d\/","title":{"rendered":"centos\u628a\u53ef\u6267\u884c\u811a\u672c\u52a0\u5165\u670d\u52a1,\u5e76\u4f7f\u7528\u5b9a\u65f6\u5668shell\u76d1\u63a7\u5e76\u91cd\u542f"},"content":{"rendered":"<h4>\u628a\u53ef\u6267\u884c\u811a\u672c\u52a0\u5165\u670d\u52a1<\/h4>\n<h6>1 \u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6 \/etc\/systemd\/system\/servername.service<\/h6>\n<pre><code class=\"language-shell\">vi \/etc\/systemd\/system\/servername.service<\/code><\/pre>\n<h6>2 \u52a0\u5165\u6587\u4ef6\u5185\u5bb9<\/h6>\n<pre><code class=\"language-shell\">[Unit]\nDescription=server description\nAfter=network.target\n\n[Service]\n#\u8fd9\u91cc\u662f\u6587\u4ef6\u8def\u5f84\nExecStart=\/www\/wwwroot\/...\nRestart=always\nRestartSec=10\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<h6>3 \u7136\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528systemctl\u6765\u63a7\u5236\u4e86<\/h6>\n<pre><code class=\"language-shell\">systemctl daemon-reload\nsystemctl start servername\nsystemctl status servername\n#\u52a0\u5165\u5f00\u673a\u542f\u52a8\nsystemctl enable servername<\/code><\/pre>\n<h4>\u7528shell\u811a\u672c\u53bb\u76d1\u63a7\u670d\u52a1\u5e76\u5b9e\u73b0\u91cd\u542f(crontab)<\/h4>\n<h6>1 \u65b0\u5efa\u4e00\u4e2ashell\u811a\u672c<\/h6>\n<pre><code class=\"language-shell\">vi jk<\/code><\/pre>\n<h6>\u586b\u5165\u4ee5\u4e0b\u5185\u5bb9<\/h6>\n<pre><code class=\"language-shell\">#!\/bin\/bash\n\nif ! pgrep -x &quot;servername&quot; &gt; \/dev\/null; then\n        # \u5982\u679c\u8fdb\u7a0b\u4e0d\u5728\u8fd0\u884c\uff0c\u5219\u91cd\u65b0\u542f\u52a8\n        echo &quot;`date` servername is stop, starting on&quot; &gt;&gt; \/www\/wwwroot\/servername.log\n        sudo service servername restart\nfi\n\nsleep 20\n\nif ! pgrep -x &quot;servername&quot; &gt; \/dev\/null; then\n        # \u5982\u679c\u6ca1\u542f\u52a8\u6210\u529f\uff0c\u5219\u91cd\u65b0vps\n        echo &quot;`date` servername starting failed, reboot&quot; &gt;&gt; \/www\/wwwroot\/servername.log\n        sudo reboot\nfi<\/code><\/pre>\n<h6>2\u628a\u8fd9\u4e2a\u811a\u672c\u52a0\u5165crontab\u5b9a\u65f6\u5668<\/h6>\n<pre><code class=\"language-shell\">crontab -e<\/code><\/pre>\n<h6>\u52a0\u5165\u4ee5\u4e0b\u5185\u5bb9<\/h6>\n<pre><code class=\"language-shell\">*\/1 * * * * sh \/www\/wwwroot\/jk<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u628a\u53ef\u6267\u884c\u811a\u672c\u52a0\u5165\u670d\u52a1 1 \u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6 \/etc\/systemd\/system\/servername [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":5,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}