feat: add lockfile
Some checks failed
perso/opencode/pipeline/head Something is wrong with the build of this commit
Some checks failed
perso/opencode/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
@@ -6,9 +6,8 @@ RUN apt-get update && apt-get upgrade -y && \
|
|||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
userdel -r node; \
|
userdel -r node; \
|
||||||
groupadd -g 1000 opencode; \
|
groupadd -g 1000 opencode; \
|
||||||
useradd -m -u 1000 -g 1000 opencode
|
useradd -m -u 1000 -g 1000 -s /usr/bin/bash opencode && \
|
||||||
|
npm update -g && \
|
||||||
RUN npm update -g && \
|
|
||||||
npm install -g opencode-ai n2-soul@9.0.8 && \
|
npm install -g opencode-ai n2-soul@9.0.8 && \
|
||||||
npm cache clean --force
|
npm cache clean --force
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,48 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
LOCKFILE="${OPENCODE_ATTACH_LOCK:-/tmp/opencode-attach.lock}"
|
||||||
|
|
||||||
: "${OPENCODE_SERVER_PASSWORD:?OPENCODE_SERVER_PASSWORD is required}"
|
: "${OPENCODE_SERVER_PASSWORD:?OPENCODE_SERVER_PASSWORD is required}"
|
||||||
: "${OPENCODE_API_URL:?OPENCODE_API_URL is required}"
|
: "${OPENCODE_API_URL:?OPENCODE_API_URL is required}"
|
||||||
|
|
||||||
|
cleanup_lock() {
|
||||||
|
if [ -f "$LOCKFILE" ]; then
|
||||||
|
existing_pid=$(cat "$LOCKFILE" 2>/dev/null || true)
|
||||||
|
[ "$existing_pid" = "$$" ] && rm -f "$LOCKFILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
kill_existing_instance() {
|
||||||
|
if [ ! -f "$LOCKFILE" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
existing_pid=$(cat "$LOCKFILE" 2>/dev/null || true)
|
||||||
|
if [ -z "$existing_pid" ] || [ "$existing_pid" = "$$" ]; then
|
||||||
|
rm -f "$LOCKFILE"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if kill -0 "$existing_pid" 2>/dev/null; then
|
||||||
|
kill "$existing_pid" 2>/dev/null
|
||||||
|
for _ in 1 2 3 4 5; do
|
||||||
|
if ! kill -0 "$existing_pid" 2>/dev/null; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if kill -0 "$existing_pid" 2>/dev/null; then
|
||||||
|
kill -9 "$existing_pid" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$LOCKFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup_lock INT TERM EXIT
|
||||||
|
|
||||||
|
kill_existing_instance
|
||||||
|
printf '%s\n' "$$" > "$LOCKFILE"
|
||||||
|
|
||||||
exec opencode attach -p "${OPENCODE_SERVER_PASSWORD}" "${OPENCODE_API_URL}" "$@"
|
exec opencode attach -p "${OPENCODE_SERVER_PASSWORD}" "${OPENCODE_API_URL}" "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user