Buddhika Ariyaratne
Buddhika Ariyaratne

Reputation: 2433

Payara Server Start as a service

I want payara server to run as a service. I logged to asadmin as sudo and used the create-service command. The following output is given.

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.

This create payara_production script in the /etc/init.d/ folder, yet once the computer is restarted, this script is not executed. I have to manually start payara to run it.

What does it mean by "You have created the service but you need to start it yourself", I had no similar issue with the versions of GlassFish I used earlier.

How can I start Payara as a service?

Upvotes: 1

Views: 4379

Answers (1)

Ondro Mihályi
Ondro Mihályi

Reputation: 7760

Payara Server (and also GlassFish) create a service using the System V mechanism. This mechanism is outdated and not well supported by newer Linux systems. Most modern Linux distributions use SystemD, which supports starting/stopping System V services using the system command but not directly enabling them at boot without any modification.

Your Linux distribution most probably uses SystemD. To run a service at boot time, you can follow this guide: https://linoxide.com/linux-how-to/enable-disable-services-ubuntu-systemd-upstart/. If you by any chance have access to Payara Support portal, you can follow this detailed guide: https://support.payara.fish/hc/en-gb/articles/360034527494-Configure-a-Payara-Server-Domain-as-a-System-Service

In short, you need to create a service file in /etc/systemd/system/ or any other folder where SystemD expects it. This file should contain ExecStart instruction to start the service, in your case /etc/init.d/payara_production start. If you want that it starts at boot also after a crash, add the `Restart=always" instruction.

If your service file is named payara.service, you can enable the service at boot with:

sudo systemctl enable payara

Edit:

Alternatively, you can run the service created by Payara Server at boot using SystemD if you modify the script to add some headers in a comment, as described here: https://serverfault.com/questions/849507/systemctl-doesnt-recognize-my-service-default-start-contains-no-runlevels-abo

For example, add this comment right below the #!/bin/sh line:

### 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

And then you can install it using the SystemD command:

systemctl enable payara_production.service

Upvotes: 2

Related Questions