Skip to content

Commit b477ee2

Browse files
committed
Firefly-2137: use a non-openssl version of redis for firefly standalone
1 parent f7a28d0 commit b477ee2

8 files changed

Lines changed: 106 additions & 8 deletions

File tree

‎bin/install.sh‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ fi
270270
# --------------------------
271271

272272
requiredFiles=("standalone_cleanup.sh" "$startScript" "startFireflyServer.sh" \
273-
"stopFireflyServer.sh" "statusFireflyServer.sh" "javaInstaller.sh" "updater.sh" "common.sh")
273+
"stopFireflyServer.sh" "statusFireflyServer.sh" "javaInstaller.sh" "updater.sh" "common.sh" \
274+
"redis/osx/redis-server-7.2-darwin-arm64")
274275
missingFiles=""
275276
for f in "${requiredFiles[@]}"; do
276277
if [ ! -f "$applicationDir/$f" ]; then
@@ -294,6 +295,13 @@ chmod 775 "$applicationDir/standalone_cleanup.sh" \
294295
"$applicationDir/install.sh"
295296
/bin/mv "$applicationDir/updater.sh" "$applicationRoot"
296297

298+
# redis for macOS (see assets/redis/osx/redis-info.md). unzip marks the files of a browser-downloaded zip as
299+
# quarantined, and macOS kills a quarantined binary that is not notarized
300+
if [[ "$(uname)" == "Darwin" ]]; then
301+
chmod +x "$applicationDir/redis/osx/redis-server-7.2-darwin-arm64"
302+
xattr -dr com.apple.quarantine "$applicationDir/redis" 2> /dev/null
303+
fi
304+
297305
cp "$applicationDir/$startScript" "$binDir"
298306
chmod +x "$binDir/$startScript"
299307

‎src/firefly/java/edu/caltech/ipac/firefly/core/RedisService.java‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package edu.caltech.ipac.firefly.core;
66

77
import edu.caltech.ipac.firefly.data.ServerEvent;
8+
import edu.caltech.ipac.firefly.server.ServerContext;
89
import edu.caltech.ipac.firefly.server.events.FluxAction;
910
import edu.caltech.ipac.firefly.server.events.ServerEventManager;
1011
import edu.caltech.ipac.firefly.server.servlets.ServerStatus;
@@ -25,6 +26,7 @@
2526
import io.lettuce.core.event.connection.ConnectionDeactivatedEvent;
2627
import io.lettuce.core.resource.DefaultClientResources;
2728
import redis.embedded.RedisServer;
29+
import redis.embedded.core.ExecutableProvider;
2830

2931
import java.io.File;
3032
import java.security.MessageDigest;
@@ -162,15 +164,36 @@ private static void tryConnect() throws Exception{
162164
}
163165
}
164166

167+
/**
168+
* Redis without TLS packaged with standalone Firefly for Apple Silicon (see assets/redis/osx/redis-info.md).
169+
* The Redis bundled in embedded-redis for Apple Silicon needs Homebrew's OpenSSL.
170+
* Returns null when not applicable
171+
*/
172+
private static ExecutableProvider packagedRedis7Provider() {
173+
boolean appleSilicon =
174+
System.getProperty("os.name", "").startsWith("Mac")
175+
&& "aarch64".equals(System.getProperty("os.arch"));
176+
String path = System.getProperty(ExecutableProvider.PROPERTY_EXECUTABLE_LOCATION);
177+
if (!appleSilicon || path == null) return null;
178+
if (!new File(path).canExecute()) {
179+
LOG.warn("Redis build without TLS not found or not executable: " + path + ", using the bundled Redis");
180+
return null;
181+
}
182+
return ExecutableProvider.newSystemPropertyProvider();
183+
}
184+
165185
private static void startLocal() throws Exception {
166186
new File(DB_DIR).mkdirs();
167-
RedisServer localRedis = RedisServer.newRedisServer()
187+
var execProvider = ServerContext.isStandalone() ? packagedRedis7Provider() : null;
188+
var dbFile = execProvider==null ? "redis.rdb" : "redis-7.2.rdb"; // Redis 6.2 cannot read an rdb written by 7.2
189+
var builder = RedisServer.newRedisServer()
168190
.port(REDIS_PORT)
169191
.setting("maxmemory %s".formatted(LOCAL_MAX_MEM))
170192
.setting("dir %s".formatted(DB_DIR))
171-
.setting("dbfilename redis.rdb")
172-
.setting("save 600 1")
173-
.build();
193+
.setting("dbfilename %s".formatted(dbFile))
194+
.setting("save 600 1");
195+
if (execProvider != null) builder = builder.executableProvider(execProvider);
196+
RedisServer localRedis = builder.build();
174197
localRedis.start();
175198
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
176199
try {

‎src/firefly/java/edu/caltech/ipac/firefly/server/ServerContext.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public class ServerContext {
8888

8989

9090
private final static String cloudEnvironmentDefault = System.getProperty("cloud.environment", "detect"); // can be "GCP", "AWS", "ON_PREM" or "detect"
91+
92+
9193
private final static UriRef.CloudEnvironment cloudEnvironment= findEnvironment();
9294
private static RequestOwnerThreadLocal owner = new RequestOwnerThreadLocal();
9395
private static String webappConfigPath;
@@ -843,6 +845,10 @@ public static boolean isInUploadDir(File f) {
843845
public static UriRef.CloudEnvironment getCloudEnvironment() {return cloudEnvironment;}
844846
public static boolean isRunningInCloud() {return cloudEnvironment!= UriRef.CloudEnvironment.ON_PREM;}
845847

848+
public static boolean isStandalone() {
849+
return AppProperties.getBooleanProperty("OP_standaloneEnabled", false);
850+
}
851+
846852

847853
private static class AssertLogger implements Assert.Logger {
848854
private final Logger.LoggerImpl _log= Logger.getLogger();

‎src/standalone/assets/common.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# common.sh: shared variables for the Firefly standalone runtime scripts.
33
# Must be sourced with $INSTALL_DIR already set (every caller needs it anyway to
44
# locate this file). Defines: applicationDir, fireflyDir, binDir, configJsonFile,
5-
# JQ, pidFile, portFile, redisDbDir, ffPort, redisPort.
5+
# JQ, pidFile, portFile, redisDbDir, redisMacExecFile, ffPort, redisPort.
66
# --------------------------
77

88
# shellcheck disable=SC2034
@@ -13,6 +13,7 @@ configJsonFile="$fireflyDir/config.json"
1313
pidFile="$fireflyDir/pid.txt"
1414
portFile="$fireflyDir/port.txt"
1515
redisDbDir="${fireflyDir}/server/temp/redis"
16+
redisMacExecFile="${applicationDir}/redis/osx/redis-server-7.2-darwin-arm64"
1617
JQ=$(which jq || echo "$binDir/jq")
1718

1819
if [[ -f "$portFile" && -s "$portFile" && -r "$portFile" ]]; then
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Redis for macOS (Apple Silicon), no-TLS build
2+
3+
`redis-server-7.2-darwin-arm64` is Redis 7.2.3 for Apple Silicon, built without TLS, so it has no
4+
OpenSSL dependency (`otool -L` lists only `libSystem`).
5+
6+
## Why it is here
7+
8+
The Redis binary bundled in the `embedded-redis` library for Apple Silicon links Homebrew's OpenSSL
9+
and will not start on a Mac without it:
10+
11+
dyld: Library not loaded: /opt/homebrew/opt/openssl@3/lib/libssl.3.dylib
12+
13+
Standalone Firefly (`OP_standaloneEnabled=true`) on Apple Silicon uses this binary instead.
14+
Linux, Intel Macs and Docker are unchanged. Firefly does not use Redis TLS.
15+
16+
## Where it came from
17+
18+
- A third-party build ("HankCP") distributed in the embedded-redis project, which is also the
19+
library's `ExecutableProvider.REDIS_7_2_MACOSX_14_SONOMA_HANKCP`:
20+
https://github.com/codemonstur/embedded-redis/tree/master/src/main/binaries
21+
- `./redis-server-7.2-darwin-arm64 --version` reports `v=7.2.3 sha=7f4bae81:0`. That commit is the
22+
official redis/redis tag 7.2.3, and `:0` means a clean checkout.
23+
- Built on macOS 14 (minimum macOS 14.0), ad-hoc signed, 2,338,096 bytes.
24+
- SHA-256: `a4a0078c060895140d8277877cec64ef414702af1fbc53dc3b3d7f1d6700dced`
25+
26+
## How to get it
27+
28+
The URL below is pinned to a commit, so the content cannot change:
29+
30+
curl -L -o redis-server-7.2-darwin-arm64 \
31+
https://github.com/codemonstur/embedded-redis/raw/4a83d18637478bfffef191648d6e9c36a708a347/src/main/binaries/redis-server-7.2-darwin-arm64
32+
shasum -a 256 redis-server-7.2-darwin-arm64 # must match the SHA-256 above
33+
chmod +x redis-server-7.2-darwin-arm64
34+
otool -L redis-server-7.2-darwin-arm64 # only /usr/lib/libSystem.B.dylib
35+
./redis-server-7.2-darwin-arm64 --version # Redis server v=7.2.3 sha=7f4bae81:0
36+
37+
Use curl, not a browser. A browser adds `com.apple.quarantine`, and macOS kills a non-notarized
38+
binary that has it (the process just dies, exit 137). If that happened:
39+
40+
xattr -d com.apple.quarantine redis-server-7.2-darwin-arm64
41+
42+
## License
43+
44+
Redis 7.2.3 is BSD-3-Clause. The license text must accompany binary distributions:
45+
46+
Copyright (c) 2006-2020, Salvatore Sanfilippo
47+
All rights reserved.
48+
49+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
50+
51+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
52+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
53+
* Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
54+
55+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2.23 MB
Binary file not shown.

‎src/standalone/assets/startFireflyServer.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,14 @@ if [[ "$name" == "Darwin" ]]; then
265265
nameParam='-Xdock:name=Firefly Server'
266266
runAsDesktopApplication="true"
267267
headless="false"
268+
redisExecParam="-Dembedded.redis.executable=${redisMacExecFile}"
268269
#dockIcon="-Xdock:icon=${applicationDir}/fireflyDockIcon.png" --- keep around if we decide to read dock
269270
else
270271
splash=
271272
nameParam="-DdockPlaceHolder="
272273
runAsDesktopApplication="false"
273274
headless="true"
275+
redisExecParam=
274276
#dockIcon=
275277
fi
276278

@@ -296,6 +298,7 @@ PROPS=" \
296298
-Djava.awt.headless=${headless} \
297299
-Dvisualize.fits.search.path=${HOME} \
298300
-Dredis.db.dir=${redisDbDir} \
301+
${redisExecParam} \
299302
-Djava.io.tmpdir=${fireflyServer}/temp \
300303
-Dalerts.dir=${fireflyServer}/alerts \
301304
-Dserver_config_dir=${serverConfigDir} \

‎src/standalone/assets/stopFireflyServer.sh‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ stopOrphans() {
3333
fi
3434
kill -9 "$pid" 2> /dev/null
3535
done
36-
redisPids=$(pgrep -f "${redisDbDir}-")
36+
redisPids=$(pgrep -f "${redisDbDir}-|${redisMacExecFile}")
3737
for pid in $redisPids; do
38-
zombieRedisPort=$(ps -o args= -p "$pid" 2> /dev/null | grep -oE '[0-9]+$')
38+
# Redis rewrites its process title to "<path> <bind-address>:<port>" followed by padding spaces,
39+
# so take the digits after the last ":" and allow trailing spaces
40+
zombieRedisPort=$(ps -o args= -p "$pid" 2> /dev/null | sed -nE 's/.*:([0-9]+) *$/\1/p')
3941
echo "Stopping orphaned redis-server process at process id $pid on port ${zombieRedisPort:-unknown}"
4042
kill -9 "$pid" 2> /dev/null
4143
done

0 commit comments

Comments
 (0)