我尝试将nodejs作为服务运行,如此步骤
1- sudo vim servicelocator.conf
2- past this .conf
description "node.js server"
author "mahmoud elgohary"
# Used to Be: Start on Startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown
# Automatically Respawn:
respawn
respawn limit 99 5
script
# Not sure why $HOME is needed, but we found that it is:
export HOME="/root"
exec /usr/bin/node /var/lib/nodejsproject/servicelocator/server.js >> /var/log/node.log 2>&1
end script
post-start script
# Optionally put a script here that will notifiy you node has (re)started
# /root/bin/hoptoad.sh "node.js has started!"
end script
3- init-checkconf /etc/init/servicelocator.conf
错误:文件/etc/init/servicelocator.conf:语法无效:init:servicelocator.conf:1:Unknown stanza
4-
ubuntu@ip-172-31-37-243:/etc/init$ sudo start servicelocator
start: Unknown job: servicelocator
答案 0 :(得分:2)
我是用暴发户做到的:
var_dump(
str_replace(
['/', '-', '.'],
'',
ucwords(
$acceptContentType, '/-.'
)
)
);
sudo apt-get install upstart
sudo vim /etc/init/servicelocator.conf
并插入以下文字:servicelocator.conf
#!upstart description "servicelocator"
start on runlevel [2345] stop on runlevel [06]
#Automatically Respawn: respawn respawn limit 99 5
保存并关闭文件。
要启动该服务:exec /usr/bin/node /var/lib/nodejsproject/servicelocator/server.js >>
/var/log/node.log
答案 1 :(得分:0)
我的最佳答案
1-运行sudo vim servicelocator.conf
2-超过此配置
description "node.js server"
author "mahmoud elgohary"
#!upstart
description "servicelocator"
start on runlevel [2345]
stop on runlevel [06]
# Automatically Respawn:
respawn
respawn limit 99 5
script
# Not sure why $HOME is needed, but we found that it is:
export HOME="/root"
exec /usr/bin/nodejs /var/lib/nodejsproject/servicelocator/server.js >> /var/log/node.log 2>&1
end script
post-start script
# Optionally put a script here that will notifiy you node has (re)started
# /root/bin/hoptoad.sh "node.js has started!"
end script
3-按Esc和wirte :wq
5- sudo apt-get install upstart
6- sudo start servicelocator