Adding service file

Service file for swampd has been added

Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
Change-Id: If449c0e943f1a82e9d18599391f0dc68c28009ec
diff --git a/Makefile.am b/Makefile.am
index 3283236..45b26d4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -38,6 +38,10 @@
 AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
 AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
 
+if HAVE_SYSTEMD
+systemdsystemunit_DATA = phosphor-pid-control.service
+endif
+
 bin_PROGRAMS = swampd setsensor
 
 setsensor_SOURCES = setsensor.cpp
diff --git a/configure.ac b/configure.ac
index b216837..bfc6917 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,6 +81,27 @@
 AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
                                       [Build test cases]))
 
+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])]
+)
+AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
+
 # Check/set gtest specific functions.
 AS_IF([test "x$enable_tests" != "xno"], [
     PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
@@ -188,6 +209,10 @@
     [AC_DEFINE(CONFIGURE_DBUS, [0], [Do not read configuration from D-Bus.])]
 )
 
+AC_ARG_VAR(SYSTEMD_TARGET, "Target for starting this service")
+AS_IF([test "x$SYSTEMD_TARGET" == "x"], [SYSTEMD_TARGET="multi-user.target"])
+
 # Create configured output
 AC_CONFIG_FILES([Makefile test/Makefile])
+AC_CONFIG_FILES([phosphor-pid-control.service])
 AC_OUTPUT
diff --git a/phosphor-pid-control.service.in b/phosphor-pid-control.service.in
new file mode 100644
index 0000000..aa29377
--- /dev/null
+++ b/phosphor-pid-control.service.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=Phosphor-Pid-Control Margin-based Fan Control Daemon
+
+[Service]
+Restart=always
+ExecStart={bindir}/swampd
+RestartSec=5
+StartLimitInterval=0
+Type=simple
+
+[Install]
+WantedBy=@SYSTEMD_TARGET@