首页 > 解决方案 > Payara 服务器作为服务启动

问题描述

我希望 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 作为服务启动?

标签: glassfishpayara

解决方案


Payara Server(以及 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-系统服务

简而言之,您需要在 SystemD 期望的任何其他文件夹中创建一个service文件。/etc/systemd/system/在您的情况下,此文件应包含ExecStart启动服务的说明/etc/init.d/payara_production start。如果您希望它在崩溃后也能在启动时启动,请添加“Restart=always”指令。

如果您的服务文件名为payara.service,您可以在启动时启用该服务:

sudo systemctl enable payara

编辑:

或者,如果您修改脚本以在注释中添加一些标头,您可以在启动时使用 SystemD 运行 Payara 服务器创建的服务,如下所述: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

推荐阅读