Fix systemd launch of timesheetsdb

- Add default environment file with postgres config
- Add full path to npm (makes ubuntu happy)
- Call handlers appropriately when systemd unit files are modified
- Add very basic test

Change-Id: I5b1dfab78e449492be193bccfe470813f3028195
diff --git a/defaults/main.yml b/defaults/main.yml
index 324e1bd..d643fe3 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -21,5 +21,6 @@
 
 # postgres db settings
 timesheets_pg_db: "timesheets"
+timesheets_pg_db_port: 5432
 timesheets_pg_db_username: "timesheets_db_user"
 timesheets_pg_db_password: "timesheets_db_pass"
diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml
index 85a5b1f..fcced9b 100644
--- a/molecule/default/verify.yml
+++ b/molecule/default/verify.yml
@@ -7,6 +7,13 @@
 - name: Verify
   hosts: all
   tasks:
-  - name: example assertion
-    assert:
-      that: true
+
+    - name: Obtain the root webpage, check that it's from timesheetsui
+      uri:
+        url: http://127.0.0.1/
+        headers:
+          Host: "timesheets.example.com"
+        status_code: 200
+        return_content: true
+      register: timesheet_root_page
+      failed_when: "'Timesheetsui' not in timesheet_root_page.content"
diff --git a/tasks/Debian.yml b/tasks/Debian.yml
index f3563ea..95366c6 100644
--- a/tasks/Debian.yml
+++ b/tasks/Debian.yml
@@ -13,6 +13,15 @@
     update_cache: true
     cache_valid_time: 3600
 
+- name: Create environment config for timesheetsdb service
+  template:
+    src: "default.timesheetsdb.j2"
+    dest: "/etc/default/timesheetsdb"
+    owner: "root"
+    group: "root"
+    mode: "0640"
+  notify:
+    - restart-timesheetsdb
 
 - name: Create systemd service unit files for timesheetsdb service
   template:
@@ -23,3 +32,6 @@
     mode: "0644"
   with_items:
     - "timesheetsdb.service"
+  notify:
+    - start-timesheetsdb
+    - restart-timesheetsdb
diff --git a/tasks/main.yml b/tasks/main.yml
index 597d5f3..fc4d7ca 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -40,14 +40,6 @@
     repo: "{{ timesheetsdb_repo }}"
     dest: "{{ timesheets_dir }}/db"
     version: "{{ timesheetsdb_version }}"
-
-- name: Create timesheetsdb configuration file
-  template:
-    src: "timesheetsdb_config.json.j2"
-    dest: "{{ timesheets_dir }}/db/timesheetsdb_config.json"
-    owner: "root"
-    group: "{{ timesheets_groupname }}"
-    mode: "0640"
   notify:
     - "restart-timesheetsdb"
 
@@ -59,7 +51,7 @@
     cmd: "npm install"
     creates: "{{ timesheets_dir }}/db/node_modules"
   notify:
-    - "start-timesheetsdb"
+    - "restart-timesheetsdb"
 
 - name: Build timesheetsdb
   become: true
@@ -69,7 +61,7 @@
     cmd: "npm run build"
     creates: "{{ timesheets_dir }}/db/dist"
   notify:
-    - "start-timesheetsdb"
+    - "restart-timesheetsdb"
 
 - name: Create directory for timesheetsui
   file:
diff --git a/templates/default.timesheetsdb.j2 b/templates/default.timesheetsdb.j2
new file mode 100644
index 0000000..749062c
--- /dev/null
+++ b/templates/default.timesheetsdb.j2
@@ -0,0 +1,10 @@
+{#
+SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+SPDX-License-Identifier: Apache-2.0
+#}
+# /etc/default/timesheetsdb
+# {{ ansible_managed }}
+DATABASE_NAME = {{ timesheets_pg_db }}
+DATABASE_PORT = {{ timesheets_pg_db_port }}
+DATABASE_USER = {{ timesheets_pg_db_username }}
+DATABASE_PASS = {{ timesheets_pg_db_password }}
diff --git a/templates/timesheetsdb.service.j2 b/templates/timesheetsdb.service.j2
index 3715246..0a35716 100644
--- a/templates/timesheetsdb.service.j2
+++ b/templates/timesheetsdb.service.j2
@@ -2,21 +2,23 @@
 SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
 SPDX-License-Identifier: Apache-2.0
 #}
+# /etc/systemd/system/timesheetsdb
+# {{ ansible_managed }}
 [Unit]
 Description=Timesheets DB Service
 Documentation=https://github.com/opennetworkinglab/timesheetsdb
 After=network-online.target
 Wants=network-online.target
 
-
 [Service]
 Type=simple
 
 User={{ timesheets_username }}
 Group={{ timesheets_groupname }}
-WorkingDirectory={{ timesheets_dir }}/db
 
-ExecStart=npm run start:prod
+EnvironmentFile=/etc/default/timesheetsdb
+WorkingDirectory={{ timesheets_dir }}/db
+ExecStart=/usr/bin/npm run start:prod
 
 Restart=on-failure
 RestartSec=30
diff --git a/templates/timesheetsdb_config.json.j2 b/templates/timesheetsdb_config.json.j2
deleted file mode 100644
index 43ebfab..0000000
--- a/templates/timesheetsdb_config.json.j2
+++ /dev/null
@@ -1,5 +0,0 @@
-{#
-SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
-SPDX-License-Identifier: Apache-2.0
-#}
-{}