R
Railwayā€¢8mo ago
GetPsyched

sveltekit service crashing :(

I just deployed my brand new project on Railway and it tried running the bun run start command repeatedly which kept failing with the following error:
TERM environment variable not set.
error: script "start" exited with code 1 (SIGHUP)
TERM environment variable not set.
error: script "start" exited with code 1 (SIGHUP)
The service inevitably crashed.
121 Replies
Percy
Percyā€¢8mo ago
Project ID: 12b919b0-8ae8-4936-a695-591b96aa0d64
GetPsyched
GetPsychedā€¢8mo ago
Perhaps this is because I don't have any adapter setup?
Brody
Brodyā€¢8mo ago
definitely is, you would want to use the node adapter and hope it's compatible with bun, if it's not then you have to use nodejs
GetPsyched
GetPsychedā€¢8mo ago
Switching to nodejs shouldn't be a problem Will try adding the node adapter Tried adding the node adapter. The issue persists. I doubt this is because of bun since it works on my local machine cc @Brody
Brody
Brodyā€¢8mo ago
term environment variable not set issue still?
GetPsyched
GetPsychedā€¢8mo ago
yes the logs look identical to before adding the adapter
Brody
Brodyā€¢8mo ago
what is your start script
GetPsyched
GetPsychedā€¢8mo ago
the default? I didn't alter anything on Railway
Brody
Brodyā€¢8mo ago
what is it
GetPsyched
GetPsychedā€¢8mo ago
checking
GetPsyched
GetPsychedā€¢8mo ago
nothing?
No description
Brody
Brodyā€¢8mo ago
not quite what I asked the start script.. in the package.json
GetPsyched
GetPsychedā€¢8mo ago
Ah! bun run css && vite build && clear && vite preview css being: bunx tailwindcss -i ./src/app.css -o ./dist/tailwind.css
Brody
Brodyā€¢8mo ago
that's not a start script or at least it shouldn't be yours
GetPsyched
GetPsychedā€¢8mo ago
"scripts": {
"css": "bunx tailwindcss -i ./src/app.css -o ./dist/tailwind.css",
"dev": "bun run css && vite dev",
"build": "bun run css && vite build",
"preview": "bun run css && vite preview",
"start": "bun run css && vite build && clear && vite preview"
},
"scripts": {
"css": "bunx tailwindcss -i ./src/app.css -o ./dist/tailwind.css",
"dev": "bun run css && vite dev",
"build": "bun run css && vite build",
"preview": "bun run css && vite preview",
"start": "bun run css && vite build && clear && vite preview"
},
what should it be then
Brody
Brodyā€¢8mo ago
just start the node server
GetPsyched
GetPsychedā€¢8mo ago
so bun run css && vite build && node build? ref: https://kit.svelte.dev/docs/adapter-node
Brody
Brodyā€¢8mo ago
haha I've seen the node adapter docs, have you lol
GetPsyched
GetPsychedā€¢8mo ago
:(
Brody
Brodyā€¢8mo ago
you already run css and build in your build script, why are you running them again?
GetPsyched
GetPsychedā€¢8mo ago
right so bun run build && node build
Brody
Brodyā€¢8mo ago
you already run build in your build script, why are you running it again?
GetPsyched
GetPsychedā€¢8mo ago
OH oh yeah lol it's 2 am here sorry
Brody
Brodyā€¢8mo ago
and while node build might work, you should be more explicit and specify the full path to the JavaScript file that you want to run
GetPsyched
GetPsychedā€¢8mo ago
I don't have any specific JS file to run?
Brody
Brodyā€¢8mo ago
yes you do
GetPsyched
GetPsychedā€¢8mo ago
I simply have these
No description
Brody
Brodyā€¢8mo ago
vite build makes one with the node adapter
GetPsyched
GetPsychedā€¢8mo ago
ah, build/index.js
Brody
Brodyā€¢8mo ago
have a read šŸ˜‰ node build/index.js would use node to run the server, I thought you wanted to use bun?
GetPsyched
GetPsychedā€¢8mo ago
And you'd be right. I'm looking for a bun equivalent rn lol But yeah a more critical error would be: Error: Prince#execute: cannot resolve binary "prince" to a filesystem path šŸ˜” headed to prince docs or wait is there a way to install prince to the project env in Railway? like I did with SQLC back then some TOML file
Brody
Brodyā€¢8mo ago
well what is prince
GetPsyched
GetPsychedā€¢8mo ago
it is a tool that compiles HTML -> PDF among some other things I've defined it in my flake.nix, but Railway doesn't refer that šŸ˜” PrinceXML to be precise
Brody
Brodyā€¢8mo ago
is it available as a nix package or an apt package?
GetPsyched
GetPsychedā€¢8mo ago
nix package likely both oh wait it isn't available as a nix package I wrote my own package for it it's in the same project folder, is it possible for Railway to refer to that rather than nixpkgs?
Brody
Brodyā€¢8mo ago
is it an overlay?
GetPsyched
GetPsychedā€¢8mo ago
no, I just wrote my own package for it very tiny script:
{ autoPatchelfHook, fetchurl, fontconfig, glibc, stdenv }:

stdenv.mkDerivation rec {
pname = "princexml";
version = "15.1";
src = fetchurl {
url = "https://www.princexml.com/download/prince-${version}-linux-generic-x86_64.tar.gz";
hash = "sha256-rm0GeKPa8iDXBhW52GNcja09Qb+aYUtvFaxZUFHEOTw=";
};

nativeBuildInputs = [ autoPatchelfHook ];

buildInputs = [
fontconfig
glibc
];

installPhase = ''
./install.sh $out
ln -sf /var/lib/prince/license.dat $out/lib/prince/license/license.dat
'';
}
{ autoPatchelfHook, fetchurl, fontconfig, glibc, stdenv }:

stdenv.mkDerivation rec {
pname = "princexml";
version = "15.1";
src = fetchurl {
url = "https://www.princexml.com/download/prince-${version}-linux-generic-x86_64.tar.gz";
hash = "sha256-rm0GeKPa8iDXBhW52GNcja09Qb+aYUtvFaxZUFHEOTw=";
};

nativeBuildInputs = [ autoPatchelfHook ];

buildInputs = [
fontconfig
glibc
];

installPhase = ''
./install.sh $out
ln -sf /var/lib/prince/license.dat $out/lib/prince/license/license.dat
'';
}
GetPsyched
GetPsychedā€¢8mo ago
it is available on Ubuntu. I'm guessing that means it's on apt, by extension?
No description
Brody
Brodyā€¢8mo ago
what's it named
GetPsyched
GetPsychedā€¢8mo ago
checking should be princexml
GetPsyched
GetPsychedā€¢8mo ago
yeah I can't find it either
Brody
Brodyā€¢8mo ago
looks like you will have to install install prince the same sort of way i install caddy here https://github.com/brody192/vite-react-template/blob/main/nixpacks.toml
GetPsyched
GetPsychedā€¢8mo ago
On that note did the team say anything about flake support? would fix all my dependency issues
Brody
Brodyā€¢8mo ago
they want to support it natively, its just a low priority because few people use it
GetPsyched
GetPsychedā€¢8mo ago
:( I see Makes perfect sense from a business POV but still a bummer lol
Brody
Brodyā€¢8mo ago
but if you can write nix packages, writing a nixpacks.toml file would be no issue
GetPsyched
GetPsychedā€¢8mo ago
It's about understanding how the toml works either way, this script is extremely tiny, so you're right, it should be relatively simple
Brody
Brodyā€¢8mo ago
if you can understand how nix packages work, you can understand nixpacks.toml
GetPsyched
GetPsychedā€¢8mo ago
yes BTW, can I not use bun run preview as my start script? it expanding to bun run css && vite preview
Brody
Brodyā€¢8mo ago
that starts a dev server
GetPsyched
GetPsychedā€¢8mo ago
rip
Brody
Brodyā€¢8mo ago
use bun to run the index.js file
GetPsyched
GetPsychedā€¢8mo ago
because apparently there's a lot of pain happening
No description
GetPsyched
GetPsychedā€¢8mo ago
I will just switch to nodejs
Brody
Brodyā€¢8mo ago
its for the better
GetPsyched
GetPsychedā€¢8mo ago
indeed invalid use of variables? ERROR: failed to solve: process "/bin/bash -ol pipefail -c tar -zxvf ${pname}.tar.gz ${pname}" did not complete successfully: exit code: 2
Brody
Brodyā€¢8mo ago
lets see the nixpacks.toml file
GetPsyched
GetPsychedā€¢8mo ago
it likely won't work as it's the first draft just wanted to see what breaks huh I didn't delete it
Brody
Brodyā€¢8mo ago
you edited it
GetPsyched
GetPsychedā€¢8mo ago
# https://nixpacks.com/docs/configuration/file

[variables]
pname = 'princexml'
version = '15.1'

[phases.setup]
nixPkgs = ['...', 'corefonts', 'fontconfig', 'glibc']

[phases.princexml]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
cmds = [
'curl -fsSLo ${pname}.tar.gz "https://www.princexml.com/download/prince-${version}-linux-generic-x86_64.tar.gz"',
'tar -zxvf ${pname}.tar.gz ${pname}',
'chmod +x ${pname}'
]

[start]
runImage = 'ubuntu:20.04'
cmd = './${pname} 2>&1'
# https://nixpacks.com/docs/configuration/file

[variables]
pname = 'princexml'
version = '15.1'

[phases.setup]
nixPkgs = ['...', 'corefonts', 'fontconfig', 'glibc']

[phases.princexml]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
cmds = [
'curl -fsSLo ${pname}.tar.gz "https://www.princexml.com/download/prince-${version}-linux-generic-x86_64.tar.gz"',
'tar -zxvf ${pname}.tar.gz ${pname}',
'chmod +x ${pname}'
]

[start]
runImage = 'ubuntu:20.04'
cmd = './${pname} 2>&1'
I don't see it on my screen do you
Brody
Brodyā€¢8mo ago
you just sent it again, so yes
GetPsyched
GetPsychedā€¢8mo ago
No description
GetPsyched
GetPsychedā€¢8mo ago
weird.
Brody
Brodyā€¢8mo ago
full logs please also whats with the runimage and cmd?
GetPsyched
GetPsychedā€¢8mo ago
Oh, there is no princexml subfolder in the tar.gz unsure. It's residue from caddy :P
Brody
Brodyā€¢8mo ago
delete the start phase also in your princexml phase you may want to copy the resulting binary file into maybe /bin or /usr/bin since your code prob expects it in path?
GetPsyched
GetPsychedā€¢8mo ago
yeah so there is ...tar.gz/foo/install.sh that I want to run (it does the binary stuff) where do I put it? [phases.install]?
Brody
Brodyā€¢8mo ago
run it in the same phase
GetPsyched
GetPsychedā€¢8mo ago
Okay, and the path would just be /bin?
Brody
Brodyā€¢8mo ago
no, the PATH would be a bunch of different locations https://utilities.up.railway.app/env-vars?prefix=PATH
GetPsyched
GetPsychedā€¢8mo ago
not the PATH for prince the PATH for the binary file wait that's the same thing ah so how do I refer to this env? or do I have to copy paste/
Brody
Brodyā€¢8mo ago
you dont need to, its just an example?
GetPsyched
GetPsychedā€¢8mo ago
I see
GetPsyched
GetPsychedā€¢8mo ago
weird.
No description
GetPsyched
GetPsychedā€¢8mo ago
idt it threw a 404 before I copy pasted that URL, replacing ${version} and it works no problem wonder why Railway throws a 404 probably a substitution error Oh I can't reference variables in other variables?
[variables]
pname = 'princexml'
version = '15.1'
full_name = 'prince-${version}-linux-generic-x86_64'
[variables]
pname = 'princexml'
version = '15.1'
full_name = 'prince-${version}-linux-generic-x86_64'
I had done this
Brody
Brodyā€¢8mo ago
no you cant
GetPsyched
GetPsychedā€¢8mo ago
yeah realised now hmm so the build works but this error came back If the build failed, then I likely need to tell the lib where the binary is where is it? šŸ’€
Brody
Brodyā€¢8mo ago
did you put the binary in /bin ?
GetPsyched
GetPsychedā€¢8mo ago
updated toml:
# https://nixpacks.com/docs/configuration/file

[variables]
pname = 'princexml'
full_name = 'prince-15.1-linux-generic-x86_64'

[phases.setup]
nixPkgs = ['...', 'corefonts', 'fontconfig', 'glibc']

[phases.princexml]
dependsOn = ['setup']
cmds = [
'curl -fsSLo ${pname}.tar.gz "https://www.princexml.com/download/${full_name}.tar.gz"',
'tar -zxvf ${pname}.tar.gz ${full_name}',
'chmod +x ${full_name}/install.sh',
'./${full_name}/install.sh /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
]
# https://nixpacks.com/docs/configuration/file

[variables]
pname = 'princexml'
full_name = 'prince-15.1-linux-generic-x86_64'

[phases.setup]
nixPkgs = ['...', 'corefonts', 'fontconfig', 'glibc']

[phases.princexml]
dependsOn = ['setup']
cmds = [
'curl -fsSLo ${pname}.tar.gz "https://www.princexml.com/download/${full_name}.tar.gz"',
'tar -zxvf ${pname}.tar.gz ${full_name}',
'chmod +x ${full_name}/install.sh',
'./${full_name}/install.sh /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
]
Brody
Brodyā€¢8mo ago
bruh /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin?????
GetPsyched
GetPsychedā€¢8mo ago
hehe it can choose
Brody
Brodyā€¢8mo ago
not how it works
GetPsyched
GetPsychedā€¢8mo ago
that's valid bash, though okay okay, so I do this? './${full_name}/install.sh /bin'
Brody
Brodyā€¢8mo ago
does it even need a path
GetPsyched
GetPsychedā€¢8mo ago
yes
Brody
Brodyā€¢8mo ago
it can decide itself
GetPsyched
GetPsychedā€¢8mo ago
base=$( dirname "$0" )

cd "$base" || exit 1
base=$( dirname "$0" )

cd "$base" || exit 1
this is a line inside install.sh
Brody
Brodyā€¢8mo ago
Press Enter to accept the default directory or enter an alternative
GetPsyched
GetPsychedā€¢8mo ago
wait then what is this
Brody
Brodyā€¢8mo ago
current dir
GetPsyched
GetPsychedā€¢8mo ago
I see
Brody
Brodyā€¢8mo ago
did you write this?
GetPsyched
GetPsychedā€¢8mo ago
yes a long while back
Brody
Brodyā€¢8mo ago
who wrote this then
GetPsyched
GetPsychedā€¢8mo ago
also me
Brody
Brodyā€¢8mo ago
šŸ¤Ø
GetPsyched
GetPsychedā€¢8mo ago
what are you raising brows for It's 3 AM, I'm not usually this stupid okay now I didn't pass a path what's the "default" since I need to tell that to my application it still doesn't find the binary at whatever the default is
Brody
Brodyā€¢8mo ago
looks like /usr/local/bin and that should be in PATH
GetPsyched
GetPsychedā€¢8mo ago
there is an option in node-prince (the npm lib) for setting the binary but that might break local builds unless I remove it locally and keep it in prod
Brody
Brodyā€¢8mo ago
do you see the Installation complete. message in your build logs
GetPsyched
GetPsychedā€¢8mo ago
yes
No description
GetPsyched
GetPsychedā€¢8mo ago
so it is in /usr/local thonk the prefix so /usr/local/bin hmm
Brody
Brodyā€¢8mo ago
should be and that also should be in PATH, so the npm package should look in PATH automatically
GetPsyched
GetPsychedā€¢8mo ago
here's what the docs for the package say:
Prince#binary(binary): Prince: set the path to the prince(1) binary. By default it is prince (in case PrinceXML was found globally installed at the Node API installation time) or the path to the prince binary of the locally installed PrinceXML distribution (in case PrinceXML was not found globally installed at the Node API installation time). This returns the Prince API for further method chaining.
Prince#binary(binary): Prince: set the path to the prince(1) binary. By default it is prince (in case PrinceXML was found globally installed at the Node API installation time) or the path to the prince binary of the locally installed PrinceXML distribution (in case PrinceXML was not found globally installed at the Node API installation time). This returns the Prince API for further method chaining.
there is also:
Prince#prefix(prefix): Prince: set the path to the PrinceXML installation. This by default is either empty (in case PrinceXML was found globally installed at the Node API installation time) or the path to the locally installed PrinceXML distribution (in case PrinceXML was not found globally installed at the Node API installation time). This returns the Prince API for further method chaining.
Prince#prefix(prefix): Prince: set the path to the PrinceXML installation. This by default is either empty (in case PrinceXML was found globally installed at the Node API installation time) or the path to the locally installed PrinceXML distribution (in case PrinceXML was not found globally installed at the Node API installation time). This returns the Prince API for further method chaining.
ref: https://www.npmjs.com/package/prince
Brody
Brodyā€¢8mo ago
it can download prince for you? why havent you used that?
GetPsyched
GetPsychedā€¢8mo ago
there is nothing to use? it doesn't specify anything I'm supposed to do to install prince automatically
Brody
Brodyā€¢8mo ago
read their docs?
GetPsyched
GetPsychedā€¢8mo ago
they don't have docs IIRC
Brody
Brodyā€¢8mo ago
read the source code?
GetPsyched
GetPsychedā€¢8mo ago
this readme is all they have lol ok Should be this https://github.com/rse/node-prince/blob/master/prince-npm.js#L292-L300
Brody
Brodyā€¢8mo ago
but how do you run the download
GetPsyched
GetPsychedā€¢8mo ago
as it says here:
in case PrinceXML was not found globally installed at the Node API installation time
so likely the download is automatically done at "Node API installation time"? I found nothing regarding this in my build logs
Brody
Brodyā€¢8mo ago
so then are you trying to overwrite the location in your code?
GetPsyched
GetPsychedā€¢8mo ago
yes, to wherever it was installed using ./install.sh
Brody
Brodyā€¢8mo ago
the package should find it automatically since it installs it into a folder in PATH
GetPsyched
GetPsychedā€¢8mo ago
but it doesn't (ā•ÆĀ°ā–”Ā°)ā•Æļøµ ā”»ā”ā”»
Brody
Brodyā€¢8mo ago
sounds like something is misconfigured
Brody
Brodyā€¢8mo ago
then specify /bin as the install path
GetPsyched
GetPsychedā€¢8mo ago
why so? I wasn't asking why should I specify /bin in the install path I was asking why /bin specifically This is an issue upstream. It can't detect NixOS as a Linux distribution Being punished for being curious oof