-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow script templates to be overridden #121
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ still leveraging the default configuration for other platforms. | |
|
||
Curently, in the nativepackager these archetypes are available: | ||
|
||
* Java Command Line Application (Experimental) | ||
* Java Command Line Application | ||
* Java Server Application (Experimental - Debian Only) | ||
|
||
|
||
Java Command Line Application | ||
|
@@ -24,6 +25,7 @@ A Java Command Line application is a Java application that consists of a set of | |
custom start scripts, or services. It is just a bash/bat script that starts up a Java project. To use | ||
this archetype in your build, do the following in your ``build.sbt``: | ||
|
||
.. code-block:: scala | ||
|
||
packageArchetype.java_application | ||
|
||
|
@@ -47,6 +49,7 @@ this archetype in your build, do the following in your ``build.sbt``: | |
This archetype will use the ``mainClass`` setting of sbt (automatically discovers your main class) to generate ``bat`` and ``bin`` scripts for your project. It | ||
produces a universal layout that looks like the following: | ||
|
||
.. code-block:: none | ||
|
||
bin/ | ||
<app_name> <- BASH script | ||
|
@@ -56,3 +59,119 @@ produces a universal layout that looks like the following: | |
|
||
|
||
You can add additional files to the project by placing things in ``src/windows``, ``src/universal`` or ``src/linux`` as needed. | ||
|
||
|
||
Java Server | ||
----------- | ||
|
||
This archetype is designed for Java applications that are intended to run as | ||
servers or services. This archetype includes wiring such that the application | ||
is started immediately upon startup. | ||
|
||
Currently supported operating systems: | ||
|
||
* Ubuntu 12.04 LTS - Upstart | ||
* Ubuntu 12.04 LTS - init.d | ||
|
||
|
||
The Java Server archetype has a similar installation layout as the java | ||
application. The primary differneces are: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
|
||
* Linux | ||
|
||
* ``/var/log/<pkg>`` is symlinked from ``<install>/log`` | ||
|
||
* Creates a start script in ``/etc/init.d`` or ``/etc/init/`` | ||
|
||
* Creates a startup config file in ``/etc/default/<pkg>`` | ||
|
||
|
||
For Debian servers, you can select to either use SystemV or Upstart for your servers. By default, Upstart (the current Ubuntu LTS default), is used. To switch to SystemV, add the following: | ||
|
||
.. code-block:: scala | ||
|
||
import NativePackagerKeys._ | ||
import com.typesafe.sbt.packager.archetypes.ServerLoader | ||
|
||
serverLoading in Debian := ServerLoader.SystemV | ||
|
||
By default, the native packager will install and run services using the ``root`` user and group. This is not a good default for services, which should not be exposed to root access. You can change the installation and usage user via the ``daemonUser`` key: | ||
|
||
.. code-block:: scala | ||
|
||
daemonUser in Debian := "my_app_user" | ||
|
||
The archetype will automatically append/prepend the creation/deletion of the user | ||
to your packaging for Debian. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should point out here that on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend to write something about #98 (Java_Opts) and #120 (Better upstart script) for handling running instances in Debian.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
Overriding Templates | ||
-------------------- | ||
|
||
You can override the default template used to generate any of the scripts in | ||
any archetype. Listed below are the overridable files and variables that | ||
you can use when generating scripts. | ||
|
||
``src/templates/bat-template`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Creating a file here will override the default template used to | ||
generate the ``.bat`` script for windows distributions. | ||
|
||
**Syntax** | ||
|
||
``@@APP_ENV_NAME@@`` - will be replaced with the script friendly name of your package. | ||
|
||
``@@APP_NAME@@`` - will be replaced with user friendly name of your package. | ||
|
||
``@APP_DEIFNES@@`` - will be replaced with a set of variable definitions, like | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not |
||
``APP_MAIN_CLASS``, ``APP_MAIN_CLASS``. | ||
|
||
You can define addiitonal variable deifnitions using ``batScriptExtraDefines``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deifnitions => definitions |
||
|
||
``src/templates/bash-template`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Creating a file here will override the default template used to | ||
generate the BASH start script found in ``bin/<application>`` in the | ||
universal distribution | ||
|
||
**Syntax** | ||
|
||
``${{template_declares}}`` - Will be replaced with a series of ``declare <var>`` | ||
lines based on the ``bashScriptDefines`` key. You can add more defines to | ||
the ``bashScriptExtraDefines`` that will be used in addition to the default set: | ||
|
||
* ``app_mainclass`` - The main class entry point for the application. | ||
* ``app_classpath`` - The complete classpath for the application (in order). | ||
|
||
|
||
|
||
``src/templates/start`` | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Creating a file here will override either the init.d startup script or | ||
the upstart start script. It will either be located at | ||
``/etc/init/<application>`` or ``/etc/init.d/<application>`` depending on which | ||
serverLoader is being used. | ||
|
||
**Syntax** | ||
|
||
You can use ``${{variable_name}}`` to reference variables when writing your scirpt. 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. | ||
|
||
``src/templates/etc-default`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Creating a file here will override the ``/etc/default/<application>`` template | ||
used when SystemV is the server loader. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feature is too cool to be used only with systemV, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you figure out how to wire it up to upstart, we can merge it :). I was mostly documenting the state of thing as they are. I agree it's a very very nice feature for servers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I need to check the SystemV support. Could be we just use the config feature in the batch file directly and throw that in /etc/default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so it looks like the two systems are actually using two different mechanisms of starting. Right now the SystemV script is a complete script rather than just a wrapper to the BASH script we generate, like upstart. Because of this, currently, they can't share the same /etc/default file. If someone who uses SystemV could detangle that, we can make the default location for config unfortunately, things like USER= wouldn't work for SystemV. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if both startup system have to work with the same So in the end your config file looks different for different start systems, which I think is fine. Still the SystemV script has a lot of hardcoded stuff Upstart# if configuration files exist, prepend their contents to $@
# so it can be processed by this runner
[[ -f "$script_conf_file" ]] && set -- $(loadConfigFile "$script_conf_file") "$@" Doesn't rely on environment variables. SystemVtest -e /etc/default/${{app_name}} && source /etc/default/${{app_name}} Relies on environment variables and isn't able to set Java_Opts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
loader: ServerLoader
as the/etc/default/<name>
should be generated withUpstart
andSystemV
. The we can close #98 as this fixes everything! Just placeetc-default
in thesrc/templates
folder. And I would add thedebianScriptReplacements
as gives us the ability to generate for examplepids
based on the applications name, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mention below, not quite ready for this. We need to unify the two scripts a bit more before I'm comfortable doing so. The config formats are slightly different (ENV variables vs. command line arguments), and the location would be the same...