[英]Upstart / init script not working
I'm trying to create a service / script to automatically start and controll my nodejs server, but it doesnt seem to work at all. 我试图创建一个服务/脚本来自动启动和控制我的nodejs服务器,但是它似乎根本不起作用。
First of all, I used this source as main reference http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/ 首先,我将此来源用作主要参考http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/
After testing around, I minimzed the content of the actual file to avoid any kind of error, resulting in this (the bare minimum, but it doesnt work) 经过测试后,我将实际文件的内容最小化以避免任何类型的错误,从而导致这种情况(最低限度,但它不起作用)
description "server"
author "blah"
start on started mountall
stop on shutdown
respawn
respawn limit 99 5
script
export HOME="/var/www"
exec nodejs /var/www/server/server.js >> /var/log/node.log 2>&1
end script
The file is saved in /etc/init/server.conf
该文件保存在/etc/init/server.conf
when trying to start the script (as root, or normal user), I get: 尝试以root或普通用户身份启动脚本时,我得到:
root@iof304:/etc/init# start server
start: Job failed to start
Then, I tried to check my syntax with init-checkconf
, resulting in: 然后,我尝试使用init-checkconf
检查我的语法,结果是:
$ init-checkconf /etc/init/server.conf
File /etc/init/server.conf: syntax ok
I tried different other things, like initctl reload-configuration
with no result. 我尝试了其他不同的操作,例如initctl reload-configuration
,但没有结果。
What can I do? 我能做什么? How can I get this to work? 我该如何工作? It can't be that hard, right? 没那么难吧?
This is what our typical startup script looks like. 这就是我们典型的启动脚本的样子。 As you can see we're running our node processes as user nodejs. 如您所见,我们以用户nodejs的身份运行节点进程。 We're also using the pre-start script to make sure all of the log file directories and .tmp directories are created with the right permissions. 我们还使用启动前脚本来确保所有日志文件目录和.tmp目录都具有正确的权限。
#!upstart
description "grabagadget node.js server"
author "Jeffrey Van Alstine"
start on started mysql
stop on shutdown
respawn
script
export HOME="/home/nodejs"
exec start-stop-daemon --start --chuid nodejs --make-pidfile --pidfile /var/run/nodejs/grabagadget.pid --startas /usr/bin/node -- /var/nodejs/grabagadget/app.js --environment production >> /var/log/nodejs/grabagadget.log 2>&1
end script
pre-start script
mkdir -p /var/log/nodejs
chown nodejs:root /var/log/nodejs
mkdir -p /var/run/nodejs
mkdir -p /var/nodejs/grabagadget/.tmp
# Git likes to reset permissions on this file, but it really needs to be writable on server start
chown nodejs:root /var/nodejs/grabagadget/views/layout.ejs
chown -R nodejs:root /var/nodejs/grabagadget/.tmp
# Date format same as (new Date()).toISOString() for consistency
sudo -u nodejs echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/nodejs/grabagadget.log
end script
pre-stop script
rm /var/run/nodejs/grabagadget.pid
sudo -u nodejs echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/nodejs/grabgadget.log
end script
从Ubuntu 15开始,不再使用暴发户,请参见systemd。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.