sysd_monitor: Add systemd unit and required json

Previous service files for this repo are contained in the corresponding
meta layer. There's a push in OpenBMC though to move these services
files into the repository that owns them. Putting this service in this
repository is the first step in that direction.

Tested:
- Booted Romulus QEMU with required meta changes and verified
application started and logged chassis poweron error.

Change-Id: Iaa0cddff20246b74950e826bdbf34de4cabad8bf
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/Makefile.am b/Makefile.am
index d62c61b..129f5b1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,9 @@
 @CODE_COVERAGE_RULES@
 endif
 
+systemdsystemunit_DATA = \
+  phosphor-systemd-target-monitor.service
+
 AM_LIBS = $(CODE_COVERAGE_LIBS)
 AM_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) -UNDEBUG $(GTEST_CPPFLAGS)
 AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
@@ -96,6 +99,9 @@
 	$(SDEVENTPLUS_LIBS) \
 	-lstdc++fs
 
+install-data-local:
+	mkdir -p ${DESTDIR}/$(sysconfdir)/phosphor-systemd-target-monitor
+	cp $(srcdir)/phosphor-target-monitor-default.json ${DESTDIR}/$(sysconfdir)/phosphor-systemd-target-monitor
 
 check_PROGRAMS =
 XFAIL_TESTS =
diff --git a/configure.ac b/configure.ac
index e6ec283..5a76118 100644
--- a/configure.ac
+++ b/configure.ac
@@ -175,5 +175,20 @@
     [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
 AX_ADD_AM_MACRO_STATIC([])
 
+PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemdsystemunitdir],
+     [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
+     [with_systemdsystemunitdir=auto])
+AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
+     def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
+     AS_IF([test "x$def_systemdsystemunitdir" = "x"],
+   [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
+    [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
+    with_systemdsystemunitdir=no],
+   [with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
+AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
+[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
+
 AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([phosphor-systemd-target-monitor.service])
 AC_OUTPUT
diff --git a/phosphor-systemd-target-monitor.service.in b/phosphor-systemd-target-monitor.service.in
new file mode 100644
index 0000000..ffd980f
--- /dev/null
+++ b/phosphor-systemd-target-monitor.service.in
@@ -0,0 +1,10 @@
+[Unit]
+Description=phosphor systemd target monitor
+After=dbus.service
+
+[Service]
+Restart=always
+ExecStart=/usr/bin/phosphor-systemd-target-monitor -f /etc/phosphor-systemd-target-monitor/phosphor-target-monitor-default.json
+
+[Install]
+WantedBy=multi-user.target