Skip to content

Commit

Permalink
Fix unrenamed bits in system units shipped in native packages (#144)
Browse files Browse the repository at this point in the history
This is a bit of a SNAFU, because the service units are broken on fresh
systems, and on systems where EdgeDB 5.x and earlier was installed they
would work, but will initialize the data in the wrong spot
(`/var/lib/edgedb`) and owned by the wrong user (`edgedb`).  This fixes
the units and adds a check that errors out if the wrong data directory
is detected, so people who have successfully installed Gel 6.0/6.1 would
be informed to move and `chown` the data directory when upgrading to 6.2
and later.
  • Loading branch information
elprans authored Feb 28, 2025
1 parent 612069e commit 2d51d10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
8 changes: 4 additions & 4 deletions edgedbpkg/edgedb/IDENTIFIER-SLOT.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

<key>ProgramArguments</key>
<array>
<string>@@{bindir}/edgedb-server</string>
<string>--data-dir=@@{localstatedir}/lib/edgedb/@@{slot}/data/</string>
<string>--runstate-dir=@@{runstatedir}/edgedb/</string>
<string>@@{bindir}/@@{name}</string>
<string>--data-dir=@@{localstatedir}/lib/@@{name_for_user_and_dir}/@@{slot}/data/</string>
<string>--runstate-dir=@@{runstatedir}/@@{name_for_user_and_dir}/</string>
<string>--tls-cert-mode=generate_self_signed</string>
</array>

<key>RunAtLoad</key>
<true/>

<key>UserName</key>
<string>edgedb</string>
<string>@@{name_for_user_and_dir}</string>

<key>KeepAlive</key>
<dict>
Expand Down
11 changes: 6 additions & 5 deletions edgedbpkg/edgedb/IDENTIFIER-SLOT.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ After=network.target
[Service]
Type=notify

User=edgedb
Group=edgedb
User=@@{name_for_user_and_dir}
Group=@@{name_for_user_and_dir}

Environment=EDGEDATA=@@{localstatedir}/lib/edgedb/@@{slot}/data/
RuntimeDirectory=edgedb
Environment=GELDATA=@@{localstatedir}/lib/@@{name_for_user_and_dir}/@@{slot}/data/
RuntimeDirectory=@@{name_for_user_and_dir}

ExecStart=@@{bindir}/edgedb-server --data-dir=${EDGEDATA} --runstate-dir=%t/edgedb --tls-cert-mode=generate_self_signed
ExecStartPre=@@{pre_start_script}
ExecStart=@@{bindir}/@@{name} --data-dir=${GELDATA} --runstate-dir=%t/@@{name_for_user_and_dir} --tls-cert-mode=generate_self_signed
ExecReload=/bin/kill -HUP ${MAINPID}
KillMode=mixed
KillSignal=SIGINT
Expand Down
20 changes: 20 additions & 0 deletions edgedbpkg/edgedb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ def marketing_name(self) -> str:
def marketing_slug(self) -> str:
return "gel"

@property
def name_for_user_and_dir(self) -> str:
return self.marketing_slug

def version_includes_revision(self) -> bool:
return ".s" in self.pretty_version

Expand Down Expand Up @@ -575,6 +579,22 @@ def get_stdlib_install_script(self, build: targets.Build) -> str:
)
return script

def get_pre_start_script(self, build: targets.Build) -> str:
if self.marketing_slug == "gel" and self.slot == "6":
# In pre-6.2 packages we shipped broken service units files
# that contained non-renamed user and data directory.
msg = (
"Obsolete directory structure detected. "
'Please move "/var/lib/edgedb/6/data" to "/var/lib/gel/6/data"'
' and run `chown -R gel:gel "/var/lib/gel/6/data"`'
)
return (
"/bin/sh -c 'if [ -d /var/lib/edgedb/6/data ]; then "
+ f"echo \\'{msg}\\' >&2; exit 1; fi'"
)
else:
return ""

def get_private_libraries(self, build: targets.Build) -> list[str]:
# Automatic dependency introspection points to libpq.so,
# since some Postgres' client binaries require it. We _do_
Expand Down

0 comments on commit 2d51d10

Please sign in to comment.