JFLarvoire / SysToolsLib

A library of Windows and Linux system management tools
Apache License 2.0
314 stars 93 forks source link

PSService - Service stuck at starting #27

Closed a-dimas closed 3 years ago

a-dimas commented 3 years ago

hi JF! first of all - great program!! one of the best contributions I ever found.

I have been trying to accomplish something for a while now using your program and reached a new stage of closeness to completion - I think I need a hand now. What I need the service to do is, from a domain-joined server, connect to (map as drive) a non-domain file share (with user and pass), and then start an app. What I had before: either the service started correctly, or the goal (connect the share and start the app) was met. I need both because this will go into prod once working. A bit more explained: If I added a line stop-process -force -id $pid for the service to kill itself, the share would be connected and the app started, but the SCM console would shout: "service failed to start". If I commented out that line, then the service would run ok, but the connection to the file share would not be established and the webapp would start and show that error message: "could not reach the file share".

Thinking about what happened there I introduced a change: the actual work (connecting to the file share and starting the app) which was part of the service is now a different program, and what the service does is only run it: start-process -filepath powershell.exe -argumentlist "-file D:\Atlassian\JIRA\bin\start-jira.ps1"

At first I thought this was actually working, because the SCM console did not complain and the app was started OK with the connection to the file share. However, the service stays at "Starting" forever.

I will try the solution in this link, basically wrap it all in a method and make the service start a new thread calling that method. However, do you have any ideas, have you had to do something similar?

Thanks, cheers!!

Dimas

a-dimas commented 3 years ago

Hi again! The link I pasted solved my issue - closing this now, I hope it'll be useful for someone else. FYI it created more PS instances in the host running it.