永远在后台运行peerjs服务器

时间:2015-05-16 16:59:03

标签: javascript node.js forever peer

我在远程服务器上安装了peerjs服务器。我可以通过putty SSH登录我的服务器。我可以运行服务器但是当我关闭putty它结束会话并且peerjs停止。如何让它在服务器中永久运行。

我已经尝试了这样的包裹。

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: peerjs
error:   Cannot start forever
error:   script /root/peerjs does not exist.

但是发现了这个错误。

     <div class="row" style="margin-bottom:50px;">
                        <!-- First, the loop checks whether any posts were discovered with the have_posts() function. -->
                        <?php if (have_posts()) : ?>
                        <!-- First, the loop checks whether any posts were discovered with the have_posts() function. -->
                        <!-- If there were any posts, a PHP while loop is started. A while loop will continue to execute as long as the condition in the parenthesis is logically true. So, as long as the function have_posts() returns a true value, the while loop will keep looping (repeating). -->
                        <?php while (have_posts()) : the_post(); ?>
                        <a href="<?php echo get_permalink(); ?>">
                         <?php echo "<div class='col-md-6 col-sm-6 col-xs-12' style='margin-bottom:30px;'>"; ?>
                         <div class="row mobilemargin">
                              <div class="categorytiletext">
                                    <div class="col-md-6 col-sm-12 col-xs-12 nopr"><?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'newimgheight hovereffect')); ?> </div>
                                    <div class="col-md-6 col-sm-12 col-xs-12 mobilewhite">
                                          <div class="testdiv">
                                               <h5 class="captext"><?php the_title(); ?></h5>
                                               <?php $trimexcerpt = get_the_excerpt();

                                               $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… ' ); 

                                               echo '<a href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>'; 

                                               ?>
                                         </div>
                                   </div>
                             </div>
                       </div>
                       <?php echo "</div>"; ?>

                 </a>
                 <!-- If there is no posts, display an error message -->
           <?php endwhile; else: ?>
           <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
     <?php endif; ?>
     <!-- If there is no posts, display an error message -->
</div>

3 个答案:

答案 0 :(得分:1)

只需添加这两行

即可创建自定义服务器,从而解决了这个问题
var PeerServer = require('peer').PeerServer;
var server = PeerServer({port: 9000, path: '/peerjs'});

node_modules/peer/node_modules/we/index.js文件 然后使用

运行服务器
forever start node_modules/peer/node_modules/we/index.js

答案 1 :(得分:1)

您只需在peerjs命令之后添加关键字“&”,它将在腻子中继续在后台运行。

示例。 peerjs-端口3001&

答案 2 :(得分:0)

您可以从代码运行(启动)对等服务器:

var PeerServer = require('peer').PeerServer;
var server = PeerServer({port: 443, path: '/peerjs'});