Closed shirshak55 closed 4 years ago
Hey there! Thanks for trying out Shawl. The issue here is that the default working directory for a Windows service is different than the location of your Express project, so Yarn can't find it. I'll add an option to set the command's working directory for the next release, but in the meantime, you have a couple of options:
shawl add --name express -- yarn --cwd C:/server start
sc start express
More generally, you can have Shawl run a script that switches to the right directory. If your Express project is in C:/server, then make a C:/server/run.cmd with this content:
cd C:/server
yarn start
And then add/start the service with:
shawl add --name express -- C:/server/run.cmd
sc start express
As for making it run on startup, you should just need to set the auto
service type:
sc config express start= auto
@mtkennerly Hai,
Its still not working. yarn --cwd C:/server start works but above command is not working as expected
Where can i find all these services in Windows Service?
upon investigation i see this message
the service process couldn't connect to service controller :(
Did you see that error by directly executing the shawl run
command configured on the service? That would be expected - it only works when invoked by the Windows service manager itself.
You can get to the services list by clicking on the start menu, typing services
, and choosing this result to open the services app:
I have a suspicion about the remaining issue. I just released v0.4.0 with a --cwd
option and better error reporting when it can't start the configured command. Could you give it a try and post your shawl.log (from the same folder as shawl.exe)? I suspect you'll see this:
2019-10-05 05:52:36 [ INFO] Launching command
2019-10-05 05:52:36 [ERROR] Unable to launch command: The system cannot find the file specified. (os error 2)
I've just added a note in the README, but the default service account is Local System, which has a different PATH
environment variable than your user account does. If Yarn and Node are in your user PATH
, but not the Local System PATH
, then it won't be able to find it. To change Local System environment variables:
environment variables
PATH
in the system variables
sectionYou could probably also change the service to run under your user account (services app -> choose a service -> properties
-> log on
).
@mtkennerly nope not working it is saying something like this
Couldnot connect to service or something like that.
I went to services and tried to start manually but there is some error i guess.
Let me provide the details.
@mtkennerly is says error like this
C:\Users\s\Desktop\projects\Monitor\main_process\shawl.exe run --name ticketMasterStarter -- yarn --cwd C:\Users\s\Desktop\projects\Monitor\main_process start
Winapi(
Os {
code: 1063,
kind: Other,
message: "The service process could not connect to the service controlle
r.",
},
)
@shirshak55, there should be a log file at C:\Users\s\Desktop\projects\Monitor\main_process\shawl.log
(same folder as shawl.exe). Could you please post it here? I need to see the full log to investigate this.
For the record, if you try to directly execute shawl run
in a console as it looks like in that last comment, it will fail 100% of the time, since it has to be executed specially by Windows as part of service startup.
@mtkennerly is there anyway I can give yarn executable directly so that if i use with other executables like npm etc i don't need to add to system path?
Like yarn is in C:/Program Files (x86)/Yarn/bin/yarn
@shirshak55 Absolutely, although there's one caveat - see below. This will do exactly what you'd expect, assuming you have a yarn.cmd
file (I installed Yarn with Scoop, so I'm not sure if all copies have it):
shawl add --name express -- "C:/Program Files (x86)/Yarn/bin/yarn.cmd" --cwd "C:/Users/s/Desktop/projects/Monitor/main_process" start
The one caveat is that if yarn start
runs node index.js
, then you may have the same problem with it not finding Node. That's why I think adding it to the system PATH
(and/or changing the service user) is probably easier overall.
@mtkennerly lol it was node. I tried adding yarn to path etc.... all that was due to path problem. I Replaced yarn with node index.js and it started working like crazy haha .
Thanks.
@mtkennerly thanks again. I wished there was some indication like node not found so we can easily check.
I am using it for node JS express server?
I have tried to use it like this
shawl add --name express -- yarn start
But it doesn't seem to start?
And I think to make it run on startup so I think the best way is to move to startup folder which we can access by shell:startup on run?