diff options
-rw-r--r-- | src/muniad.cc | 29 | ||||
-rw-r--r-- | src/ws/node.js | 8 | ||||
-rw-r--r-- | src/ws/view.js | 6 |
3 files changed, 41 insertions, 2 deletions
diff --git a/src/muniad.cc b/src/muniad.cc index 7e260be..e225760 100644 --- a/src/muniad.cc +++ b/src/muniad.cc @@ -32,6 +32,8 @@ #include <string.h> #include <sys/time.h> #include <list> +#include <string> +#include <fstream> #include <libwebsockets.h> @@ -50,6 +52,8 @@ static struct lws_protocols protocols[] = static struct option options[] = { { "help", no_argument, nullptr, 'h' }, + { "background", no_argument, nullptr, 'b' }, + { "pidfile", required_argument, nullptr, 'P' }, { "port", required_argument, nullptr, 'p' }, { "file", required_argument, nullptr, 'f' }, { "ssl", no_argument, nullptr, 's' }, @@ -68,6 +72,8 @@ int main(int argc, char **argv) const char *key_path = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.key.pem"; + std::string pidfile; + bool background{false}; int port = 7681; int use_ssl = 0; struct lws_context *context; @@ -87,7 +93,7 @@ int main(int argc, char **argv) while(n >= 0) { - n = getopt_long(argc, argv, "ci:khsp:f:", options, nullptr); + n = getopt_long(argc, argv, "ci:khsp:f:P:b", options, nullptr); if(n < 0) { continue; @@ -106,6 +112,12 @@ int main(int argc, char **argv) case 'p': port = atoi(optarg); break; + case 'P': + pidfile = optarg; + break; + case 'b': + background = true; + break; case 'f': db_filename = strdup(optarg); break; @@ -115,12 +127,25 @@ int main(int argc, char **argv) interface = interface_name; break; case 'h': - fprintf(stderr, "Usage: muniad [--port=<p>] [--ssl] [--file=<f>]\n"); + fprintf(stderr, "Usage: muniad [--port=<p>] [--ssl] [--file=<f>] [--background] [--pidfile=<f>]\n"); exit(1); } } //_parse("+all"); + if(background) + { + // Fork, chdir to / and redirect stdout and stderr to /dev/null + daemon(0, 0); + // Create a new session, make the current process process group leader. + setsid(); + } + + if(!pidfile.empty()) + { + std::ofstream fs(pidfile); + fs << getpid() << '\n'; + } node_manager.init(db_filename); diff --git a/src/ws/node.js b/src/ws/node.js index fd4a9d7..2f93dac 100644 --- a/src/ws/node.js +++ b/src/ws/node.js @@ -389,6 +389,14 @@ Node.prototype.setAttribute = function(name, value) { this.state_element.style.backgroundColor = "#da4343"; } + else if(value == "preparing") + { + this.state_element.style.backgroundColor = "#f1e0b4"; + } + else if(value == "ready") + { + this.state_element.style.backgroundColor = "#bad0aa"; + } else { this.state_element.style.backgroundColor = "#ebedf0"; diff --git a/src/ws/view.js b/src/ws/view.js index 5b69a24..70d938a 100644 --- a/src/ws/view.js +++ b/src/ws/view.js @@ -424,6 +424,12 @@ function changeState(e) break; default: case "todo": + update(id, "state", "preparing"); + break; + case "preparing": + update(id, "state", "ready"); + break; + case "ready": update(id, "state", "in-progress"); break; } |