问题描述
我希望payara服务器作为服务运行。我以sudo身份登录asadmin并使用了create-service命令。给出以下输出。
The Service was created successfully. Here are the details:
Name of the service:production
Type of the service:Domain
Configuration location of the service:/etc/init.d/payara_production
User account that will run the service: root
You have created the service but you need to start it yourself. Here are the most typical Linux commands of interest:
* /etc/init.d/payara_production start
* /etc/init.d/payara_production stop
* /etc/init.d/payara_production restart
For your convenience this message has also been saved to this file:
/home/buddhika/payara/glassfish/domains/production/PlatformServices.log
Command create-service executed successfully.
这个在/etc/init.d/文件夹中创建的payara_production脚本,但是一旦计算机重新启动,就不会执行该脚本。我必须手动启动payara才能运行它。
“您已经创建了服务,但需要自己启动它”是什么意思,我之前使用的GlassFish版本没有类似的问题。
如何启动Payara服务?
解决方法
Payara服务器(以及GlassFish)使用System V机制创建服务。这种机制已经过时,较新的Linux系统也没有很好的支持。大多数现代Linux发行版都使用SystemD,该系统支持使用system
命令启动/停止System V服务,但在启动时不进行任何修改就不能直接启用它们。
您的Linux发行版很可能使用SystemD。要在引导时运行服务,请遵循以下指南:https://linoxide.com/linux-how-to/enable-disable-services-ubuntu-systemd-upstart/。如果您有机会访问Payara支持门户,则可以按照以下详细指南进行操作:https://support.payara.fish/hc/en-gb/articles/360034527494-Configure-a-Payara-Server-Domain-as-a-System-Service
简而言之,您需要在service
或SystemD期望的任何其他文件夹中创建一个/etc/systemd/system/
文件。该文件应包含ExecStart
指令以启动服务(在您的情况下为/etc/init.d/payara_production start
)。如果您希望它在崩溃后也能在启动时启动,请添加“ Restart = always”指令。
如果您的服务文件名为payara.service
,则可以在启动时启用以下服务:
sudo systemctl enable payara
编辑:
或者,如果您修改脚本以在注释中添加一些标头,则可以在启动时使用SystemD运行Payara Server创建的服务,如此处所述:https://serverfault.com/questions/849507/systemctl-doesnt-recognize-my-service-default-start-contains-no-runlevels-abo
例如,在#!/bin/sh
行下方添加此注释:
### BEGIN INIT INFO
# Provides: payara_production
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: your description here
### END INIT INFO
然后您可以使用SystemD命令安装它:
systemctl enable payara_production.service