在Debian服务器上,我安装了Node.js. 我了解如何使用此命令行从putty启动应用程序:
node /srv/www/MyUserAccount/server/server.js
Run Code Online (Sandbox Code Playgroud)
并在地址50.51.52.53:8080(IP和端口)上找到它.
但是一旦我关闭腻子,我就再也无法到达地址50.51.52.53:8080了.
如何使Node.js应用程序永久运行?
你可以猜到,我是Linux和Node.js的初学者.
部署Node.js的最佳方法是什么?
我有一个Dreamhost VPS(他们称之为VM),我已经能够安装Node.js并设置代理.只要我保持打开节点的SSH连接,这就很好用.
在Python Twisted中,您可以使用twistd命令帮助您完成与运行应用程序相关的许多事情(例如,将其守护进程).
如何守护node.js服务器,以便即使在当前会话关闭后它也可以运行?
谢谢你的帮助
我正在尝试设置一个简单的systemd计时器,以便每天午夜运行bash脚本.
systemctl --user status backup.service 失败并记录以下内容:
backup.service: Failed at step EXEC spawning /home/user/.scripts/backup.sh: No such file or directory.
backup.service: Main process exited, code=exited, status=203/EXEC
Failed to start backup.
backup.service: Unit entered failed state.
backup.service: Failed with result 'exit-code'.
Run Code Online (Sandbox Code Playgroud)
我迷路了,因为文件和目录存在.该脚本是可执行的,只是为了检查,我甚至设置了777的权限.
一些背景:
在backup.timer和backup.service单元文件位于/home/user/.config/systemd/user.
backup.timer 已加载并处于活动状态,目前正在等待午夜.
这是它的样子:
[Unit]
Description=Runs backup at 0000
[Timer]
OnCalendar=daily
Unit=backup.service
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
这是backup.service:
[Unit]
Description=backup
[Service]
Type=oneshot
ExecStart=/home/user/.scripts/backup.sh
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
最后,这是一个意思backup.sh:
#!/usr/env/bin bash
rsync -a --delete --quiet /home/user/directory/ …Run Code Online (Sandbox Code Playgroud) 我想在node.js中使用CasperJS.
我已经引用了以下URL来在node.js中使用CasperJS:
在上述URL的帮助下,我编写了以下代码:
//DISPLAY=:0 node test2.js
var phantom = require('phantom');
console.log('Hello, world!');
phantom.create(function (ph) {
ph.casperPath = '/opt/libs/casperjs'
ph.injectJs('/opt/libs/casperjs/bin/bootstrap.js');
var casper = require('casper').create();
casper.start('http://google.fr/');
casper.thenEvaluate(function (term) {
document.querySelector('input[name="q"]').setAttribute('value', term);
document.querySelector('form[name="f"]').submit();
}, {
term: 'CasperJS'
});
casper.then(function () {
// Click on 1st result link
this.click('h3.r a');
});
casper.then(function () {
console.log('clicked ok, new location is ' + this.getCurrentUrl());
});
casper.run();
});
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我收到以下错误:
错误味精:
tz@tz-ubuntu:/opt/workspaces/TestPhantomjs$ DISPLAY=:0 node test2.js
Hello, world!
Error: Cannot find module 'casper'
at Function._resolveFilename (module.js:332:11)
at …Run Code Online (Sandbox Code Playgroud) 我有一个perl脚本,可以将ENV变量设置为指向特定输出,例如$ debug,$ verbose,$ develop等
通常我从命令行运行它们
$ VERBOSE=1 perl myperlscript.pl params
Run Code Online (Sandbox Code Playgroud)
我现在想用nohup来运行它们.使用命令行
$ nohup VERBOSE=1 perl myperlscript.pl params
Run Code Online (Sandbox Code Playgroud)
显然是不对的,因为设置ENV {VERBOSE}的尝试被解释为nohup的一个参数并且我获得了msg
nohup:无法运行命令`VERBOSE = 1':没有这样的文件或目录
这里的语法是什么?我试图在Linux机器上运行它.
我试图在我的Windows服务器上安装node.js的forever模块,但是出现了这个错误:
C:\rts_lobby>npm install forever
npm http GET https://registry.npmjs.org/forever
npm http 200 https://registry.npmjs.org/forever
npm http GET https://registry.npmjs.org/forever/-/forever-0.8.5.tgz
npm http 200 https://registry.npmjs.org/forever/-/forever-0.8.5.tgz
(...snip...)
npm http GET https://registry.npmjs.org/parse-table
> microtime@0.2.0 install C:\rts_lobby\node_modules\forever\node_modules\microti
me
> node-waf configure build
npm http GET https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/lazy
npm http GET https://registry.npmjs.org/eventemitter2
'node-waf' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! error installing microtime@0.2.0
npm http GET https://registry.npmjs.org/prompt/0.1.12
(...snip...)
npm http GET https://registry.npmjs.org/mkdirp
> node-fork@0.4.1 preinstall C:\rts_lobby\node_modules\forever\node_modules\node
-fork …Run Code Online (Sandbox Code Playgroud) 我正在为一个应用程序使用Ionic框架和nodejs。所有的nodejs文件都在linux服务器中。我正在通过腻子使用'npm start&'命令启动nodejs服务器。但是问题是如果我关闭腻子,服务器将在一段时间后停止。我尝试了“ nohup npm start&”。但是我仍然面临着同样的问题。如何将其作为守护进程启动。
我启动node.js服务器有nohup的3000端口用于后台运行,但现在我想node.js用3000停止服务器并再次使用相同的端口启动.我怎么能停止这个过程?
我可以用这个命令让进程杀死;
ps -a","ps -ef |grep nohup
Run Code Online (Sandbox Code Playgroud)
但它回归;
-bash: kill: (11929) - No such process
Run Code Online (Sandbox Code Playgroud)
谢谢
嗨,我是使用 Code Deploy 的新手。我正在尝试启动一个节点应用程序。我的根目录中有 setup.sh、start.sh 和 app.js。
这是我的 appspec.yml 文件
version: 0.0
os: linux
files:
- source: /
destination: /
hooks:
Install:
- location: setup.sh
timeout: 3600
ApplicationStart:
- location: start.sh
timeout: 3600
Run Code Online (Sandbox Code Playgroud)
设置文件
yum -y install nodejs npm --enablerepo=epel
npm install
Run Code Online (Sandbox Code Playgroud)
启动文件
node /app.js
Run Code Online (Sandbox Code Playgroud)
app.js(只是一个基本的虚拟服务器)
var express = require("express");
var app = express();
app.get("/",function(req,res) {
res.send("Hello world")
})
var server = app.listen(8080,function() {
console.log("Listening at " + server.address().address + ": " + server.address().port);
});
Run Code Online (Sandbox Code Playgroud)
安装步骤成功完成,但代码部署在执行 ApplicationStart 步骤时卡在挂起状态。
我很确定这是因为 app.js …