Skip to content

Commit

Permalink
Deploying to gh-pages - 22:09:33
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-dmytruk committed Aug 28, 2024
1 parent 5c440f0 commit 82a73c9
Showing 1 changed file with 204 additions and 1 deletion.
205 changes: 204 additions & 1 deletion snapshot/guide/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
&lt;key&gt;Label&lt;/key&gt;
&lt;string&gt;com.example.poja&lt;/string&gt;

&lt;key&gt;Enabled&lt;/key&gt;
&lt;false/&gt;

&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
&lt;string&gt;[executable]&lt;/string&gt;
&lt;string&gt;-Dpoja.apache.useInheritedChannel=false&lt;/string&gt;
&lt;/array&gt;

&lt;key&gt;Sockets&lt;/key&gt;
&lt;dict&gt;
&lt;key&gt;Listeners&lt;/key&gt;
&lt;dict&gt;
&lt;key&gt;SockServiceName&lt;/key&gt;
&lt;string&gt;8080&lt;/string&gt;
&lt;key&gt;SockType&lt;/key&gt;
&lt;string&gt;stream&lt;/string&gt;
&lt;key&gt;SockProtocol&lt;/key&gt;
&lt;string&gt;TCP&lt;/string&gt;
&lt;/dict&gt;
&lt;/dict&gt;

&lt;key&gt;StandardErrorPath&lt;/key&gt;
&lt;string&gt;/tmp/com.example.poja.log&lt;/string&gt;

&lt;key&gt;inetdCompatibility&lt;/key&gt;
&lt;dict&gt;
&lt;key&gt;Wait&lt;/key&gt;
&lt;false/&gt;
&lt;/dict&gt;

&lt;key&gt;KeepAlive&lt;/key&gt;
&lt;false/&gt;
&lt;/dict&gt;
&lt;/plist&gt;</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>

Expand Down

0 comments on commit 82a73c9

Please sign in to comment.