Running Payara Server as a Service - Added Support for systemD on Linux

Photo of Rudy De Busscher by Rudy De Busscher

Before your application can respond to any request from the user, Payara Server needs to be started as a process on a machine. The Payara Server Domain instance or a Payara instance can be started using the Asadmin CLI tool.

But in many cases when you run Payara Server on an on-premise machine or in a virtual machine, you want to start the Payara process automatically when the machine is booted. You can do this by defining Payara as a Service on the machine.

Depending on which operating system you use and the type of software installed on Linux, a certain file needs to be created. The Asadmin CLI tool can help you with this task and create these files so that you can install Payara Server as a Service very easily.

Support for systemD

With the November 2021 release, we have added support for systemD on Linux besides the support for systemV.

This is the command to define the domain1 as a service on Linux

./asadmin create-service --service-user payaraadmin domain1

First of all, the command detects if it should use systemD or systemV configuration files. If it detects that systemD is installed, it creates the file /etc/systemd/system/payara_domain1.service with all the options to start Payara Server when the machine boots up.

The --service-user option is required in most cases as the creation of the files and the execution of the service requires a user with system privileges.  If you omit this option, the user executing the Asadmin command is used. In the above example, payaraadmin user should be defined and have all the required permissions.

You can edit this file to customize the startup for your environment. Payara itself will not access the file, only the service component of the Operating System will use the file.  You can also use the --serviceproperties option of the create-service command to define environment variables that are needed for the Payara Server process.

If you do not want to rely on the auto-detection or want to override it, you can use the option --system-type.

./asadmin create-service --service-user payaraadmin --system-type systemv domain1

The above command will always use the systemV to define Payara as a Service, regardless of what is available on the machine.

Once the file is created, you can try it out by performing the commands:

systemctl daemon-reload
systemctl start payara_domain1.service

This way, you can verify all setup is done correctly and you can be confident that Payara Server starts next time the machine is rebooted.

You can read more on our documentation page.

Support for Windows

Besides the support for running Payara as a Service on Linux alike systems, we also support the same functionality on Windows.

The required steps are similar to what is described above with a few differences

  • You can't specify the --serviceuser option and must run the command as a user with OS-level administrator rights.
  • The Microsoft .NET framework needs to be installed and accessible for the user.
  • You can define the name of the service using the --name option of the command line if you want to override the default which is the domain name.

Once the service file is created, you can manipulate it just as any other Windows service, for example:

net start domain1

Delete the Service

If you no longer need the service, you can undo the actions of the crate-service command by executing the delete-service Asadmin command.

This command removes the necessary files so that Payara Server is no longer started when the machine is restarted.

Define Payara as a Service on Linux with systemD

With the November 2021 release, we have added support for systemD to define Payara as a Service on Linux machines as the component is gaining popularity over systemV.

To make it easy for the user, we added an auto-detection mechanism so that the Asadmin command itself determines if it should use the newly supported systemD, or if it should still use the systemV way as we supported in the past. However, you can override this by specifying the --system-type option if you want to force one of the other system.

 Payara Platform  Download Here 

 

Comments