{"id":5513,"date":"2016-11-12T21:34:22","date_gmt":"2016-11-12T13:34:22","guid":{"rendered":"https:\/\/sdeno.com\/?p=5513"},"modified":"2017-05-12T23:47:12","modified_gmt":"2017-05-12T15:47:12","slug":"node-js%e7%bd%91%e7%ab%99%e5%8f%91%e5%b8%83%e5%99%a8-forever","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=5513","title":{"rendered":"node.js\u7f51\u7ad9\u53d1\u5e03\u5668\u2014forever"},"content":{"rendered":"<p>\u7c7b\u4f3c\u7684\u8fd8\u6709pm2\uff0c\u300a<a href=\"https:\/\/sdeno.com\/?p=5468\" target=\"_blank\">node.js\u7f51\u7ad9\u53d1\u5e03\u5de5\u5177\u6a21\u5757\u2014pm2<\/a>\u300b<\/p>\n<p><span style=\"color: #404040;\">Github\u5730\u5740\uff1a<\/span><a href=\"https:\/\/github.com\/nodejitsu\/forever\" target=\"_blank\">https:\/\/github.com\/nodejitsu\/forever<\/a><\/p>\n<h6 id=\"forever-1\" style=\"color: #000000;\">forever\u5b89\u88c5<\/h6>\n<div style=\"color: #000000;\">\n<pre><code class=\"js\"><span class=\"c1\" style=\"color: #586e75;\">\/\/ \u8bb0\u5f97\u52a0-g\uff0cforever\u8981\u6c42\u5b89\u88c5\u5230\u5168\u5c40\u73af\u5883\u4e0b<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">sudo<\/span> <span class=\"nx\" style=\"color: #555555;\">npm<\/span> <span class=\"nx\" style=\"color: #555555;\">install<\/span> <span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">g<\/span><\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h6 id=\"forever-2\" style=\"color: #000000;\">forever\u4f7f\u7528\u8bf4\u660e<\/h6>\n<div style=\"color: #000000;\">\n<pre><code class=\"js\"><span class=\"c1\" style=\"color: #586e75;\">\/\/ 1. \u7b80\u5355\u7684\u542f\u52a8<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">start<\/span> <span class=\"nx\" style=\"color: #555555;\">app<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">js<\/span>\r\n\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/ 2. \u6307\u5b9aforever\u4fe1\u606f\u8f93\u51fa\u6587\u4ef6\uff0c\u5f53\u7136\uff0c\u9ed8\u8ba4\u5b83\u4f1a\u653e\u5230~\/.forever\/forever.log<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">start<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">l<\/span> <span class=\"nx\" style=\"color: #555555;\">forever<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">log<\/span> <span class=\"nx\" style=\"color: #555555;\">app<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">js<\/span>\r\n\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/ 3. \u6307\u5b9aapp.js\u4e2d\u7684\u65e5\u5fd7\u4fe1\u606f\u548c\u9519\u8bef\u65e5\u5fd7\u8f93\u51fa\u6587\u4ef6\uff0c<\/span>\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/  -o \u5c31\u662fconsole.log\u8f93\u51fa\u7684\u4fe1\u606f\uff0c-e \u5c31\u662fconsole.error\u8f93\u51fa\u7684\u4fe1\u606f<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">start<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">o<\/span> <span class=\"nx\" style=\"color: #555555;\">out<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">log<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">e<\/span> <span class=\"nx\" style=\"color: #555555;\">err<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">log<\/span> <span class=\"nx\" style=\"color: #555555;\">app<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">js<\/span>\r\n\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/ 4. \u8ffd\u52a0\u65e5\u5fd7\uff0cforever\u9ed8\u8ba4\u662f\u4e0d\u80fd\u8986\u76d6\u4e0a\u6b21\u7684\u542f\u52a8\u65e5\u5fd7\uff0c<\/span>\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/  \u6240\u4ee5\u5982\u679c\u7b2c\u4e8c\u6b21\u542f\u52a8\u4e0d\u52a0-a\uff0c\u5219\u4f1a\u4e0d\u8ba9\u8fd0\u884c<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">start<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">l<\/span> <span class=\"nx\" style=\"color: #555555;\">forever<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">log<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">a<\/span> <span class=\"nx\" style=\"color: #555555;\">app<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">js<\/span>\r\n\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/ 5. \u76d1\u542c\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u6539\u52a8<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">start<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">w<\/span> <span class=\"nx\" style=\"color: #555555;\">app<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">js<\/span><\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div style=\"color: #000000;\">\n<h6 id=\"section-3\">\u663e\u793a\u6240\u6709\u8fd0\u884c\u7684\u670d\u52a1<\/h6>\n<pre><code class=\"js\"><span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">list<\/span><\/code><\/pre>\n<\/div>\n<div style=\"color: #000000;\">\n<h6><\/h6>\n<h6 id=\"section-2\">\u6587\u4ef6\u6539\u52a8\u76d1\u542c\u5e76\u81ea\u52a8\u91cd\u542f<\/h6>\n<pre><code class=\"js\"><span class=\"c1\" style=\"color: #586e75;\">\/\/ 1. \u76d1\u542c\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u6539\u52a8\uff08\u4e0d\u592a\u5efa\u8bae\u8fd9\u6837\uff09<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">start<\/span> <span class=\"o\" style=\"color: #859900;\">-<\/span><span class=\"nx\" style=\"color: #555555;\">w<\/span> <span class=\"nx\" style=\"color: #555555;\">app<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">js<\/span><\/code><\/pre>\n<h6><\/h6>\n<h6 id=\"section-4\">\u505c\u6b62\u64cd\u4f5c<\/h6>\n<\/div>\n<div style=\"color: #000000;\">\n<pre><code class=\"js\"><span class=\"c1\" style=\"color: #586e75;\">\/\/ 1. \u505c\u6b62\u6240\u6709\u8fd0\u884c\u7684node App<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">stopall<\/span>\r\n\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/ 2. \u505c\u6b62\u5176\u4e2d\u4e00\u4e2anode App<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">stop<\/span> <span class=\"nx\" style=\"color: #555555;\">app<\/span><span class=\"p\" style=\"color: #93a1a1;\">.<\/span><span class=\"nx\" style=\"color: #555555;\">js<\/span>\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/ \u5f53\u7136\u8fd8\u53ef\u4ee5\u8fd9\u6837<\/span>\r\n<span class=\"c1\" style=\"color: #586e75;\">\/\/ forever list \u627e\u5230\u5bf9\u5e94\u7684uid\uff0c\u7136\u540e\uff1a<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">stop uid<\/span><\/code><\/pre>\n<\/div>\n<div style=\"color: #000000;\">\n<h6><\/h6>\n<h6 id=\"section-5\">\u91cd\u542f\u64cd\u4f5c<\/h6>\n<p style=\"color: #404040;\">\u91cd\u542f\u64cd\u4f5c\u8ddf\u505c\u6b62\u64cd\u4f5c\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<div class=\"highlight\">\n<pre><code class=\"js\"><span class=\"c1\" style=\"color: #586e75;\">\/\/ 1. \u542f\u52a8\u6240\u6709<\/span>\r\n<span class=\"nx\" style=\"color: #555555;\">forever<\/span> <span class=\"nx\" style=\"color: #555555;\">restartall<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<p><a href=\"http:\/\/blog.csdn.net\/jbboy\/article\/details\/35281225\" target=\"_blank\">\u00a0http:\/\/blog.csdn.net\/jbboy\/article\/details\/35281225<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7c7b\u4f3c\u7684\u8fd8\u6709pm2\uff0c\u300anode.js\u7f51\u7ad9\u53d1\u5e03\u5de5\u5177\u6a21\u5757\u2014pm2\u300b Github\u5730\u5740\uff1ahttps:\/\/github. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,39],"tags":[],"class_list":["post-5513","post","type-post","status-publish","format-standard","hentry","category-nodejs","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5513"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5513\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}