monitor: Add service files to repo

This commit adds the fan monitor service files to the repo.

In YAML mode, the fan monitor init service and the fan monitor service
that starts at the fan control ready target will be installed.  In JSON
mode, just one service file will be installed, which will start at the
multi-user target.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ie1cebcbf8c138cb3b0ac44dd2eeb54458c7f68b5
diff --git a/configure.ac b/configure.ac
index ff87337..d330f54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -215,6 +215,7 @@
         # Set config flag for runtime json usage
         AC_DEFINE([MONITOR_USE_JSON], [1], [Fan monitor use runtime json configuration])
         AC_MSG_NOTICE([Fan monitor json configuration usage enabled])
+        AC_CONFIG_FILES([monitor/service_files/json/phosphor-fan-monitor@.service])
     ],
     [
         AC_ARG_VAR(FAN_MONITOR_YAML_FILE,
@@ -227,6 +228,9 @@
         AC_SUBST([GEN_FAN_MONITOR_DEFS],
                  ["$PYTHON \${top_srcdir}/monitor/gen-fan-monitor-defs.py \
                   -m $FAN_MONITOR_YAML_FILE"])
+
+        AC_CONFIG_FILES([monitor/service_files/yaml/phosphor-fan-monitor-init@.service
+                         monitor/service_files/yaml/phosphor-fan-monitor@.service])
     ])
 
     AC_ARG_VAR(NUM_MONITOR_LOG_ENTRIES, [Maximum number of entries in the message log])
diff --git a/monitor/Makefile.am b/monitor/Makefile.am
index 78b0b57..7c16680 100644
--- a/monitor/Makefile.am
+++ b/monitor/Makefile.am
@@ -4,6 +4,17 @@
 bin_PROGRAMS = \
 	phosphor-fan-monitor
 
+systemdsystemunit_DATA=
+
+if WANT_JSON
+systemdsystemunit_DATA += \
+	service_files/json/phosphor-fan-monitor@.service
+else
+systemdsystemunit_DATA += \
+	service_files/yaml/phosphor-fan-monitor@.service \
+	service_files/yaml/phosphor-fan-monitor-init@.service
+endif
+
 phosphor_fan_monitor_SOURCES = \
 	argument.cpp \
 	fan.cpp \
diff --git a/monitor/service_files/json/phosphor-fan-monitor@.service.in b/monitor/service_files/json/phosphor-fan-monitor@.service.in
new file mode 100644
index 0000000..0975784
--- /dev/null
+++ b/monitor/service_files/json/phosphor-fan-monitor@.service.in
@@ -0,0 +1,7 @@
+[Unit]
+Description=Phosphor Fan Monitor Daemon
+After=mapper-wait@-xyz-openbmc_project-inventory.service
+
+[Service]
+Restart=on-failure
+ExecStart=@BINDIR@/phosphor-fan-monitor
diff --git a/monitor/service_files/yaml/phosphor-fan-monitor-init@.service.in b/monitor/service_files/yaml/phosphor-fan-monitor-init@.service.in
new file mode 100644
index 0000000..8fba6e3
--- /dev/null
+++ b/monitor/service_files/yaml/phosphor-fan-monitor-init@.service.in
@@ -0,0 +1,13 @@
+[Unit]
+Description=Phosphor Fan Monitor Initialization
+Wants=obmc-power-on@%i.target
+After=obmc-power-on@%i.target
+Conflicts=obmc-chassis-powered-off@%i.target
+
+[Service]
+Restart=on-failure
+ExecStart=@BINDIR@/phosphor-fan-monitor --init
+SyslogIdentifier=phosphor-fan-monitor
+
+[Install]
+WantedBy=obmc-chassis-poweron@%i.target
diff --git a/monitor/service_files/yaml/phosphor-fan-monitor@.service.in b/monitor/service_files/yaml/phosphor-fan-monitor@.service.in
new file mode 100644
index 0000000..e57844a
--- /dev/null
+++ b/monitor/service_files/yaml/phosphor-fan-monitor@.service.in
@@ -0,0 +1,11 @@
+[Unit]
+Description=Phosphor Fan Monitor Daemon
+Conflicts=obmc-chassis-powered-off@%i.target
+
+[Service]
+Restart=on-failure
+ExecStart=@BINDIR@/phosphor-fan-monitor --monitor
+SyslogIdentifier=phosphor-fan-monitor
+
+[Install]
+RequiredBy=obmc-fan-control-ready@%i.target