summaryrefslogtreecommitdiffhomepage
path: root/plugins/fcgi/webapp-runner.cpp
blob: ad8c396461043b1072c1e5f988f00b44e632f45c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "plugins/fcgi/fastcgiprocess.h"

#include <iostream>
#include <string>

namespace {
 void usage()
 {
  std::cout << R"(Usage:
        webapp-runner <host:port> <executable-command>

          or:

        webapp-runner <unix-domain-socket> <executable-command>

Description:

webapp-runner starts the specified executable FastCGI application and connects
it to the specified unix domain socket or local host:port address. Addresses
can be specified in IPv4 or IPv6 format.

Examples:

webapp-runner ::1:6543 ./fcgi1
webapp-runner fcgi-socket0 ./fcgi1
)" << std::endl;
 }
} // namespace

int main(int argc, char* argv[])
{
 try {
  if (argc >= 3) {
   std::string address{argv[1]};
   std::string command{argv[2]};

   if (auto pos{address.find_last_of(':')}; pos != std::string::npos) {
    std::string host{address.substr(0, pos)};
    unsigned short port{static_cast<unsigned short>(std::stoul(address.substr(pos + 1)))};
    run_fcgi_app(command, host, port, argc - 2, &argv[2]);
   } else {
    run_fcgi_app(command, address, argc - 2, &argv[2]);
   }
  } else {
   usage();
   exit(0);
  }
 } catch (const std::exception& ex) {
  std::cout << "webapp-runner caught error: " << ex.what() << std::endl;
 }

 return 0;
}