-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c440f0
commit 82a73c9
Showing
1 changed file
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1465,7 +1465,7 @@ <h1 id="httpPoja"><a class="anchor" href="#httpPoja"></a>9 HTTP POJA Application | |
Currently HTTP POJA is based on <a href="https://hc.apache.org/httpcomponents-core-5.2.x/">Apache HTTP Core library</a>.</p> | ||
</div> | ||
<div class="paragraph"> | ||
<p>This feature allows creating simple applications that launch and respond on demand with minimal overhead. The module is suitable for usage with <code>systemd</code> on Linux or <code>launchd</code> on MacOS.</p> | ||
<p>This feature allows creating simple applications that launch and respond on demand with minimal overhead. The module is suitable for usage with <code>systemd</code> on Linux or <code>launchd</code> on MacOS. Examples are given below.</p> | ||
</div> | ||
<div class="paragraph"> | ||
<p>To use the HTTP POJA feature add the following dependencies:</p> | ||
|
@@ -1542,6 +1542,209 @@ <h1 id="httpPoja"><a class="anchor" href="#httpPoja"></a>9 HTTP POJA Application | |
</tr> | ||
</tbody> | ||
</table> | ||
<div class="sect2"> | ||
<h3 id="_use_http_poja_with_launchd_on_macos">Use HTTP POJA with launchd on MacOS</h3> | ||
<div class="paragraph"> | ||
<p>If you have built a HTTP POJA application as a native image executable, create the following <code>plist</code> file and | ||
replace <code>[executable]</code> with your executable path.</p> | ||
</div> | ||
<div class="admonitionblock note"> | ||
<table> | ||
<tr> | ||
<td class="icon"> | ||
<i class="fa icon-note" title="Note"></i> | ||
</td> | ||
<td class="content"> | ||
If you are unfamiliar with building native image executables refer to <a href="https://guides.micronaut.io/latest/micronaut-creating-first-graal-app">Micronaut Creating First Graal App</a> guide. | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
<div class="admonitionblock note"> | ||
<table> | ||
<tr> | ||
<td class="icon"> | ||
<i class="fa icon-note" title="Note"></i> | ||
</td> | ||
<td class="content"> | ||
If you do not wish to use native image prepend <code>java</code> and <code>-jar</code> program arguments and use the jar instead. | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="title">~/Library/LaunchAgents/com.example.poja.plist</div> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Label</key> | ||
<string>com.example.poja</string> | ||
|
||
<key>Enabled</key> | ||
<false/> | ||
|
||
<key>ProgramArguments</key> | ||
<array> | ||
<string>[executable]</string> | ||
<string>-Dpoja.apache.useInheritedChannel=false</string> | ||
</array> | ||
|
||
<key>Sockets</key> | ||
<dict> | ||
<key>Listeners</key> | ||
<dict> | ||
<key>SockServiceName</key> | ||
<string>8080</string> | ||
<key>SockType</key> | ||
<string>stream</string> | ||
<key>SockProtocol</key> | ||
<string>TCP</string> | ||
</dict> | ||
</dict> | ||
|
||
<key>StandardErrorPath</key> | ||
<string>/tmp/com.example.poja.log</string> | ||
|
||
<key>inetdCompatibility</key> | ||
<dict> | ||
<key>Wait</key> | ||
<false/> | ||
</dict> | ||
|
||
<key>KeepAlive</key> | ||
<false/> | ||
</dict> | ||
</plist></code></pre> | ||
</div> | ||
</div> | ||
<div class="paragraph"> | ||
<p>Load the <code>plist</code> file with launchd:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">launchctl load ~/Library/LaunchAgents/com.example.poja.plist</code></pre> | ||
</div> | ||
</div> | ||
<div class="paragraph"> | ||
<p>Then the configured application will respond on port <code>8080</code>:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">curl localhost:8080</code></pre> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="sect2"> | ||
<h3 id="_use_http_poja_with_systemd_on_linux">Use HTTP POJA with systemd on Linux</h3> | ||
<div class="paragraph"> | ||
<p>If you have built a HTTP POJA application as a native image executable, create the following files and | ||
replace <code>[executable]</code> with your executable path.</p> | ||
</div> | ||
<div class="admonitionblock note"> | ||
<table> | ||
<tr> | ||
<td class="icon"> | ||
<i class="fa icon-note" title="Note"></i> | ||
</td> | ||
<td class="content"> | ||
If you are unfamiliar with building native image executables refer to <a href="https://guides.micronaut.io/latest/micronaut-creating-first-graal-app">Micronaut Creating First Graal App</a> guide. | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
<div class="admonitionblock note"> | ||
<table> | ||
<tr> | ||
<td class="icon"> | ||
<i class="fa icon-note" title="Note"></i> | ||
</td> | ||
<td class="content"> | ||
If you do not wish to use native image prepend <code>java</code> and <code>-jar</code> program arguments and use the jar instead. | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="title">/etc/systemd/system/examplepoja.socket</div> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-toml hljs" data-lang="toml">[Unit] | ||
Description=Socket to launch poja example on incoming connection | ||
|
||
[Socket] | ||
ListenStream=127.0.0.1:8080 | ||
Accept=yes | ||
|
||
[Install] | ||
WantedBy=sockets.target</code></pre> | ||
</div> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="title">/etc/systemd/system/[email protected]</div> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-toml hljs" data-lang="toml">[Unit] | ||
Description=Example Poja Service | ||
Requires=examplepoja.socket | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=[executable] -Dpoja.apache.useInheritedChannel=false | ||
ExecStop=/bin/kill $MAINPID | ||
KillMode=process | ||
StandardInput=socket | ||
StandardOutput=socket | ||
StandardError=journal | ||
|
||
[Install] | ||
WantedBy=multi-user.target</code></pre> | ||
</div> | ||
</div> | ||
<div class="paragraph"> | ||
<p>Change selinux policy to allow systemd to use executable in the desired location with:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">chcon -R -t bin_t [executable parent directory]</code></pre> | ||
</div> | ||
</div> | ||
<div class="paragraph"> | ||
<p>Enable and start listening on the socket with systemctl:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">sudo systemctl enable examplepoja.socket | ||
sudo systemctl start examplepoja.socket</code></pre> | ||
</div> | ||
</div> | ||
<div class="paragraph"> | ||
<p>Then the configured application will respond on port <code>8080</code>:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">curl localhost:8080</code></pre> | ||
</div> | ||
</div> | ||
<div class="sect3"> | ||
<h4 id="_use_http_poja_with_systemd_socket_activate_on_linux">Use HTTP POJA with <code>systemd-socket-activate</code> on Linux</h4> | ||
<div class="paragraph"> | ||
<p>To test your application with <code>systemd-socket-activate</code> run:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">systemd-socket-activate --inetd -a -l /tmp/http-poja.sock [executable]</code></pre> | ||
</div> | ||
</div> | ||
<div class="paragraph"> | ||
<p>In a separate terminal send a request to the socket:</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">curl --unix-socket /tmp/http-poja.sock http://localhost/</code></pre> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h1 id="knownIssues"><a class="anchor" href="#knownIssues"></a>10 Known Issues</h1> | ||
|
||
|