我有一个 nodejs 应用程序,我想将它作为 oracle linux 服务器中的一项服务运行。 我已经创建了服务文件/etc/init.d/wsdlsrv 然后我运行这个命令:
cd /etc/init.d
chmod +x wsdlsrv
/sbin/chkconfig wsdlsrv on
systemctl start wsdlsrv
wsdlsrv 代码如下:
user="root"
. /etc/init.d/functions
export PATH="/usr/local/bin/:/usr/bin/:$PATH"
name='wsdlsrv'
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "/home/wsdlsrv"
su $user -c "node app" >> "$stdout_log" 2>> "$stderr_log" &
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
但是,当我尝试使用 systemclt 启动服务时,它抛出错误:wsdlsrv.service 的作业失败,因为控制进程退出并显示错误代码。有关详细信息,请参阅“systemctl status wsdlsrv.service”和“journalctl -xe”。wsdlsrv.service 的作业失败,因为控制进程退出并显示错误代码。有关详细信息,请参阅“systemctl status wsdlsrv.service”和“journalctl -xe”。
最佳答案
您是否尝试过使用 service wsdlsrv start
?
确保/etc/sysconfig/wsdlsrv 中至少有空文件条目
[root@centos ~]# cat /etc/sysconfig/wsdlsrv
# TODO: add relevant configuration stuff here.
然后您需要通过执行systemctl daemon-reload
来重新加载systemctl 守护进程。
之后你可以使用 systemctl status wsdlsrv
, systemctl start wsdlsrv
等
例如:
[root@centos init.d]# systemctl status wsdlsrv
● wsdlsrv.service - (null)
Loaded: loaded (/etc/rc.d/init.d/wsdlsrv; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2017-03-14 17:12:47 EDT; 7min ago
Docs: man:systemd-sysv-generator(8)
Mar 14 17:12:47 centos systemd[1]: Starting (null)...
Mar 14 17:12:47 centos systemd[1]: wsdlsrv.service: control process exited, code=exited status=203
Mar 14 17:12:47 centos systemd[1]: Failed to start (null).
Mar 14 17:12:47 centos systemd[1]: Unit wsdlsrv.service entered failed state.
Mar 14 17:12:47 centos systemd[1]: wsdlsrv.service failed.
您可以使用 journalctl -xe
查看来自 systemd 的错误消息
关于node.js - 在 Oracle linux 中为 nodejs 应用程序创建服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42795961/