Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
muuki88 committed May 21, 2016
1 parent 17ab0f9 commit 1d34fad
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport.RpmConstants
import com.typesafe.sbt.packager.archetypes.systemloader.ServerLoader

/**
* This class contains the default settings for creating and deploying an archetypical Java application.
* A Java application archetype is defined as a project that has a main method and is run by placing
* all of its JAR files on the classpath and calling that main method.
* == Java Server App Packaging ==
*
* This doesn't create the best of distributions, but it can simplify the distribution of code.
* Provides configuration for running an application on a server.
*
* @see [[http://sbt-native-packager.readthedocs.io/en/latest/archetypes/java_server/index.html]]
*/
object JavaServerAppPackaging extends AutoPlugin {
import ServerLoader._
Expand Down Expand Up @@ -177,7 +176,7 @@ object JavaServerAppPackaging extends AutoPlugin {

/**
* Loads an available script from the native-packager source if available.
*
*
* @param config for which plugin (Debian, Rpm)
* @param replacements for the placeholders
* @param scriptName that should be loaded
Expand Down
47 changes: 0 additions & 47 deletions src/sphinx/archetypes/akka_app.rst

This file was deleted.

2 changes: 1 addition & 1 deletion src/sphinx/archetypes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ of them for usage.

Java Command Line Application <java_app/index.rst>
Java Server Application <java_server/index.rst>
Akka App [DEPRECATED] <akka_app.rst>
Systemloaders <systemloaders.rst>
Configuration Archetypes <misc_archetypes.rst>
An archetype cheatsheet <cheatsheet.rst>
100 changes: 4 additions & 96 deletions src/sphinx/archetypes/java_server/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,103 +67,11 @@ Windows Configuration
Support planned.


Service Manager Configuration
=============================
Systemloader Configuration
==========================

It is possible to change the default Service Manager for a given platform by specifying a ``ServerLoader``. To use
Upstart for an Rpm package simply:

.. code-block:: scala
import com.typesafe.sbt.packager.archetypes.ServerLoader
serverLoading in Rpm := ServerLoader.Upstart
*As a side note Fedora/RHEL/Centos family of linux specifies* ``Default requiretty`` *in its* ``/etc/sudoers``
*file. This prevents the default Upstart script from working correctly as it uses sudo to run the application
as the* ``daemonUser`` *. Simply disable requiretty to use Upstart or modify the Upstart template.*

Customize Start Script
----------------------

Sbt Native Packager leverages templating to customize various start/stop scripts and pre/post install tasks.
As an example, to alter the ``loader-functions`` which manage the specific start and stop process commands
for SystemLoaders you can to the ``linuxScriptReplacements`` map:

.. code-block:: scala
import com.typesafe.sbt.packager.archetypes.TemplateWriter
linuxScriptReplacements += {
val functions = sourceDirectory.value / "templates" / "custom-loader-functions"
// Nil == replacements. If you want to replace stuff in your script put them in this Seq[(String,String)]
"loader-functions" -> TemplateWriter.generateScript(functions.toURL, Nil)
}
which will add the following resource file to use start/stop instead of initctl in the post install script:

.. code-block:: bash
startService() {
app_name=$1
start $app_name
}
stopService() {
app_name=$1
stop $app_name
}
The :doc:`debian </formats/debian>` and :doc:`redhat </formats/rpm>` pages have further information on overriding
distribution specific actions.

Override Start Script
-----------------------------------------------

It's also possible to override the entire script/configuration for your service manager.
Create a file ``src/templates/$format/$loader`` and it will be used instead.

Possible values:

* ``$format`` - ``debian`` or ``rpm``
* ``$loader`` - ``upstart``, ``systemv`` or ``systemd``

**Syntax**

You can use ``${{variable_name}}`` to reference variables when writing your script. The default set of variables is:

* ``descr`` - The description of the server.
* ``author`` - The configured author name.
* ``exec`` - The script/binary to execute when starting the server
* ``chdir`` - The working directory for the server.
* ``retries`` - The number of times to retry starting the server.
* ``retryTimeout`` - The amount of time to wait before trying to run the server.
* ``app_name`` - The name of the application (linux friendly)
* ``app_main_class`` - The main class / entry point of the application.
* ``app_classpath`` - The (ordered) classpath of the application.
* ``daemon_user`` - The user that the server should run as.


SystemD Support
---------------

There is also experimental SystemD support for Fedora release 20 (Heisenbug). You can use the ```Systemd``` server loader:

.. code-block:: scala
import com.typesafe.sbt.packager.archetypes.ServerLoader
serverLoading in Rpm := ServerLoader.Systemd
There is only partial systemd support in Ubuntu 14.04 LTS which prevents sbt-native-packager systemd from working correctly on
Ubuntu. Ubuntu 15.04 is the first version that switched to Systemd and the default Upstart won't work. Switch to Systemd with

.. code-block:: scala
import com.typesafe.sbt.packager.archetypes.ServerLoader
serverLoading in Debian := ServerLoader.Systemd
See the :ref:`systemloaders` documentation on how to add a systemloader (e.g. SystemV, Systemd or Upstart) to your
package.

Package Lifecycle Configuration
===============================
Expand Down
37 changes: 4 additions & 33 deletions src/sphinx/archetypes/java_server/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ Features

The *JavaServerAppPackaging* archetype depends on the :ref:`java-app-plugin` and adds the following features

* install/uninstall services
* daemon user/group support
* default mappings for server applications
* ``/var/log/<pkg>`` is symlinked from ``<install>/logs``
* ``/var/run/<pkg>`` owned by ``daemonUser``
* Creates a start script in for the configured system loader (SystemV, Upstart or SystemD)

* ``etc-default`` support

Usage
=====
Expand All @@ -32,6 +31,8 @@ Usage
Everything else works the same way as the :ref:`java-app-plugin`.

.. tip:: If you want your application to be registered as a service enable a :ref:`systemloaders` plugin.

Settings & Tasks
================

Expand All @@ -53,21 +54,6 @@ have sensible defaults.
``daemonShell``
Shell provided for the daemon user

``serverLoading``
Loading system to be used for application start script (SystemV, Upstart, Systemd)

``startRunlevels``
Sequence of runlevels on which application will start up

``stopRunlevels``
Sequence of runlevels on which application will stop

``requiredStartFacilities``
Names of system services that should be provided at application start

``requiredStopFacilities``
Names of system services that should be provided at application stop

``daemonStdoutLogFile``
Filename stdout/stderr of application daemon. Now it's supported only in SystemV

Expand Down Expand Up @@ -98,21 +84,6 @@ this `native packager discussion`_.
If you want to change something in this predefined structure read more about it in
the :doc:`linux section </formats/linux>`.

Service Managers
================

Platforms are tied to both package managers (Rpm, Debian) and Service Managers (System V, Upstart, SystemD). By
default the native packager will configure a service manager to run the daemon process. The default configurations are:

+---------------+--------------------+
| Package Format| Service Manager |
+===============+====================+
| Debian | Upstart (Default) |
+---------------+--------------------+
| Rpm | SystemV (Default) |
+---------------+--------------------+

See the :ref:`server-app-customize` section on how to change these.

.. _server-app-customize:

Expand Down
135 changes: 135 additions & 0 deletions src/sphinx/archetypes/systemloaders.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
.. _systemloaders:

Systemloaders
=============

SBT native packager provides support for different systemloaders in order to register your application as a service on
your target system, start it automatically and provide systemloader specific configuration.

.. tip:: You can use systemloaders with the :ref:`java-app-plugin` or the :ref:`java-server-plugin`!

Overview
--------

There is a generic ``SystemloaderPlugin`` which configures default settings and requires necessary plugins. It gets
triggered automatically, when you enable a specific systemloader plugin. If you want to implement your own loader,
you should require the ``SystemloaderPlugin``.

General Settings
~~~~~~~~~~~~~~~~

``serverLoading``
Loading system to be used for application start script (SystemV, Upstart, Systemd).
This setting can be used to trigger systemloader specific behaviour in your build.

``startRunlevels``
Sequence of runlevels on which application will start up

``stopRunlevels``
Sequence of runlevels on which application will stop

``requiredStartFacilities``
Names of system services that should be provided at application start

``requiredStopFacilities``
Names of system services that should be provided at application stop


SystemV
-------

Native packager provides different SysV scripts for ``rpm`` (CentOS, RHEL, Fedora) and ``debian`` (Debian, Ubuntu)
package based systems. Enable SystemV with:

.. code-block:: scala
enablePlugins(SystemVPlugin)
The :ref:`java-server-plugin` provides a ``daemonStdoutLogFile`` setting, that you can use to redirect the systemV
output into a file.

Systemd
-------

In order to enable Systemd add this plugin:

.. code-block:: scala
enablePlugins(SystemdPlugin)
Upstart
-------

SystemV alternative developed by `Ubuntu <http://upstart.ubuntu.com/>`_. Native packager adds support for rpm as well,
but we recommend using Systemd if possible.

.. code-block:: scala
enablePlugins(UpstartPlugin)
*As a side note Fedora/RHEL/Centos family of linux specifies* ``Default requiretty`` *in its* ``/etc/sudoers``
*file. This prevents the default Upstart script from working correctly as it uses sudo to run the application
as the* ``daemonUser`` *. Simply disable requiretty to use Upstart or modify the Upstart template.*

Customization
-------------

Customize Start Script
~~~~~~~~~~~~~~~~~~~~~~

Sbt Native Packager leverages templating to customize various start/stop scripts and pre/post install tasks.
As an example, to alter the ``loader-functions`` which manage the specific start and stop process commands
for SystemLoaders you can to the ``linuxScriptReplacements`` map:

.. code-block:: scala
import com.typesafe.sbt.packager.archetypes.TemplateWriter
linuxScriptReplacements += {
val functions = sourceDirectory.value / "templates" / "custom-loader-functions"
// Nil == replacements. If you want to replace stuff in your script put them in this Seq[(String,String)]
"loader-functions" -> TemplateWriter.generateScript(functions.toURL, Nil)
}
which will add the following resource file to use start/stop instead of initctl in the post install script:

.. code-block:: bash
startService() {
app_name=$1
start $app_name
}
stopService() {
app_name=$1
stop $app_name
}
The :doc:`debian </formats/debian>` and :doc:`redhat </formats/rpm>` pages have further information on overriding
distribution specific actions.

Override Start Script
~~~~~~~~~~~~~~~~~~~~~

It's also possible to override the entire script/configuration for your service manager.
Create a file ``src/templates/systemloader/$loader`` and it will be used instead.

Possible values:

* ``$loader`` - ``upstart``, ``systemv`` or ``systemd``

**Syntax**

You can use ``${{variable_name}}`` to reference variables when writing your script. The default set of variables is:

* ``descr`` - The description of the server.
* ``author`` - The configured author name.
* ``exec`` - The script/binary to execute when starting the server
* ``chdir`` - The working directory for the server.
* ``retries`` - The number of times to retry starting the server.
* ``retryTimeout`` - The amount of time to wait before trying to run the server.
* ``app_name`` - The name of the application (linux friendly)
* ``app_main_class`` - The main class / entry point of the application.
* ``app_classpath`` - The (ordered) classpath of the application.
* ``daemon_user`` - The user that the server should run as.
* ``daemon_log_file`` - Absolute path to daemon log file.

0 comments on commit 1d34fad

Please sign in to comment.