Start a program upon nginx initialization?

Applications, development tools, FPGA, C, WEB
Post Reply
erikgroving
Posts: 13
Joined: Tue May 26, 2015 9:10 pm

Start a program upon nginx initialization?

Post by erikgroving » Wed Nov 11, 2015 5:42 pm

When nginx loads up, is it possible to initialize the pitaya to already be running an app and then consistently run the app? I'm not sure if this requires an http connection or if there's some kind of initialization in the nginx code. I've perused the code and found the code where apps are started, but do not know where or how it is called. The controller code seems to be started by a function called rp_bazaar_start in the rp_bazaar_cmd.h/c files. However, grepping the entire Bazaar (nginx) directory yields no results on where or when this is ever called.

*edit* So this is called by the javascript in the index.html, with the start_app_url it seems. Going to keep looking in to see if I can figure this out.
**edit** The program can run without a tab on closing and typing http://*red_pitaya_ip*/bazaar?start=*app name* into the browser, this calls the rp_bazaar_start function.
***edit*** FIGURED OUT: I removed the startApp and stopApp portions in the javascript of the index.html for the app. In the rcS file, I added a small c program that cURLS the start function to the home ip (127.0.0.1) on bootup (I had already previously cross-compiled libcurl for the red pitaya, if anyone wants help with that, I wrote a script to do that). Now the application is always running, never closes regardless of the tabs, which is what I need for my long-term stability applications. Yay.

I need the application started on bootup, and if the user opens the browser to the application, and then closes the application, I don't want the nginx server to stop running the application on the pitaya.

I've read up a bit on nginx, I'm not sure if there's something I can modify to the configuration file, and then save myself the time from having to rebuild the nginx server, but I could absolutely use some help. If anyone fairly literate and familiar with web servers / nginx could help me, I'd greatly appreciate it.

Also as a side note, I do want to maintain the web interface, thus porting to a command line application is not something I want to do. Although, if I could initialize an http connection in the rcS script to initialize an app, that is something I'd be willing to try, though I'm not sure how to keep connection running after.

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Start a program upon nginx initialization?

Post by Nils Roos » Wed Nov 11, 2015 11:19 pm

You beat me to explaining it^^

If you want to know the whole story, when you request a resource (eg. "/bazaar") from nginx, it looks into its configuration - /opt/redpitaya/www/conf/nginx.conf on the RP, patches/nginx.conf in the repo - and finds that /bazaar is to be handled by the command "rp_module_cmd". This is declared in ngx_http_rp_module.c to be provided by the function ngx_http_rp_bazaar_cmd(). From there, rp_bazaar_cmd_handler() is called to execute the command given in the url-parameters (eg. "?start=scope").

erikgroving
Posts: 13
Joined: Tue May 26, 2015 9:10 pm

Re: Start a program upon nginx initialization?

Post by erikgroving » Thu Nov 12, 2015 12:13 am

Thanks a lot for explaining it further, the actual nitty-gritty how the interaction was working was escaping me. Your explanation helped me to understand the .conf file a little better, as well as the http handler. I wasn't sure too much of what was happening on the nginx end and was able to do it without touching any of it and just connecting what I saw in the nginx extension modules to what I had seen in the index.html!
:D

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 90 guests