Running Stash as a Linux service
For production use on a Linux server, Stash should be configured to run as a Linux service, that is, as a daemon process. This has the following advantages:
- Stash can be automatically restarted when the operating system restarts.
- Stash can be automatically restarted if it stops for some reason.
- Stash is less likely to be accidentally shut down, as can happen if the terminal Stash was manually started in is closed.
- Logs from the Stash JVM can be properly managed by the service.
This page describes the following approaches to running Stash as a service on Linux:
- Use the Java Service Wrapper, which allows a Java application to be run as a UNIX daemon.
- Use an
init.dscript to start Stash at boot time - this doesn't restart Stash if it stops for some reason.
- Use a systemd unit file to start Stash at boot time - this doesn't restart Stash if it stops for some reason.
Note that Stash assumes that the external database is available when it starts; these approaches do not support service dependencies, and the startup scripts will not wait for the external database to become available.
On this page:
Using the Java Service Wrapper
The Service Wrapper provides the following benefits:
- Allows Stash, which is a Java application, to be run as a service.
- No need for a user to be logged on to the system at all times, or for a command prompt to be open and running on the desktop to be able to run Stash.
- The ability to run Stash in the background as a service, for improved convenience, system performance and security.
- Stash is launched automatically on system startup and does not require that a user be logged in.
- Users are not able to stop, start, or otherwise tamper with Stash unless they are an administrator.
- Can provide advanced failover, error recovery, and analysis features to make sure that Stash has the maximum possible uptime.
Please see http://wrapper.tanukisoftware.com/doc/english/launch-nix.html for wrapper installation and configuration instructions.
The service wrapper supports the standard commands for SysV init scripts, so it should work if you just create a symlink to it from
Using an init.d script
The usual way on Linux to ensure that a process restarts at system restart is to use an init.d script. This approach does not restart Stash if it stops by itself.
Create a stash user, set the permissions to that user, create a home directory for Stash and create a symlink to make upgrades easier:
(Be sure to replace X.Y.Z in the above commands with the version number of Stash.)
Create the startup script in
/etc/init.d/stashwith the following contents (Ensure the script is executable by running
chmod 755 stash):
Running on system boot
To start on system boot, add the script to the start up process.
For Ubuntu (and other Debian derivatives) use:
For RHEL (and derivates) use:
Note: You may have to install the
redhat-lsbpackage on RHEL (or derivatives) to provide the LSB functions used in the script.
Verify that the Stash service comes back up after restarting the machine.
Using a systemd unit file
Thanks to Patrick Nelson for calling out this approach, which he set up for a Fedora system. It also works on other distributions that use systemd as the init system. This approach does not restart Stash if it stops by itself.
stash.servicefile in your
/etc/systemd/system/directory with the following lines:
The value for
Usershould be adjusted to match the user that Stash runs as.
ExecStopshould be adjusted to match the path to your
<Stash installation directory>.
Enable the service to start at boot time by running the following in a terminal:
- Stop Stash, then restart the system, to check that Stash starts as expected.
- Use the following commands to manage the service:
Disable the service:
Check that the service is set to start at boot time:
Manually start and stop the service:
Check the status of Stash:
Was this helpful?
Thanks for your feedback!