Hi there! I want to ask you all some questions about how to run nginx application with Habitat CLI for Windows.
I just don't know how to write the plan.sh1 file and run file. If the files look like this,is that right? Also,there is my nginx.conf. And I want to know how to start hab services up, is the "hab svc load/start"? Before this,should i install the core/windows-service? Plzzzzzzz help me!!!!!!!!
Sorry for taking so long to respond. We don’t have any example windows based nginx plans but looking over what you have, your plan.ps1
looks ok. It looks very "bash"ish but should run in powershell. You could completely remove the Invoke-Build
since it just returns 0
.
The run
hook would look something like:
nginx -c {{pkg.path }}\dist\config\nginx.conf
No need for pkgPathFor
since nginx
's bin
dir will be on the path.
I just changed the run file like you said but it didn’t work.This is the nginx.conf and after building I try to use ‘hab load/start svc xlk-test1/hello-test1’ to open my website,but it failed.I also try to install ‘core/windows-service by using’, after ‘hab sup run’ it shows wrong logs.
I think there may be a few things going on here:
-
your plan specifies a
svc_user
namedroot
. That assumes that there is a user namedroot
on the machine which looks like it is missing. For Windows plans, most don’t use thesvc_user
which causes the service to run under the same account as the supervisor. I would start with removing that from your plan. -
If you want to run the supervisor inside of a Windows Service which is the way to go in a production environment, then the service calls
hab sup run
and you control the supervisor by starting and stopping the service. Not sure exactly what is meant byshows wrong logs
but I’s start by not using thewindows-service
and just getting things working in the studio. -
I think I was incorrect in my
nginx
call above that points to{{pkg.path }}\dist\config\nginx.conf
. It should point to{{pkg.path }}\config\nginx.conf
instead.
I noticed that your third point,so I used '{{pkg.path }}\config\nginx.conf' last time.
Now I delete the 'svc_user=root' in plan.sh1 and this time there are no wrong logs but still can't open the website.
Then I try ‘hab sup run’, it shows wrong logs, so I just kill the process which pid=7260, and I try ‘hab sup run’ again and open another cmd.exe to ‘hab svc load/start’. It shows wrongs logs.(the bule part is my Windows administrator identity name)
The error with the pipe removal is actually just noise. We have an open issue to address that but it should not be affecting you here. It looks like your real problems are with the error.log
file and the pid
directive. You probably need to create the logs
directory in an init
hook. Based on your config above it seems like you are terminating pid
with a ;
but you can look at /hab/svc/hello-test1/config/nginx.conf
to see how the template got rendered and ensure it looks right.
Also, hab sup run
usually will not work in a studio because the studio starts with a running supervisor. After loading your service (and there should be no need to call hab svc start
afterwards) you can run Get-SupervisorLog
to view the Supervisor output.
Sorry for take long time to reply you.
As you said,there should be no need to call ‘hab svc start’, but when I call ‘hab svc load’ it shows wrong logs which is:
✗✗✗✗✗✗
✗✗✗✗✗✗ Unable to contact the Supervisor.
✗✗✗✗✗✗
✗✗✗✗✗✗ If the Supervisor you are contacting is local, this probably means it is not running. You can run a Supervisor in the foreground with:
✗✗✗✗✗✗
✗✗✗✗✗✗ hab sup run
✗✗✗✗✗✗
✗✗✗✗✗✗ Or try restarting the Supervisor through your operating system’s init process or Windows service.
and the ‘(os error 10061)’.
And when I call ‘Get-SupervisorLog’, the logs are:
hello-test1.default(E): nginx: [alert] could not open error log file: CreateFile() “logs/error.log” failed (3: The system cannot find the path specified)
hello-test1.default(E): 2019/02/13 19:45:30 [emerg] 7452#3284: directive “pid” is not terminated by “;” in C:\hab\studios\hello-test1\hab\pkgs\xlk-test1\hello-test1\0.1.0\20190213181655\config\nginx.conf:2
hab-launch(SV): Child for service ‘hello-test1.default’ with PID 7908 exited with code exit code: 0
hello-test1.default(SV): Starting service as user=xlk, group=<anonymous>
hello-test1.default(E): nginx: [alert] could not open error log file: CreateFile() “logs/error.log” failed (3: The system cannot find the path specified)
hello-test1.default(E): 2019/02/13 19:45:31 [emerg] 84#6524: directive “pid” is not terminated by “;” in C:\hab\studios\hello-test1\hab\pkgs\xlk-test1\hello-test1\0.1.0\20190213181655\config\nginx.conf:2
hab-launch(SV): Child for service ‘hello-test1.default’ with PID 7612 exited with code exit code: 0
hello-test1.default(SV): Starting service as user=xlk, group=<anonymous>
hello-test1.default(E): nginx: [alert] could not open error log file: CreateFile() “logs/error.log” failed (3: The system cannot find the path specified)
hello-test1.default(E): 2019/02/13 19:45:32 [emerg] 7640#3624: directive “pid” is not terminated by “;” in C:\hab\studios\hello-test1\hab\pkgs\xlk-test1\hello-test1\0.1.0\20190213181655\config\nginx.conf:2
hab-launch(SV): Child for service ‘hello-test1.default’ with PID 3208 exited with code exit code: 0.
It seems still the error.log directory problem. Could you plz tell me how to create the error.log directory in the init hook.
So happy to tell you that I have solved my problem.
I just changed the run hook:
Your suggestion is very helpful to me. Thank you very much!!
So glad you got this working!!