1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nomad_ynh.git synced 2024-09-03 19:55:53 +02:00

Merge pull request #1 from YunoHost-Apps/testing

First implementation
This commit is contained in:
yalh76 2022-07-23 21:59:28 +02:00 committed by GitHub
commit a97d8ed78c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 1912 additions and 983 deletions

View file

@ -9,9 +9,6 @@
# Since each app is different, maintainers can adapt its contents so as to perform
# automatic actions when a new upstream release is detected.
# Remove this exit command when you are ready to run this Action
exit 1
#=================================================
# FETCHING LATEST RELEASE AND ITS ASSETS
#=================================================
@ -21,7 +18,6 @@ current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions)
version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1)
assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'"))
# Later down the script, we assume the version has only digits and dots
# Sometimes the release name starts with a "v", so let's filter it out.
@ -48,75 +44,6 @@ elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.
exit 0
fi
# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.)
echo "${#assets[@]} available asset(s)"
#=================================================
# UPDATE SOURCE FILES
#=================================================
# Here we use the $assets variable to get the resources published in the upstream release.
# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like.
# Let's loop over the array of assets URLs
for asset_url in ${assets[@]}; do
echo "Handling asset at $asset_url"
# Assign the asset to a source file in conf/ directory
# Here we base the source file name upon a unique keyword in the assets url (admin vs. update)
# Leave $src empty to ignore the asset
case $asset_url in
*"admin"*)
src="app"
;;
*"update"*)
src="app-upgrade"
;;
*)
src=""
;;
esac
# If $src is not empty, let's process the asset
if [ ! -z "$src" ]; then
# Create the temporary directory
tempdir="$(mktemp -d)"
# Download sources and calculate checksum
filename=${asset_url##*/}
curl --silent -4 -L $asset_url -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
# Delete temporary directory
rm -rf $tempdir
# Get extension
if [[ $filename == *.tar.gz ]]; then
extension=tar.gz
else
extension=${filename##*.}
fi
# Rewrite source file
cat <<EOT > conf/$src.src
SOURCE_URL=$asset_url
SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=$extension
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true
EOT
echo "... conf/$src.src updated"
else
echo "... asset ignored"
fi
done
#=================================================
# SPECIFIC UPDATE STEPS
#=================================================

49
.github/workflows/updater.yml vendored Normal file
View file

@ -0,0 +1,49 @@
# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected.
# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization.
# This file should be enough by itself, but feel free to tune it to your needs.
# It calls updater.sh, which is where you should put the app-specific update steps.
name: Check for new upstream releases
on:
# Allow to manually trigger the workflow
workflow_dispatch:
# Run it every day at 6:00 UTC
schedule:
- cron: '0 6 * * *'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
id: run_updater
run: |
# Setting up Git user
git config --global user.name 'yunohost-bot'
git config --global user.email 'yunohost-bot@users.noreply.github.com'
# Run the updater script
/bin/bash .github/workflows/updater.sh
- name: Commit changes
id: commit
if: ${{ env.PROCEED == 'true' }}
run: |
git commit -am "Upgrade to v$VERSION"
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update to version ${{ env.VERSION }}
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
signoff: false
base: testing
branch: ci-auto-update-v${{ env.VERSION }}
delete-branch: true
title: 'Upgrade to version ${{ env.VERSION }}'
body: |
Upgrade to v${{ env.VERSION }}
draft: false

365
LICENSE
View file

@ -1,4 +1,363 @@
File containing the license of your package.
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.
More information here:
https://yunohost.org/packaging_apps_guidelines#yep-1-3

206
README.md
View file

@ -15,46 +15,196 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
## Overview
Some long and extensive description of what the app is and does, lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
### Features
- Ut enim ad minim veniam, quis nostrud exercitation ullamco ;
- Laboris nisi ut aliquip ex ea commodo consequat ;
- Duis aute irure dolor in reprehenderit in voluptate ;
- Velit esse cillum dolore eu fugiat nulla pariatur ;
- Excepteur sint occaecat cupidatat non proident, sunt in culpa."
Nomad is a simple and flexible workload orchestrator to deploy and manage containers ([docker](https://www.nomadproject.io/docs/drivers/docker.html), [podman](https://www.nomadproject.io/docs/drivers/podman)), non-containerized applications ([executable](https://www.nomadproject.io/docs/drivers/exec.html), [Java](https://www.nomadproject.io/docs/drivers/java)), and virtual machines ([qemu](https://www.nomadproject.io/docs/drivers/qemu.html)) across on-prem and clouds at scale.
**Shipped version:** 1.0~ynh1
**Demo:** https://demo.example.com
**Shipped version:** 1.3.2~ynh1
## Screenshots
![Screenshot of Nomad](./doc/screenshots/example.jpg)
![Screenshot of Nomad](./doc/screenshots/assets.png)
## Disclaimers / important information
* Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?
* not-working single-sign on or LDAP integration ?
* the app requires an important amount of RAM / disk / .. to install or to work properly
* etc...
## Some Nomad Job examples
* Other infos that people should be aware of, such as:
* any specific step to perform after installing (such as manually finishing the install, specific admin credentials, ...)
* how to configure / administrate the application if it ain't obvious
* upgrade process / specificities / things to be aware of ?
* security considerations ?
### Busybox
`lxc-create --name=busybox --template=busybox`
```
job "job-busybox" {
datacenters = ["dc1"]
type = "service"
group "group-busybox" {
task "task-busybox" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-busybox"
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian
`lxc-create --name=debian --template=debian`
```
job "job-debian" {
datacenters = ["dc1"]
type = "service"
group "group-debian" {
task "task-debian" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Stretch
`lxc-create --name=stretch --template=debian -- --release=stretch`
```
job "job-stretch" {
datacenters = ["dc1"]
type = "service"
group "group-stretch" {
task "task-stretch" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
template_args = ["--release=stretch"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Buster
`lxc-create --name=buster --template=debian -- --release=buster`
```
job "job-buster" {
datacenters = ["dc1"]
type = "service"
group "group-buster" {
task "task-buster" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
template_args = ["--release=buster"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Buster from images.linuxcontainers.org
`lxc-create --name=download-buster --template=download -- --dist=debian --release=buster --arch=amd64 --keyserver=hkp://keyserver.ubuntu.com`
```
job "job-download-buster" {
datacenters = ["dc1"]
type = "service"
group "group-download-buster" {
task "task-download-buster" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-download"
template_args = ["--dist=debian","--release=buster","--arch=amd64","--keyserver=hkp://keyserver.ubuntu.com"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Bullseye from images.linuxcontainers.org
`lxc-create --name=download-bullseye --template=download -- --dist=debian --release=bullseye --arch=amd64 --keyserver=hkp://keyserver.ubuntu.com`
```
job "job-download-bullseye" {
datacenters = ["dc1"]
type = "service"
group "group-download-bullseye" {
task "task-download-bullseye" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-download"
template_args = ["--dist=debian","--release=bullseye","--arch=amd64","--keyserver=hkp://keyserver.ubuntu.com"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
## Documentation and resources
* Official app website: <https://example.com>
* Official user documentation: <https://yunohost.org/apps>
* Official admin documentation: <https://yunohost.org/packaging_apps>
* Upstream app code repository: <https://some.forge.com/example/example>
* Official app website: <https://www.nomadproject.io/>
* Official admin documentation: <https://www.nomadproject.io/docs>
* Upstream app code repository: <https://github.com/hashicorp/nomad>
* YunoHost documentation for this app: <https://yunohost.org/app_nomad>
* Report a bug: <https://github.com/YunoHost-Apps/nomad_ynh/issues>

View file

@ -15,46 +15,196 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
## Vue d'ensemble
Some long and extensive description of what the app is and does, lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
### Features
- Ut enim ad minim veniam, quis nostrud exercitation ullamco ;
- Laboris nisi ut aliquip ex ea commodo consequat ;
- Duis aute irure dolor in reprehenderit in voluptate ;
- Velit esse cillum dolore eu fugiat nulla pariatur ;
- Excepteur sint occaecat cupidatat non proident, sunt in culpa."
Nomad is a simple and flexible workload orchestrator to deploy and manage containers ([docker](https://www.nomadproject.io/docs/drivers/docker.html), [podman](https://www.nomadproject.io/docs/drivers/podman)), non-containerized applications ([executable](https://www.nomadproject.io/docs/drivers/exec.html), [Java](https://www.nomadproject.io/docs/drivers/java)), and virtual machines ([qemu](https://www.nomadproject.io/docs/drivers/qemu.html)) across on-prem and clouds at scale.
**Version incluse :** 1.0~ynh1
**Démo :** https://demo.example.com
**Version incluse :** 1.3.2~ynh1
## Captures d'écran
![Capture d'écran de Nomad](./doc/screenshots/example.jpg)
![Capture d'écran de Nomad](./doc/screenshots/assets.png)
## Avertissements / informations importantes
* Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?
* not-working single-sign on or LDAP integration ?
* the app requires an important amount of RAM / disk / .. to install or to work properly
* etc...
## Some Nomad Job examples
* Other infos that people should be aware of, such as:
* any specific step to perform after installing (such as manually finishing the install, specific admin credentials, ...)
* how to configure / administrate the application if it ain't obvious
* upgrade process / specificities / things to be aware of ?
* security considerations ?
### Busybox
`lxc-create --name=busybox --template=busybox`
```
job "job-busybox" {
datacenters = ["dc1"]
type = "service"
group "group-busybox" {
task "task-busybox" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-busybox"
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian
`lxc-create --name=debian --template=debian`
```
job "job-debian" {
datacenters = ["dc1"]
type = "service"
group "group-debian" {
task "task-debian" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Stretch
`lxc-create --name=stretch --template=debian -- --release=stretch`
```
job "job-stretch" {
datacenters = ["dc1"]
type = "service"
group "group-stretch" {
task "task-stretch" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
template_args = ["--release=stretch"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Buster
`lxc-create --name=buster --template=debian -- --release=buster`
```
job "job-buster" {
datacenters = ["dc1"]
type = "service"
group "group-buster" {
task "task-buster" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
template_args = ["--release=buster"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Buster from images.linuxcontainers.org
`lxc-create --name=download-buster --template=download -- --dist=debian --release=buster --arch=amd64 --keyserver=hkp://keyserver.ubuntu.com`
```
job "job-download-buster" {
datacenters = ["dc1"]
type = "service"
group "group-download-buster" {
task "task-download-buster" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-download"
template_args = ["--dist=debian","--release=buster","--arch=amd64","--keyserver=hkp://keyserver.ubuntu.com"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Bullseye from images.linuxcontainers.org
`lxc-create --name=download-bullseye --template=download -- --dist=debian --release=bullseye --arch=amd64 --keyserver=hkp://keyserver.ubuntu.com`
```
job "job-download-bullseye" {
datacenters = ["dc1"]
type = "service"
group "group-download-bullseye" {
task "task-download-bullseye" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-download"
template_args = ["--dist=debian","--release=bullseye","--arch=amd64","--keyserver=hkp://keyserver.ubuntu.com"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
## Documentations et ressources
* Site officiel de l'app : <https://example.com>
* Documentation officielle utilisateur : <https://yunohost.org/apps>
* Documentation officielle de l'admin : <https://yunohost.org/packaging_apps>
* Dépôt de code officiel de l'app : <https://some.forge.com/example/example>
* Site officiel de l'app : <https://www.nomadproject.io/>
* Documentation officielle de l'admin : <https://www.nomadproject.io/docs>
* Dépôt de code officiel de l'app : <https://github.com/hashicorp/nomad>
* Documentation YunoHost pour cette app : <https://yunohost.org/app_nomad>
* Signaler un bug : <https://github.com/YunoHost-Apps/nomad_ynh/issues>

View file

@ -1,29 +1,47 @@
;; Test complet
;; Test complet client
; Manifest
domain="domain.tld"
path="/path"
is_public=1
language="fr"
admin="john"
password="1Strong-Password"
port="666"
node_type="client"
bootstrap_expect="1"
retry_join="192.168.1.100"
server_ip="192.168.1.100"
driver_lxc=1
; Checks
pkg_linter=1
setup_sub_dir=1
setup_sub_dir=0
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=CommitHash
#upgrade=1 from_commit=CommitHash
backup_restore=1
multi_instance=1
multi_instance=0
port_already_use=0
change_url=1
;; Test complet server
; Manifest
domain="domain.tld"
is_public=1
node_type="server"
bootstrap_expect="1"
retry_join="192.168.1.100"
server_ip="none..."
driver_lxc=1
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
#upgrade=1 from_commit=CommitHash
backup_restore=1
multi_instance=0
port_already_use=0
change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=CommitHash
name=Name and date of the commit.
manifest_arg=domain=DOMAIN&path=PATH&is_public=1&language=fr&admin=USER&password=pass&port=666&

View file

@ -1,7 +0,0 @@
SOURCE_URL=url of app's source
SOURCE_SUM=sha256 checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

41
conf/client.hcl Normal file
View file

@ -0,0 +1,41 @@
#----------------------- client-specific options ---------------------
client {
# A boolean indicating if client mode is enabled. All other client configuration options depend on this value.
# Defaults to false.
enabled = true
# This is the state dir used to store client state. By default, it lives inside of the data_dir, in the
# "client" sub-path.
# state_dir = "/tmp/client"
# A directory used to store allocation data. Depending on the workload, the size of this directory can grow
# arbitrarily large as it is used to store downloaded artifacts for drivers (QEMU images, JAR files, etc.). It is therefore
# important to ensure this directory is placed some place on the filesystem with adequate storage capacity. By default, this
# directory lives under the data_dir at the "alloc" sub-path.
# alloc_dir = "/tmp/alloc"
# An array of server addresses. This list is used to register the client with the server nodes and advertise
# the available resources so that the agent can receive work.
servers = ["__SERVER_IP__:__RPC_PORT__"]
# This is the value used to uniquely identify the local agent's node registration with the servers. This can be any arbitrary
# string but must be unique to the cluster. By default, if not specified, a randomly- generate UUID will be used.
# node_id = "foo"
# A string used to logically group client nodes by class. This can be used during job placement as a filter.
# This option is not required and has no default.
# node_class = "experimentation"
# This is a key/value mapping of metadata pairs. This is a free-form map and can contain any string values.
meta {}
# This is a key/value mapping of internal configuration for clients, such as for driver configuration.
options {}
# This is a string to force network fingerprinting to use a specific network interface
# network_interface = "eth0"
# This is an int that sets the default link speed of network interfaces, in megabits, if their speed can not be
# determined dynamically.
network_speed = 100
}

6
conf/default.conf Normal file
View file

@ -0,0 +1,6 @@
lxc.net.0.type = veth
lxc.net.0.link = __CLIENT_LXC_BRIDGE__
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
lxc.apparmor.profile = generated
lxc.apparmor.allow_nesting = 1

2
conf/dnsmasq-lxd Normal file
View file

@ -0,0 +1,2 @@
bind-interfaces
except-interface=__CLIENT_LXC_BRIDGE__

7
conf/driver-lxc.hcl Normal file
View file

@ -0,0 +1,7 @@
plugin "nomad-driver-lxc" {
config {
enabled = true
volumes_enabled = true
lxc_path = "/var/lib/lxc"
}
}

7
conf/driver-lxc.src Normal file
View file

@ -0,0 +1,7 @@
SOURCE_URL=https://github.com/hashicorp/nomad-driver-lxc/archive/68239f4f639bde68e80616b7e931b8cc368969b0.tar.gz
SOURCE_SUM=50ddae947a189fefe0f6a5419d8f5ae749daa124f100b3ce900d83eab073c2ad
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

9
conf/lxc-net Normal file
View file

@ -0,0 +1,9 @@
USE_LXC_BRIDGE="true"
LXC_BRIDGE="__CLIENT_LXC_BRIDGE__"
LXC_ADDR="__CLIENT_LXC_PLAGE_IP__.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="__CLIENT_LXC_PLAGE_IP__.0/24"
LXC_DHCP_RANGE="__CLIENT_LXC_PLAGE_IP__.2,__CLIENT_LXC_PLAGE_IP__.254"
LXC_DHCP_MAX="253"
LXC_DHCP_CONFILE=""
LXC_DOMAIN=""

View file

@ -1,25 +1,29 @@
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
# Path to source
alias __FINALPATH__/;
proxy_pass http://127.0.0.1:__HTTP_PORT__;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.php;
# Nomad blocking queries will remain open for a default of 5 minutes.
# Increase the proxy timeout to accommodate this timeout with an
# additional grace period.
proxy_read_timeout 310s;
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
#client_max_body_size 50M;
# Nomad log streaming uses streaming HTTP requests. In order to
# synchronously stream logs from Nomad to NGINX to the browser
# proxy buffering needs to be turned off.
proxy_buffering off;
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
# The Upgrade and Connection headers are used to establish
# a WebSockets connection.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# The default Origin header will be the proxy address, which
# will be rejected by Nomad. It must be rewritten to be the
# host address instead.
proxy_set_header Origin "${scheme}://${proxy_host}";
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;

118
conf/nomad.hcl Normal file
View file

@ -0,0 +1,118 @@
# -------------- General options ---------------
# Specifies the region the Nomad agent is a member of. A region typically maps to a
# geographic region, for example USA, with potentially multiple zones, which map to
# datacenters such as us-west and us-east. Defaults to global.
#region = "USA"
# Datacenter of the local agent. All members of a datacenter should share a local
# LAN connection. Defaults to dc1.
#datacenter = "data-center-one"
# The name of the local node. This value is used to identify individual nodes in a
# given datacenter and must be unique per-datacenter. By default this is set to the
# local host's name.
#name = "client-one"
# A local directory used to store agent state. Client nodes use this directory by
# default to store temporary allocation data as well as cluster information. Server
# nodes use this directory to store cluster state, including the replicated log and
# snapshot data. This option is required to start the Nomad agent.
data_dir = "__DATADIR__"
# Controls the verbosity of logs the Nomad agent will output. Valid log levels include
# WARN, INFO, or DEBUG in increasing order of verbosity. Defaults to INFO.
#log_level = "DEBUG"
# Used to indicate which address the Nomad agent should bind to for network services,
# including the HTTP interface as well as the internal gossip protocol and RPC mechanism.
# This should be specified in IP format, and can be used to easily bind all network services
# to the same address. It is also possible to bind the individual services to different
# addresses using the addresses configuration option. Defaults to the local loopback
# address 127.0.0.1.
bind_addr = "0.0.0.0"
# Enables the debugging HTTP endpoints. These endpoints can be used with profiling tools
# to dump diagnostic information about Nomad's internals. It is not recommended to leave
# this enabled in production environments. Defaults to false.
enable_debug = false
# Controls the network ports used for different services required by the Nomad agent.
ports {
# The port used to run the HTTP server. Applies to both client and server nodes. Defaults to __HTTP_PORT__.
http = __HTTP_PORT__
# The port used for internal RPC communication between agents and servers, and for inter-server
# traffic for the consensus algorithm (raft). Defaults to __RPC_PORT__. Only used on server nodes.
rpc = __RPC_PORT__
# The port used for the gossip protocol for cluster membership. Both TCP and UDP should be routable
# between the server nodes on this port. Defaults to __SERF_PORT__. Only used on server nodes.
serf = __SERF_PORT__
}
# Controls the bind address for individual network services. Any values configured in this block
# take precedence over the default bind_addr.
addresses {
# The address the HTTP server is bound to. This is the most common bind address to change.
# Applies to both clients and servers.
# http = "0.0.0.0"
# The address to bind the internal RPC interfaces to. Should be exposed only to other cluster
# members if possible. Used only on server nodes, but must be accessible from all agents.
# rpc = "0.0.0.0"
# The address used to bind the gossip layer to. Both a TCP and UDP listener will be exposed on this
# address. Should be restricted to only server nodes from the same datacenter if possible.
# Used only on server nodes.
# serf = "0.0.0.0"
}
# Controls the advertise address for individual network services. This can be used to advertise a
# different address to the peers of a server node to support more complex network configurations such
# as NAT. This configuration is optional, and defaults to the bind address of the specific network
# service if it is not provided. This configuration is only applicable on server nodes.
#advertise {
# The address to advertise for the RPC interface. This address should be reachable by all of
# the agents in the cluster.
# rpc = "1.2.3.4:__RPC_PORT__"
# The address advertised for the gossip layer. This address must be reachable from all server nodes.
# It is not required that clients can reach this address.
# serf = "1.2.3.4:__SERF_PORT__"
#}
# Used to control how the Nomad agent exposes telemetry data to external metrics collection servers.
telemetry {
# Address of a statsite server to forward metrics data to.
# statsite_address = "1.2.3.4:5678"
# Address of a statsd server to forward metrics to.
# statsd_address = "1.2.3.4:5678"
# A boolean indicating if gauge values should not be prefixed with the local hostname.
# disable_hostname = false
}
# Enables gracefully leaving when receiving the interrupt signal. By default, the agent will
# exit forcefully on any signal.
leave_on_interrupt = false
# Enables gracefully leaving when receiving the terminate signal. By default, the agent will
# exit forcefully on any signal.
leave_on_terminate = false
# Enables logging to syslog. This option only works on Unix based systems.
enable_syslog = false
# Controls the syslog facility that is used. By default, LOCAL0 will be used. This should
# be used with enable_syslog.
syslog_facility = "LOCAL0"
# Disables automatic checking for security bulletins and new version releases.
disable_update_check = true
# Disables providing an anonymous signature for de-duplication with the update check.
disable_anonymous_signature = false

View file

@ -1,430 +0,0 @@
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[__NAMETOCHANGE__]
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = __USER__
group = __USER__
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php/php__PHPVERSION__-fpm-__NAMETOCHANGE__.sock
; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 511
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
; When set, listen.owner and listen.group are ignored
;listen.acl_users =
;listen.acl_groups =
; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
;listen.allowed_clients = 127.0.0.1
; Specify the nice(2) priority to apply to the pool processes (only if set)
; The value can vary from -19 (highest priority) to 20 (lower priority)
; Note: - It will only work if the FPM master process is launched as root
; - The pool processes will inherit the master process priority
; unless it specified otherwise
; Default Value: no set
; process.priority = -19
; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user
; or group is differrent than the master process user. It allows to create process
; core dump and ptrace the process for the pool user.
; Default Value: no
; process.dumpable = yes
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children.
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 5
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 2
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
;pm.max_requests = 500
; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. It shows the following informations:
; pool - the name of the pool;
; process manager - static, dynamic or ondemand;
; start time - the date and time FPM has started;
; start since - number of seconds since FPM has started;
; accepted conn - the number of request accepted by the pool;
; listen queue - the number of request in the queue of pending
; connections (see backlog in listen(2));
; max listen queue - the maximum number of requests in the queue
; of pending connections since FPM has started;
; listen queue len - the size of the socket queue of pending connections;
; idle processes - the number of idle processes;
; active processes - the number of active processes;
; total processes - the number of idle + active processes;
; max active processes - the maximum number of active processes since FPM
; has started;
; max children reached - number of times, the process limit has been reached,
; when pm tries to start more children (works only for
; pm 'dynamic' and 'ondemand');
; Value are updated in real time.
; Example output:
; pool: www
; process manager: static
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 62636
; accepted conn: 190460
; listen queue: 0
; max listen queue: 1
; listen queue len: 42
; idle processes: 4
; active processes: 11
; total processes: 15
; max active processes: 12
; max children reached: 0
;
; By default the status page output is formatted as text/plain. Passing either
; 'html', 'xml' or 'json' in the query string will return the corresponding
; output syntax. Example:
; http://www.foo.bar/status
; http://www.foo.bar/status?json
; http://www.foo.bar/status?html
; http://www.foo.bar/status?xml
;
; By default the status page only outputs short status. Passing 'full' in the
; query string will also return status for each pool process.
; Example:
; http://www.foo.bar/status?full
; http://www.foo.bar/status?json&full
; http://www.foo.bar/status?html&full
; http://www.foo.bar/status?xml&full
; The Full status returns for each process:
; pid - the PID of the process;
; state - the state of the process (Idle, Running, ...);
; start time - the date and time the process has started;
; start since - the number of seconds since the process has started;
; requests - the number of requests the process has served;
; request duration - the duration in µs of the requests;
; request method - the request method (GET, POST, ...);
; request URI - the request URI with the query string;
; content length - the content length of the request (only with POST);
; user - the user (PHP_AUTH_USER) (or '-' if not set);
; script - the main script called (or '-' if not set);
; last request cpu - the %cpu the last request consumed
; it's always 0 if the process is not in Idle state
; because CPU calculation is done when the request
; processing has terminated;
; last request memory - the max amount of memory the last request consumed
; it's always 0 if the process is not in Idle state
; because memory calculation is done when the request
; processing has terminated;
; If the process is in Idle state, then informations are related to the
; last request the process has served. Otherwise informations are related to
; the current request being served.
; Example output:
; ************************
; pid: 31330
; state: Running
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 63087
; requests: 12808
; request duration: 1250261
; request method: GET
; request URI: /test_mem.php?N=10000
; content length: 0
; user: -
; script: /home/fat/web/docs/php/test_mem.php
; last request cpu: 0.00
; last request memory: 0
;
; Note: There is a real-time FPM status monitoring sample web page available
; It's available in: /usr/share/php/7.0/fpm/status.html
;
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;pm.status_path = /status
; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping
; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong
; The access log file
; Default: not set
;access.log = log/$pool.access.log
; The access log format.
; The following syntax is allowed
; %%: the '%' character
; %C: %CPU used by the request
; it can accept the following format:
; - %{user}C for user CPU only
; - %{system}C for system CPU only
; - %{total}C for user + system CPU (default)
; %d: time taken to serve the request
; it can accept the following format:
; - %{seconds}d (default)
; - %{miliseconds}d
; - %{mili}d
; - %{microseconds}d
; - %{micro}d
; %e: an environment variable (same as $_ENV or $_SERVER)
; it must be associated with embraces to specify the name of the env
; variable. Some exemples:
; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
; %f: script filename
; %l: content-length of the request (for POST request only)
; %m: request method
; %M: peak of memory allocated by PHP
; it can accept the following format:
; - %{bytes}M (default)
; - %{kilobytes}M
; - %{kilo}M
; - %{megabytes}M
; - %{mega}M
; %n: pool name
; %o: output header
; it must be associated with embraces to specify the name of the header:
; - %{Content-Type}o
; - %{X-Powered-By}o
; - %{Transfert-Encoding}o
; - ....
; %p: PID of the child that serviced the request
; %P: PID of the parent of the child that serviced the request
; %q: the query string
; %Q: the '?' character if query string exists
; %r: the request URI (without the query string, see %q and %Q)
; %R: remote IP address
; %s: status (response code)
; %t: server time the request was received
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %T: time the log has been written (the request has finished)
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %u: remote user
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = log/$pool.log.slow
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 1d
; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024
; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
chdir = __FINALPATH__
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
;catch_workers_output = yes
; Clear environment in FPM workers
; Prevents arbitrary environment variables from reaching FPM worker processes
; by clearing the environment in workers before env vars specified in this
; pool configuration are added.
; Setting to "no" will make all environment variables available to PHP code
; via getenv(), $_ENV and $_SERVER.
; Default Value: yes
;clear_env = no
; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; execute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5 .php7
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or /usr)
; Default Value: nothing is defined by default except the values in php.ini and
; specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
; Common values to change to increase file upload limit
; php_admin_value[upload_max_filesize] = 50M
; php_admin_value[post_max_size] = 50M
; php_admin_flag[mail.add_x_header] = Off
; Other common parameters
; php_admin_value[max_execution_time] = 600
; php_admin_value[max_input_time] = 300
; php_admin_value[memory_limit] = 256M
; php_admin_flag[short_open_tag] = On

53
conf/server.hcl Normal file
View file

@ -0,0 +1,53 @@
# ------------- server-specific options -----------------------------
server {
# A boolean indicating if server mode should be enabled for the local agent. All other server
# options depend on this value being set. Defaults to false.
enabled = true
# This is an integer representing the number of server nodes to wait for before bootstrapping. It is most
# common to use the odd-numbered integers 3 or 5 for this value, depending on the cluster size. A value of
# 1 does not provide any fault tolerance and is not recommended for production use cases.
bootstrap_expect = __BOOTSTRAP_EXPECT__
# This is the data directory used for server-specific data, including the replicated log. By default, this
# directory lives inside of the data_dir in the "server" sub-path.
# data_dir = "/tmp/server"
# The Nomad protocol version spoken when communicating with other Nomad servers. This value is typically not
# required as the agent internally knows the latest version, but may be useful in some upgrade scenarios.
# protocol_version = 0
# The number of parallel scheduler threads to run. This can be as many as one per core, or 0 to disallow this
# server from making any scheduling decisions. This defaults to the number of CPU cores.
# num_schedulers = 1
# This is an array of strings indicating which sub-schedulers this server will handle. This can be used to
# restrict the evaluations that worker threads will dequeue for processing. This defaults to all available schedulers.
# enabled_schedulers = "[]"
# This is a string with a unit suffix, such as "300ms", "1.5h" or "25m". Valid time units are "ns",
# "us" (or "µs"), "ms", "s", "m", "h". Controls how long a node must be in a terminal state before it is
# garbage collected and purged from the system.
node_gc_threshold = "6h"
# When provided, Nomad will ignore a previous leave and attempt to rejoin the cluster when starting.
# By default, Nomad treats leave as a permanent intent and does not attempt to join the cluster again when
# starting. This flag allows the previous state to be used to rejoin the cluster.
rejoin_after_leave = true
# Similar to start_join but allows retrying a join if the first attempt fails. This is useful for cases
# where we know the address will become available eventually.
retry_join = ["__RETRY_JOIN__"]
# The time to wait between join attempts. Defaults to 30s.
retry_interval = "30s"
# The maximum number of join attempts to be made before exiting with a return code of 1.
# By default, this is set to 0 which is interpreted as infinite retries.
retry_max = 0
# An array of strings specifying addresses of nodes to join upon startup. If Nomad is unable to join with any
# of the specified addresses, agent startup will fail. By default, the agent won't join any nodes when it starts up.
# start_join = []
}

View file

@ -1,45 +1,14 @@
[Unit]
Description=Small description of the service
Description=__APP__ agent
After=network.target
[Service]
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
ExecStart=__FINALPATH__/script
User=__SYSTEMD_USER__
Group=__SYSTEMD_USER__
ExecStart=/usr/bin/nomad agent -config=__CONFIG_PATH__
StandardOutput=append:/var/log/__APP__/__APP__.log
StandardError=inherit
# Sandboxing options to harden security
# Depending on specificities of your service/app, you may need to tweak these
# .. but this should be a good baseline
# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
DevicePolicy=closed
ProtectSystem=full
ProtectControlGroups=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
LockPersonality=yes
SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap
# Denying access to capabilities that should not be relevant for webapps
# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
[Install]
WantedBy=multi-user.target

View file

@ -1,9 +1 @@
Some long and extensive description of what the app is and does, lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
### Features
- Ut enim ad minim veniam, quis nostrud exercitation ullamco ;
- Laboris nisi ut aliquip ex ea commodo consequat ;
- Duis aute irure dolor in reprehenderit in voluptate ;
- Velit esse cillum dolore eu fugiat nulla pariatur ;
- Excepteur sint occaecat cupidatat non proident, sunt in culpa."
Nomad is a simple and flexible workload orchestrator to deploy and manage containers ([docker](https://www.nomadproject.io/docs/drivers/docker.html), [podman](https://www.nomadproject.io/docs/drivers/podman)), non-containerized applications ([executable](https://www.nomadproject.io/docs/drivers/exec.html), [Java](https://www.nomadproject.io/docs/drivers/java)), and virtual machines ([qemu](https://www.nomadproject.io/docs/drivers/qemu.html)) across on-prem and clouds at scale.

View file

@ -1,12 +1,173 @@
* Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?
* not-working single-sign on or LDAP integration ?
* the app requires an important amount of RAM / disk / .. to install or to work properly
* etc...
## Some Nomad Job examples
* Other infos that people should be aware of, such as:
* any specific step to perform after installing (such as manually finishing the install, specific admin credentials, ...)
* how to configure / administrate the application if it ain't obvious
* upgrade process / specificities / things to be aware of ?
* security considerations ?
### Busybox
`lxc-create --name=busybox --template=busybox`
```
job "job-busybox" {
datacenters = ["dc1"]
type = "service"
group "group-busybox" {
task "task-busybox" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-busybox"
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian
`lxc-create --name=debian --template=debian`
```
job "job-debian" {
datacenters = ["dc1"]
type = "service"
group "group-debian" {
task "task-debian" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Stretch
`lxc-create --name=stretch --template=debian -- --release=stretch`
```
job "job-stretch" {
datacenters = ["dc1"]
type = "service"
group "group-stretch" {
task "task-stretch" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
template_args = ["--release=stretch"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Buster
`lxc-create --name=buster --template=debian -- --release=buster`
```
job "job-buster" {
datacenters = ["dc1"]
type = "service"
group "group-buster" {
task "task-buster" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-debian"
template_args = ["--release=buster"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Buster from images.linuxcontainers.org
`lxc-create --name=download-buster --template=download -- --dist=debian --release=buster --arch=amd64 --keyserver=hkp://keyserver.ubuntu.com`
```
job "job-download-buster" {
datacenters = ["dc1"]
type = "service"
group "group-download-buster" {
task "task-download-buster" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-download"
template_args = ["--dist=debian","--release=buster","--arch=amd64","--keyserver=hkp://keyserver.ubuntu.com"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```
### Debian Bullseye from images.linuxcontainers.org
`lxc-create --name=download-bullseye --template=download -- --dist=debian --release=bullseye --arch=amd64 --keyserver=hkp://keyserver.ubuntu.com`
```
job "job-download-bullseye" {
datacenters = ["dc1"]
type = "service"
group "group-download-bullseye" {
task "task-download-bullseye" {
driver = "lxc"
config {
log_level = "info"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-download"
template_args = ["--dist=debian","--release=bullseye","--arch=amd64","--keyserver=hkp://keyserver.ubuntu.com"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
```

BIN
doc/screenshots/assets.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

View file

@ -5,29 +5,25 @@
"description": {
"en": "Simple and flexible workload orchestrator"
},
"version": "1.0~ynh1",
"url": "https://example.com",
"version": "1.3.2~ynh1",
"url": "https://www.nomadproject.io/",
"upstream": {
"license": "free",
"website": "https://example.com",
"demo": "https://demo.example.com",
"admindoc": "https://yunohost.org/packaging_apps",
"userdoc": "https://yunohost.org/apps",
"code": "https://some.forge.com/example/example"
"license": "MPL-2.0",
"website": "https://www.nomadproject.io/",
"admindoc": "https://www.nomadproject.io/docs",
"code": "https://github.com/hashicorp/nomad"
},
"license": "free",
"license": "MPL-2.0",
"maintainer": {
"name": "John doe",
"email": "john.doe@example.com"
"name": "",
"email": ""
},
"requirements": {
"yunohost": ">= 4.3.0"
},
"multi_instance": true,
"multi_instance": false,
"services": [
"nginx",
"php7.3-fpm",
"mysql"
"nginx"
],
"arguments": {
"install": [
@ -35,37 +31,77 @@
"name": "domain",
"type": "domain"
},
{
"name": "path",
"type": "path",
"example": "/example",
"default": "/example"
},
{
"name": "is_public",
"type": "boolean",
"default": true
},
{
"name": "language",
"name": "node_type",
"type": "string",
"ask": {
"en": "Choose the application language",
"fr": "Choisissez la langue de l'application"
"en": "What kind of Nomad node you want to install ?"
},
"choices": ["fr", "en"],
"default": "fr"
"choices": [
"server",
"client"
],
"default": "server"
},
{
"name": "admin",
"type": "user"
},
{
"name": "password",
"type": "password",
"name": "bootstrap_expect",
"type": "string",
"ask": {
"en": "[Server only] How many server nodes to wait for before bootstrapping ?"
},
"choices": [
"1",
"3",
"5",
"7",
"9"
],
"default": "1",
"help": {
"en": "Use the help field to add an information for the admin about this question.",
"fr": "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question."
"en": "For production, it's recommanded to have 3 to 5 server nodes."
}
},
{
"name": "retry_join",
"type": "string",
"ask": {
"en": "[Server only] What is the IP of another server to join ?"
},
"example": "192.168.1.100",
"optional": true
},
{
"name": "server_ip",
"type": "string",
"ask": {
"en": "[Client only] What is the IP of the Nomad server node ?"
},
"example": "192.168.1.100",
"optional": true
},
{
"name": "server_ip",
"type": "string",
"ask": {
"en": "[Client only] What is the IP of the Nomad server node ?"
},
"example": "192.168.1.100",
"optional": true
},
{
"name": "driver_lxc",
"type": "boolean",
"ask": {
"en": "[Client only] Do you want to install LXC driver ?"
},
"default": true,
"help": {
"en": "It will also install lxc."
}
}
]

View file

@ -5,7 +5,15 @@
#=================================================
# dependencies used by the app
pkg_dependencies="deb1 deb2 php$YNH_DEFAULT_PHP_VERSION-deb1 php$YNH_DEFAULT_PHP_VERSION-deb2"
pkg_dependencies=""
extra_pkg_dependencies="nomad"
server_pkg_dependencies=""
client_pkg_dependencies=""
client_lxc_pkg_dependencies="pkg-config lxc-dev lxc lxc-templates"
go_version=1.15
#=================================================
# PERSONAL HELPERS

View file

@ -27,10 +27,8 @@ ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
@ -38,12 +36,6 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE DATA DIR
#=================================================
@ -56,19 +48,6 @@ ynh_backup --src_path="$datadir" --is_big
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
@ -87,16 +66,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/etc/$app/"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
ynh_backup --src_path="$config_path"
#=================================================
# END OF SCRIPT

View file

@ -27,12 +27,10 @@ app=$YNH_APP_INSTANCE_NAME
ynh_script_progression --message="Loading installation settings..."
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
# Add settings here as needed by your application
#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#db_user=$db_name
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
http_port=$(ynh_app_setting_get --app=$app --key=http_port)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
@ -120,7 +118,7 @@ fi
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
#=================================================
# RELOAD NGINX

View file

@ -22,7 +22,7 @@ ynh_abort_if_errors
# RETRIEVE ARGUMENTS
#=================================================
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
@ -52,7 +52,7 @@ EOF
}
get__prices() {
local prices = "$(grep "DONATION\['" "$final_path/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')"
local prices = "$(grep "DONATION\['" "$config_path/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')"
if [ "$prices" == "," ];
then
# Return YNH_NULL if you prefer to not return a value at all.
@ -85,9 +85,9 @@ set__prices() {
frequency=$(echo $price | cut -d/ -f1)
currency=$(echo $price | cut -d/ -f2)
price_id=$(echo $price | cut -d/ -f3)
sed "d/DONATION\['$frequency'\]\['$currency'\]" "$final_path/settings.py"
sed "d/DONATION\['$frequency'\]\['$currency'\]" "$config_path/settings.py"
echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py"
echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$config_path/settings.py"
done
#---------------------------------------------

221
scripts/install Executable file → Normal file
View file

@ -7,6 +7,7 @@
#=================================================
source _common.sh
source ynh_install_go
source /usr/share/yunohost/helpers
#=================================================
@ -24,22 +25,25 @@ ynh_abort_if_errors
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
path_url="/"
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
node_type=$YNH_APP_ARG_NODE_TYPE
bootstrap_expect=$YNH_APP_ARG_BOOTSTRAP_EXPECT
retry_join=$YNH_APP_ARG_RETRY_JOIN
server_ip=$YNH_APP_ARG_SERVER_IP
driver_lxc=$YNH_APP_ARG_DRIVER_LXC
app=$YNH_APP_INSTANCE_NAME
client_lxc_bridge="lxcbr0"
client_lxc_plage_ip="10.1.44"
client_lxc_main_iface=$(ip route | grep default | awk '{print $5;}')
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
@ -50,8 +54,14 @@ ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=node_type --value=$node_type
ynh_app_setting_set --app=$app --key=bootstrap_expect --value=$bootstrap_expect
ynh_app_setting_set --app=$app --key=retry_join --value=$retry_join
ynh_app_setting_set --app=$app --key=server_ip --value=$server_ip
ynh_app_setting_set --app=$app --key=driver_lxc --value=$driver_lxc
ynh_app_setting_set --app=$app --key=client_lxc_bridge --value=$client_lxc_bridge
ynh_app_setting_set --app=$app --key=client_lxc_plage_ip --value=$client_lxc_plage_ip
ynh_app_setting_set --app=$app --key=client_lxc_main_iface --value=$client_lxc_main_iface
#=================================================
# STANDARD MODIFICATIONS
@ -61,23 +71,49 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_script_progression --message="Finding an available port..."
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
http_port=4646
ynh_port_available --port=$http_port || ynh_die --message="Port $http_port is needs to be available for this app"
ynh_app_setting_set --app=$app --key=http_port --value=$http_port
# Optional: Expose this port publicly
# (N.B.: you only need to do this if the app actually needs to expose the port publicly.
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
rpc_port=4647
ynh_port_available --port=$rpc_port || ynh_die --message="Port $rpc_port is needs to be available for this app"
ynh_app_setting_set --app=$app --key=rpc_port --value=$rpc_port
serf_port=4648
ynh_port_available --port=$serf_port || ynh_die --message="Port $serf_port is needs to be available for this app"
ynh_app_setting_set --app=$app --key=serf_port --value=$serf_port
# Open the port
# ynh_script_progression --message="Configuring firewall..."
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_script_progression --message="Configuring firewall..."
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $rpc_port
needs_exposed_ports="$rpc_port"
if [ "$node_type" == "server" ]
then
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $serf_port
needs_exposed_ports="$serf_port $needs_exposed_ports"
fi
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
if [ "$node_type" == "server" ]
then
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
fi
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
ynh_exec_warn_less ynh_install_go --go_version=$go_version
fi
pkg_dependencies="$pkg_dependencies $client_pkg_dependencies"
fi
ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
#=================================================
# CREATE DEDICATED USER
@ -85,38 +121,7 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..."
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
ynh_system_user_create --username=$app
#=================================================
# NGINX CONFIGURATION
@ -128,10 +133,6 @@ ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ...
#=================================================
#=================================================
# CREATE DATA DIRECTORY
#=================================================
@ -141,46 +142,100 @@ datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir
mkdir -p $datadir/plugins
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
chown -R $app:$app "$datadir"
#=================================================
# BUILD DRIVERS
#=================================================
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
ynh_script_progression --message="Building LXC driver..."
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir="$tempdir" --source_id="driver-lxc"
pushd $tempdir
final_path=$tempdir
ynh_use_go
export GOPATH="$tempdir/go"
export GOCACHE="$tempdir/.cache"
ynh_exec_warn_less $ynh_go build
popd
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
ynh_secure_remove --file="$tempdir"
fi
fi
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
config_path=/etc/$app.d
ynh_app_setting_set --app=$app --key=config_path --value=$config_path
chmod 400 "$final_path/some_config_file"
chown $app:$app "$final_path/some_config_file"
mkdir -p $config_path
chmod 750 "$config_path"
chmod -R o-rwx "$config_path"
chown -R $app:$app "$config_path"
ynh_add_config --template="../conf/nomad.hcl" --destination="$config_path/nomad.hcl"
chmod 400 "$config_path/nomad.hcl"
chown $app:$app "$config_path/nomad.hcl"
if [ "$node_type" == "server" ]
then
ynh_add_config --template="../conf/server.hcl" --destination="$config_path/server.hcl"
chmod 400 "$config_path/server.hcl"
chown $app:$app "$config_path/server.hcl"
fi
if [ "$node_type" == "client" ]
then
ynh_add_config --template="../conf/client.hcl" --destination="$config_path/client.hcl"
chmod 400 "$config_path/client.hcl"
chown $app:$app "$config_path/client.hcl"
if [ $driver_lxc -eq 1 ]
then
ynh_add_config --template="../conf/driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
chmod 400 "$config_path/driver-lxc.hcl"
chown $app:$app "$config_path/driver-lxc.hcl"
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
systemctl restart dnsmasq
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
fi
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
systemctl enable lxc-net --quiet
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Started LXC network bridge" --log_path="systemd"
fi
fi
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
systemd_user=$app
if [ "$node_type" == "client" ]
then
systemd_user="root"
fi
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
ynh_script_progression --message="Setuping application with CURL..."
# Set the app as temporarily public for curl call
ynh_script_progression --message="Configuring SSOwat..."
# Making the app public for curl
ynh_permission_update --permission="main" --add="visitors"
# Installation with curl
ynh_script_progression --message="Finalizing installation..."
ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
# Remove the public access
ynh_permission_update --permission="main" --remove="visitors"
#=================================================
# GENERIC FINALIZATION
#=================================================
@ -196,7 +251,7 @@ ynh_use_logrotate
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/$app.log"
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports $needs_exposed_ports
#=================================================
# START SYSTEMD SERVICE
@ -204,15 +259,7 @@ yunohost service add $app --log="/var/log/$app/$app.log"
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..."
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
#=================================================
# SETUP SSOWAT
@ -227,14 +274,6 @@ then
ynh_permission_update --permission="main" --add="visitors"
fi
# Only the admin can access the admin panel of the app (if the app has an admin panel)
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
# Everyone can access the API part
# We don't want to display the tile in the SSO so we put --show_tile="false"
# And we don't want the YunoHost admin to be able to remove visitors group to this permission, so we put --protected="true"
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
#=================================================
# RELOAD NGINX
#=================================================

View file

@ -7,6 +7,7 @@
#=================================================
source _common.sh
source ynh_install_go
source /usr/share/yunohost/helpers
#=================================================
@ -17,11 +18,12 @@ ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
#=================================================
# STANDARD REMOVE
@ -41,6 +43,7 @@ fi
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_exec_warn_less nomad node drain -self -enable
# Remove the dedicated systemd config
ynh_remove_systemd_config
@ -53,20 +56,59 @@ ynh_script_progression --message="Removing logrotate configuration..."
ynh_remove_logrotate
#=================================================
# REMOVE THE MYSQL DATABASE
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing the MySQL database..."
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE APP MAIN DIR
# CLOSE A PORT
#=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
if yunohost firewall list | grep -q "\- $rpc_port$"
then
ynh_script_progression --message="Closing port $rpc_port..."
ynh_exec_warn_less yunohost firewall disallow TCP $rpc_port
fi
if yunohost firewall list | grep -q "\- $serf_port$"
then
ynh_script_progression --message="Closing port $serf_port..."
ynh_exec_warn_less yunohost firewall disallow TCP $serf_port
fi
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
client_lxc_bridge=$(ynh_app_setting_get --app=$app --key=client_lxc_bridge)
ynh_systemd_action --service_name=lxc-net --action="stop"
systemctl disable lxc-net --quiet
ynh_secure_remove --file="/etc/default/lxc-net"
ynh_secure_remove --file="/etc/lxc/default.conf"
ynh_secure_remove --file="/etc/dnsmasq.d/lxd"
systemctl restart dnsmasq
fi
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
ynh_remove_go
fi
fi
#=================================================
# REMOVE DATA DIR
@ -79,48 +121,6 @@ then
ynh_secure_remove --file="$datadir"
fi
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Removing PHP-FPM configuration..."
# Remove the dedicated PHP-FPM config
ynh_remove_fpm_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
#=================================================
# REMOVE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Removing Fail2Ban configuration..."
# Remove the dedicated Fail2Ban config
ynh_remove_fail2ban_config
#=================================================
# SPECIFIC REMOVE
#=================================================
@ -128,11 +128,8 @@ ynh_remove_fail2ban_config
#=================================================
ynh_script_progression --message="Removing various files..."
# Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app"
# Remove a directory securely
ynh_secure_remove --file="/etc/$app"
ynh_secure_remove --file="$config_path"
# Remove the log files
ynh_secure_remove --file="/var/log/$app"

117
scripts/restore Executable file → Normal file
View file

@ -29,20 +29,19 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
http_port=$(ynh_app_setting_get --app=$app --key=http_port)
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
@ -51,18 +50,7 @@ test ! -d $final_path \
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
ynh_system_user_create --username=$app
#=================================================
# RESTORE THE DATA DIRECTORY
@ -75,16 +63,7 @@ mkdir -p $datadir
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..."
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
chown -R $app:$app "$datadir"
#=================================================
# SPECIFIC RESTORATION
@ -93,15 +72,21 @@ ynh_systemd_action --action=restart --service_name=fail2ban
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
# Define and install dependencies
if [ "$node_type" == "server" ]
then
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
fi
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
fi
pkg_dependencies="$pkg_dependencies $client_pkg_dependencies"
fi
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the PHP-FPM configuration..."
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
#=================================================
# RESTORE THE NGINX CONFIGURATION
@ -110,23 +95,48 @@ ynh_script_progression --message="Restoring the NGINX web server configuration..
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..."
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="$config_path"
ynh_restore_file --origin_path="/etc/$app/"
chmod 750 "$config_path"
chmod -R o-rwx "$config_path"
chown -R $app:$app "$config_path"
# Open the port
ynh_script_progression --message="Configuring firewall..."
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $rpc_port
needs_exposed_ports="$rpc_port"
if [ "$node_type" == "server" ]
then
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $serf_port
needs_exposed_ports="$serf_port $needs_exposed_ports"
fi
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
client_lxc_bridge=$(ynh_app_setting_get --app=$app --key=client_lxc_bridge)
client_lxc_plage_ip=$(ynh_app_setting_get --app=$app --key=client_lxc_plage_ip)
client_lxc_main_iface=$(ip route | grep default | awk '{print $5;}')
ynh_app_setting_set --app=$app --key=client_lxc_main_iface --value=$client_lxc_main_iface
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
systemctl restart dnsmasq
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
fi
ynh_secure_remove --file="/etc/lxc/default.conf"
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
systemctl enable lxc-net --quiet
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Started LXC network bridge" --log_path="systemd"
fi
fi
#=================================================
# RESTORE SYSTEMD
@ -141,6 +151,8 @@ systemctl enable $app.service --quiet
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
mkdir -p /var/log/$app
chown -R $app:$app "/var/log/$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
@ -148,23 +160,22 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/$app.log"
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports $needs_exposed_ports
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================

View file

@ -7,6 +7,7 @@
#=================================================
source _common.sh
source ynh_install_go
source /usr/share/yunohost/helpers
#=================================================
@ -18,10 +19,16 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
language=$(ynh_app_setting_get --app=$app --key=language)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
bootstrap_expect=$(ynh_app_setting_get --app=$app --key=bootstrap_expect)
retry_join=$(ynh_app_setting_get --app=$app --key=retry_join)
server_ip=$(ynh_app_setting_get --app=$app --key=server_ip)
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
http_port=$(ynh_app_setting_get --app=$app --key=http_port)
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
#=================================================
# CHECK VERSION
@ -66,54 +73,35 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
fi
# Create a permission if needed
if ! ynh_permission_exists --permission="api"; then
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
ynh_system_user_create --username=$app
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
if [ "$node_type" == "server" ]
then
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
fi
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
ynh_exec_warn_less ynh_install_go --go_version=$go_version
fi
pkg_dependencies="$pkg_dependencies $client_pkg_dependencies"
fi
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
#=================================================
# NGINX CONFIGURATION
@ -126,24 +114,77 @@ ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
# BUILD DRIVERS
#=================================================
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
ynh_script_progression --message="Building LXC driver..."
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir="$tempdir" --source_id="driver-lxc"
pushd $tempdir
final_path=$tempdir
ynh_use_go
export GOPATH="$tempdir/go"
export GOCACHE="$tempdir/.cache"
ynh_exec_warn_less $ynh_go build
popd
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
ynh_secure_remove --file="$tempdir"
fi
fi
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
mkdir -p $config_path
chmod 750 "$config_path"
chmod -R o-rwx "$config_path"
chown -R $app:$app "$config_path"
chmod 400 "$final_path/some_config_file"
chown $app:$app "$final_path/some_config_file"
ynh_add_config --template="../conf/nomad.hcl" --destination="$config_path/nomad.hcl"
chmod 400 "$config_path/nomad.hcl"
chown $app:$app "$config_path/nomad.hcl"
if [ "$node_type" == "server" ]
then
ynh_add_config --template="../conf/server.hcl" --destination="$config_path/server.hcl"
chmod 400 "$config_path/server.hcl"
chown $app:$app "$config_path/server.hcl"
fi
if [ "$node_type" == "client" ]
then
ynh_add_config --template="../conf/client.hcl" --destination="$config_path/client.hcl"
chmod 400 "$config_path/client.hcl"
chown $app:$app "$config_path/client.hcl"
if [ $driver_lxc -eq 1 ]
then
ynh_add_config --template="../conf/driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
chmod 400 "$config_path/driver-lxc.hcl"
chown $app:$app "$config_path/driver-lxc.hcl"
fi
fi
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
systemd_user=$app
if [ "$node_type" == "client" ]
then
systemd_user="root"
fi
# Create a dedicated systemd config
ynh_add_systemd_config
@ -162,22 +203,19 @@ ynh_use_logrotate --non-append
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/$app.log"
needs_exposed_ports="$rpc_port"
if [ "$node_type" == "server" ]
then
needs_exposed_ports="$serf_port $needs_exposed_ports"
fi
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports $needs_exposed_ports
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..."
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
#=================================================
# RELOAD NGINX

247
scripts/ynh_install_go Normal file
View file

@ -0,0 +1,247 @@
#!/bin/bash
ynh_go_try_bash_extension() {
if [ -x src/configure ]; then
src/configure && make -C src || {
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
}
fi
}
goenv_install_dir="/opt/goenv"
go_version_path="$goenv_install_dir/versions"
# goenv_ROOT is the directory of goenv, it needs to be loaded as a environment variable.
export GOENV_ROOT="$goenv_install_dir"
# Load the version of Go for an app, and set variables.
#
# ynh_use_go has to be used in any app scripts before using Go for the first time.
# This helper will provide alias and variables to use in your scripts.
#
# To use gem or Go, use the alias `ynh_gem` and `ynh_go`
# Those alias will use the correct version installed for the app
# For example: use `ynh_gem install` instead of `gem install`
#
# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_go`
# And propagate $PATH to sudo with $ynh_go_load_path
# Exemple: `ynh_exec_as $app $ynh_go_load_path $ynh_gem install`
#
# $PATH contains the path of the requested version of Go.
# However, $PATH is duplicated into $go_path to outlast any manipulation of $PATH
# You can use the variable `$ynh_go_load_path` to quickly load your Go version
# in $PATH for an usage into a separate script.
# Exemple: $ynh_go_load_path $final_path/script_that_use_gem.sh`
#
#
# Finally, to start a Go service with the correct version, 2 solutions
# Either the app is dependent of Go or gem, but does not called it directly.
# In such situation, you need to load PATH
# `Environment="__YNH_GO_LOAD_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
# You will replace __YNH_GO_LOAD_PATH__ with $ynh_go_load_path
#
# Or Go start the app directly, then you don't need to load the PATH variable
# `ExecStart=__YNH_GO__ my_app run`
# You will replace __YNH_GO__ with $ynh_go
#
#
# one other variable is also available
# - $go_path: The absolute path to Go binaries for the chosen version.
#
# usage: ynh_use_go
#
# Requires YunoHost version 3.2.2 or higher.
ynh_use_go () {
go_version=$(ynh_app_setting_get --app=$app --key=go_version)
# Get the absolute path of this version of Go
go_path="$go_version_path/$go_version/bin"
# Allow alias to be used into bash script
shopt -s expand_aliases
# Create an alias for the specific version of Go and a variable as fallback
ynh_go="$go_path/go"
alias ynh_go="$ynh_go"
# Load the path of this version of Go in $PATH
if [[ :$PATH: != *":$go_path"* ]]; then
PATH="$go_path:$PATH"
fi
# Create an alias to easily load the PATH
ynh_go_load_path="PATH=$PATH"
# Sets the local application-specific Go version
pushd $final_path
$goenv_install_dir/bin/goenv local $go_version
popd
}
# Install a specific version of Go
#
# ynh_install_go will install the version of Go provided as argument by using goenv.
#
# This helper creates a /etc/profile.d/goenv.sh that configures PATH environment for goenv
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
#
# Don't forget to execute go-dependent command in a login environment
# (e.g. sudo --login option)
# When not possible (e.g. in systemd service definition), please use direct path
# to goenv shims (e.g. $goenv_ROOT/shims/bundle)
#
# usage: ynh_install_go --go_version=go_version
# | arg: -v, --go_version= - Version of go to install.
#
# Requires YunoHost version 3.2.2 or higher.
ynh_install_go () {
# Declare an array to define the options of this helper.
local legacy_args=v
local -A args_array=( [v]=go_version= )
local go_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Go prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing Go binary, to avoid to block goenv
test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv
# Install or update goenv
goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)"
if [ -n "$goenv" ]; then
ynh_print_info --message="goenv already seems installed in \`$goenv'."
pushd "${goenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then
echo "Trying to update with git..."
git pull -q --tags origin master
cd ..
ynh_go_try_bash_extension
fi
popd
else
ynh_print_info --message="Installing goenv with git..."
mkdir -p $goenv_install_dir
pushd $goenv_install_dir
git init -q
git remote add -f -t master origin https://github.com/syndbg/goenv.git > /dev/null 2>&1
git checkout -q -b master origin/master
ynh_go_try_bash_extension
goenv=$goenv_install_dir/bin/goenv
popd
fi
goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)"
if [ -n "$goenv_latest" ]; then
ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'."
pushd "${goenv_latest%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then
ynh_print_info --message="Trying to update xxenv-latest with git..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${goenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest"
fi
# Enable caching
mkdir -p "${goenv_install_dir}/cache"
# Create shims directory if needed
mkdir -p "${goenv_install_dir}/shims"
# Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH
# And replace the old Go binary
test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go
# Install the requested version of Go
local final_go_version=$(goenv latest --print $go_version)
ynh_print_info --message="Installation of Go-$final_go_version"
goenv install --skip-existing $final_go_version
# Store go_version into the config of this app
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version
# Cleanup Go versions
ynh_cleanup_go
# Set environment for Go users
echo "#goenv
export GOENV_ROOT=$goenv_install_dir
export PATH=\"$goenv_install_dir/bin:$PATH\"
eval \"\$(goenv init -)\"
#goenv" > /etc/profile.d/goenv.sh
# Load the environment
eval "$(goenv init -)"
}
# Remove the version of Go used by the app.
#
# This helper will also cleanup Go versions
#
# usage: ynh_remove_go
ynh_remove_go () {
local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version)
# Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Go prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Remove the line for this app
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version
# Cleanup Go versions
ynh_cleanup_go
}
# Remove no more needed versions of Go used by the app.
#
# This helper will check what Go version are no more required,
# and uninstall them
# If no app uses Go, goenv will be also removed.
#
# usage: ynh_cleanup_go
ynh_cleanup_go () {
# List required Go versions
local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id)
local required_go_versions=""
for installed_app in $installed_apps
do
local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version")
if [[ $installed_app_go_version ]]
then
required_go_versions="${installed_app_go_version}\n${required_go_versions}"
fi
done
# Remove no more needed Go versions
local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/')
for installed_go_version in $installed_go_versions
do
if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1`
then
ynh_print_info --message="Removing of Go-$installed_go_version"
$goenv_install_dir/bin/goenv uninstall --force $installed_go_version
fi
done
# If none Go version is required
if [[ ! $required_go_versions ]]
then
# Remove goenv environment configuration
ynh_print_info --message="Removing of goenv"
ynh_secure_remove --file="$goenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/goenv.sh"
fi
}