{"id":6656,"date":"2014-09-13T17:08:12","date_gmt":"2014-09-13T09:08:12","guid":{"rendered":"http:\/\/jpuyy.com\/?p=6656"},"modified":"2014-11-04T16:26:12","modified_gmt":"2014-11-04T08:26:12","slug":"nodejs-forever","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=6656","title":{"rendered":"nodejs-forever"},"content":{"rendered":"<p class=\"p1\">node.js\u7684forever\u53ef\u4fdd\u8bc1\u8fdb\u7a0b\u6302\u6389\u4e4b\u540e\u91cd\u542f\uff0c\u4fdd\u8bc1\u9ad8\u53ef\u7528<\/p>\n<p class=\"p1\">Monitors the script specified in the current process or as a daemon<\/p>\n<p class=\"p1\"><span class=\"s1\">[<\/span><span class=\"s2\">Daemon<\/span><span class=\"s1\">]<\/span><span class=\"s2\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span><\/span><\/p>\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 <\/span>The forever process will run as a daemon which will make the target process start<\/p>\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 <\/span>in the background. This is extremely useful for remote starting simple node.js scripts<\/p>\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 <\/span>without using nohup. It is recommended to run start with -o -l, &amp; -e.<\/p>\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 <\/span>ex. forever start -l forever.log -o out.log -e err.log my-daemon.js<\/p>\n<p class=\"p1\">\u5e38\u7528\u52a8\u4f5c\u6709<\/p>\n<p>start Start SCRIPT as a daemon<br \/>\nstop Stop the daemon SCRIPT<br \/>\nstopall Stop all running forever scripts<br \/>\nrestart Restart the daemon SCRIPT<br \/>\nrestartall Restart all running forever scripts<br \/>\nlist List all running forever scripts<br \/>\nconfig Lists all forever user configuration<br \/>\nset Sets the specified forever config<br \/>\nclear Clears the specified forever config<br \/>\nlogs Lists log files for all forever processes<br \/>\nlogs &lt;script|index&gt; Tails the logs for &lt;script|index&gt;<br \/>\ncolumns add<br \/>\nAdds the specified column to the output in `forever list`<br \/>\ncolumns rm<br \/>\nRemoved the specified column from the output in `forever list`<br \/>\ncolumns set Set all columns for the output in `forever list`<br \/>\ncolumns reset Resets all columns to defaults for the output in `forever list`<br \/>\ncleanlogs [CAREFUL] Deletes all historical forever log files<\/p>\n<p>\u4f8b\u5b50:<\/p>\n<p>\u67e5\u770b\u88abforever\u542f\u52a8\u7684\u8fdb\u7a0b<\/p>\n<pre>forever list<\/pre>\n<p>\u91cd\u542f\u5177\u4f53\u67d0\u4e00\u4e2a\u811a\u672c\uff0c\u5982\u679c\u4e0d\u77e5\u9053\u7edd\u5bf9\u8def\u5f84\uff0cforever\u4f1a\u81ea\u52a8\u5339\u914d\u91cd\u542f<\/p>\n<pre>forever restart myscript.js<\/pre>\n<p>&#8211;sourceDir\u6307\u5b9ajs\u811a\u672c\u4f4d\u7f6e<\/p>\n<pre class=\"p1\">forever\u00a0stop --sourceDir=\/data\/nodejs\/ start.js<\/pre>\n<p class=\"p1\">-l \u6307\u5b9alog\u6240\u5728\u4f4d\u7f6e\uff0c -e \u6307\u5b9a\u9519\u8bef\u65e5\u5fd7\uff0c-o\u6307console\u7684\u8f93\u51fa\uff0c-a \u8ffd\u52a0\u7684\u65b9\u5f0f\uff0c\u5e73\u65f6\u4f7f\u7528\u65f6\u6700\u597d\u628a-l, -e, -o\u5168\u7528\u4e0a\u3002<\/p>\n<pre class=\"p1\">forever start -l \/var\/log\/nodejs\/log -e \/var\/log\/nodejs\/error -o \/var\/log\/nodejs\/out.log\u00a0-a --sourceDir=\/data\/nodejs start.js<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>node.js\u7684forever\u53ef\u4fdd\u8bc1\u8fdb\u7a0b\u6302\u6389\u4e4b\u540e\u91cd\u542f\uff0c\u4fdd\u8bc1\u9ad8\u53ef\u7528 Monitors the script specified in the current process or as a daemon [Daemon]\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[140],"tags":[],"class_list":["post-6656","post","type-post","status-publish","format-standard","hentry","category-nodejs"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6656"}],"version-history":[{"count":6,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6656\/revisions"}],"predecessor-version":[{"id":6802,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6656\/revisions\/6802"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}