Browse Source

More info added to README.md

Óscar García Amor 4 years ago
parent
commit
fdcc0644cc
3 changed files with 60 additions and 5 deletions
  1. 57 2
      README.md
  2. 1 1
      sysdweb/main.py
  3. 2 2
      sysdweb/server.py

+ 57 - 2
README.md

@@ -27,11 +27,66 @@ Once you have configured sysdweb, simply run.
 sysdweb
 ```
 
-By default sysdweb listen in 10080 port to all hosts, you can change listen
+By default sysdweb listen in 10080 port to 127.0.0.1, you can change listen
 port and address with `-p` and `-l`.
 
 ```sh
-sysdweb -p 9080 -l 127.0.0.1
+sysdweb -p 9080 -l 0.0.0.0
+```
+
+## API
+
+You can control configured services via REST API, for example, with curl.
+
+The API endpoint is `/api/v1/<service>/<action>`, always `GET` and response
+a json with following format.
+
+```json
+{
+  "<action>": "<result>"
+}
+```
+
+The `<service>` tag is defined in config file and match with section label.
+For example, in following config, the service would be `ngx`.
+
+```ini
+[ngx]
+title = Nginx
+unit = nginx.service
+```
+
+The posible `<actions>` are.
+
+* start
+* stop
+* restart
+* reload
+* reloadorrestart
+* status
+
+All actions (except `status`) return as result `OK` if can communicate with
+DBUS or `Fail` if any error occurs.
+
+For `status` action, the posible responses are.
+
+* active (started unit)
+* reloading
+* inactive (stopped unit)
+* failed (stopped unit)
+* activating
+* deactivating
+* not-found (for inexistent unit)
+
+In the example defined above all valid enpoins are.
+
+```
+http://127.0.0.1:10080/api/v1/ngx/start
+http://127.0.0.1:10080/api/v1/ngx/stop
+http://127.0.0.1:10080/api/v1/ngx/restart
+http://127.0.0.1:10080/api/v1/ngx/reload
+http://127.0.0.1:10080/api/v1/ngx/reloadorrestart
+http://127.0.0.1:10080/api/v1/ngx/status
 ```
 
 [1]: https://aur.archlinux.org/packages/sysdweb/

+ 1 - 1
sysdweb/main.py

@@ -12,7 +12,7 @@ import argparse
 
 def main():
     parser = argparse.ArgumentParser()
-    parser.add_argument('-l', '--listen', metavar='host or ip', default='0.0.0.0', help='listen address, default: 0.0.0.0')
+    parser.add_argument('-l', '--listen', metavar='host or ip', default='127.0.0.1', help='listen address, default: 127.0.0.1')
     parser.add_argument('-p', '--port', metavar='port', default='10080', help='listen port, default: 10080')
     args = parser.parse_args()
 

+ 2 - 2
sysdweb/server.py

@@ -63,7 +63,7 @@ def get_main():
         service_status = get_service_action(service, 'status')
         if service_status['status'] == 'not-found':
             cls = 'active'
-        elif service_status['status'] == 'inactive':
+        elif service_status['status'] == 'inactive' or service_status['status'] == 'failed':
             cls = 'danger'
         elif service_status['status'] == 'active':
             cls = 'success'
@@ -71,7 +71,7 @@ def get_main():
             cls = 'warning'
         disabled_start = True if cls == 'active' or cls == 'success' else False
         disabled_stop = True if cls == 'active' or cls == 'danger' else False
-        disabled_restart = True if cls == 'active' else False
+        disabled_restart = True if cls == 'active' or cls == 'danger' else False
         services.append({'class': cls,
             'disabled_start': disabled_start,
             'disabled_stop': disabled_stop,