Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a service for package.json scripts #12

Open
Vap0r1ze opened this issue Oct 26, 2023 · 3 comments
Open

Creating a service for package.json scripts #12

Vap0r1ze opened this issue Oct 26, 2023 · 3 comments

Comments

@Vap0r1ze
Copy link

Vap0r1ze commented Oct 26, 2023

My "start" script is tsx src/index.ts so I tried the following:

# ser create --name jewel --start --enable --interpreter $(which pnpm) start
# ser create --name jewel --start --enable --interpreter $PWD/node_modules/.bin/tsx src/index.ts

The first was me hoping it didnt check if the file was real, but it does so that "hack" didnt work.
The second didn't work because tsx's hashbang gets node from the env, which doesn't exist til ~/.bashrc is ran.

I suggest there should be a builtin way to do package.json scripts as services, or the even more abstractly any command.
Until then my workaround is to make an executable: printf '#!'$(which bash)'\npnpm start\n' this did not work either lol

@secretshardul
Copy link
Contributor

secretshardul commented Nov 11, 2023

The idea behind servicer was to run services in production environment. Is there a reason behind why you cannot build index.ts and then run it with node?

I think --interpreter $PWD/node_modules/.bin/tsx won't work because tsx is a JS file and not a binary file. It needs to be called using node, so the interpreter should be node. Also the create command is not designed for compound commands. It handles simple commands of format INTERPRETER FILE_PATH, not INTERPRETER tsx FILE_PATH.

Your bet would be to use ser edit and write a custom .service file. Have you figured out a way to call tsx using its absolute path?

Edit: tsx binary is indeed located in node_modules/.bin/tsx.

@secretshardul
Copy link
Contributor

ser create --name jewel --start --enable --interpreter $PWD/node_modules/.bin/tsx src/index.ts worked for me.

The second didn't work because tsx's hashbang gets node from the env, which doesn't exist til ~/.bashrc is ran.

As mentioned in the docs node must be available to the root user without ~/.bashrc. Try adding a symlink in /usr/local/bin and then run the script

sudo ln -s $(which node) "/usr/local/bin/node"

Lmk if this works

@Vap0r1ze
Copy link
Author

I use tsx because it's a very simple build system and works very cleanly with how I use the node:child_process module
That workaround probably will work but I'd rather not do that so that I dont have to update it when I upgrade my node version

I may just switch to including the build step in my production update flow (before doing git pull) so that I can use servicer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants