-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ionut Nechita <[email protected]>
- Loading branch information
1 parent
3127850
commit 6f2b88d
Showing
4 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
set -e | ||
|
||
mkdir -p "$out"/bin | ||
|
||
cat > "$out"/bin/control <<EOF | ||
export PATH="$PATH":"$su"/bin | ||
start() | ||
{ | ||
su "$user" -s /bin/sh -c 'cd $serverDir; \ | ||
export JBOSS_JAVA_SIZING="\ | ||
-Xms$initialHeapMem \ | ||
-Xmx$maxHeapMem \ | ||
-XX:MetaspaceSize=$initialMetaspaceSize \ | ||
-XX:MaxMetaspaceSize=$maxMetaspaceSize"; \ | ||
$serverDir/bin/$wildflyMode.sh \ | ||
-c $wildflyConfig \ | ||
-b $wildflyBind \ | ||
-bmanagement $wildflyBindManagement \ | ||
' | ||
} | ||
preStart() | ||
{ | ||
su "$user" -s /bin/sh -c 'cd $serverDir; \ | ||
$serverDir/bin/add-user.sh \ | ||
-u $userAdmin \ | ||
-p $passwordAdmin \ | ||
' | ||
} | ||
if [ "$cleanBoot" == "1" ]; then | ||
rm -rf "$serverDir" | ||
fi | ||
if [ ! -d "$serverDir" ]; then | ||
mkdir -p "$serverDir" | ||
cd "$serverDir" | ||
cp -a "$wildfly"/opt/wildfly/* . | ||
chown -R "$user":"$group" "$serverDir" | ||
for i in \`find "$serverDir" -type d\` | ||
do | ||
chmod 775 -R "\$i" 2>/dev/null | ||
done | ||
for i in \`find "$serverDir" -type f\` | ||
do | ||
chmod 664 -R "\$i" 2>/dev/null | ||
done | ||
for i in \`find "$serverDir" -name "*.sh"\` | ||
do | ||
chmod 775 -R "\$i" 2>/dev/null | ||
done | ||
preStart | ||
fi | ||
start | ||
EOF | ||
|
||
chmod +x "$out"/bin/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
|
||
with lib; | ||
|
||
let | ||
|
||
cfg = config.services.wildfly; | ||
|
||
wildflyService = pkgs.stdenv.mkDerivation { | ||
name = "wildfly-server"; | ||
builder = ./builder.sh; | ||
inherit (pkgs) wildfly su; | ||
inherit (cfg) | ||
enable | ||
cleanBoot | ||
serverDir | ||
user | ||
group | ||
userAdmin | ||
passwordAdmin | ||
initialHeapMem | ||
maxHeapMem | ||
initialMetaspaceSize | ||
maxMetaspaceSize | ||
wildflyConfig | ||
wildflyMode | ||
wildflyBind | ||
wildflyBindManagement | ||
; | ||
}; | ||
|
||
cleanupScript = pkgs.writeScript "wildfly-cleanup" '' | ||
#!${pkgs.bash}/bin/bash | ||
if [ "${toString cfg.cleanBoot}" == "1" ]; then | ||
rm -rf ${cfg.serverDir} | ||
fi | ||
''; | ||
|
||
in | ||
|
||
{ | ||
|
||
###### interface | ||
|
||
options = { | ||
|
||
services.wildfly = { | ||
|
||
enable = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = "Whether to enable Wildfly."; | ||
}; | ||
|
||
cleanBoot = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = "Delete and install the server instance file location every time. No persistence."; | ||
}; | ||
|
||
serverDir = mkOption { | ||
description = "Location of the server instance files"; | ||
default = "/opt/wildfly"; | ||
type = types.str; | ||
}; | ||
|
||
user = mkOption { | ||
default = "nobody"; | ||
description = "User account under which Wildfly runs."; | ||
type = types.str; | ||
}; | ||
|
||
group = mkOption { | ||
default = "nogroup"; | ||
description = "Group account under which Wildfly runs."; | ||
type = types.str; | ||
}; | ||
|
||
userAdmin = mkOption { | ||
default = "admin"; | ||
description = "Admin user who does the web management of Wildfly."; | ||
type = types.str; | ||
}; | ||
|
||
passwordAdmin = mkOption { | ||
default = "wildfly"; | ||
description = "Password admin user who does the web management of Wildfly."; | ||
type = types.str; | ||
}; | ||
|
||
initialHeapMem = mkOption { | ||
description = "Initial Heap memory."; | ||
default = "400M"; | ||
type = types.str; | ||
}; | ||
|
||
maxHeapMem = mkOption { | ||
description = "Max Heap memory."; | ||
default = "600M"; | ||
type = types.str; | ||
}; | ||
|
||
initialMetaspaceSize = mkOption { | ||
description = "Initial Metaspace size."; | ||
default = "100M"; | ||
type = types.str; | ||
}; | ||
|
||
maxMetaspaceSize = mkOption { | ||
description = "Max Metaspace size."; | ||
default = "300M"; | ||
type = types.str; | ||
}; | ||
|
||
wildflyConfig = mkOption { | ||
description = "Wildfly default config."; | ||
default = "standalone-full.xml"; | ||
type = types.str; | ||
}; | ||
|
||
wildflyMode = mkOption { | ||
description = "Wildfly default mode."; | ||
default = "standalone"; | ||
type = types.str; | ||
}; | ||
|
||
wildflyBind = mkOption { | ||
description = "Wildfly bind address."; | ||
default = "0.0.0.0"; | ||
type = types.str; | ||
}; | ||
|
||
wildflyBindManagement = mkOption { | ||
description = "Wildfly bind management address."; | ||
default = "127.0.0.1"; | ||
type = types.str; | ||
}; | ||
|
||
}; | ||
|
||
}; | ||
|
||
###### implementation | ||
|
||
config = mkMerge [ | ||
(mkIf cfg.enable { | ||
systemd.services.wildfly = { | ||
description = "WildFly Application Server"; | ||
script = "${wildflyService}/bin/control"; | ||
wantedBy = [ "multi-user.target" ]; | ||
}; | ||
}) | ||
|
||
(mkIf ((!cfg.enable) && cfg.cleanBoot) { | ||
system.activationScripts.wildflyCleanup = { | ||
text = '' | ||
${cleanupScript} | ||
''; | ||
deps = [ ]; | ||
}; | ||
}) | ||
]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
lib, | ||
stdenv, | ||
fetchurl, | ||
common-updater-scripts, | ||
coreutils, | ||
git, | ||
gnused, | ||
makeWrapper, | ||
nix, | ||
openjdk, | ||
writeScript, | ||
nixosTests, | ||
jq, | ||
cacert, | ||
curl, | ||
}: | ||
|
||
stdenv.mkDerivation rec { | ||
pname = "wildfly"; | ||
version = "24.0.1"; | ||
|
||
src = fetchurl { | ||
url = "https://download.jboss.org/wildfly/${version}.Final/wildfly-${version}.Final.tar.gz"; | ||
hash = "sha256-eD88L5gHeYc6vHC8lRdRHWUGk2wbYRwCjnc+6R5U7o8="; | ||
}; | ||
|
||
nativeBuildInputs = [ makeWrapper ]; | ||
|
||
buildCommand = '' | ||
mkdir -p "$out/opt" | ||
tar xf "$src" -C "$out/opt" | ||
mv "$out/opt/${pname}-${version}.Final" "$out/opt/${pname}" | ||
find "$out/opt/${pname}" -name \*.sh -print0 | xargs -0 sed -i -e '/#!\/bin\/sh/aJAVA_HOME=${openjdk}' | ||
''; | ||
|
||
meta = { | ||
description = "WildFly Application Server"; | ||
homepage = "https://www.wildfly.org/"; | ||
sourceProvenance = with sourceTypes; [ binaryBytecode ]; | ||
license = licenses.asl20; | ||
maintainers = with maintainers; [ | ||
ionutnechita | ||
]; | ||
mainProgram = "wildfly"; | ||
platforms = platforms.unix; | ||
}; | ||
} |