Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for systemd #5

Closed
jariq opened this issue Jul 15, 2018 · 1 comment
Closed

Support for systemd #5

jariq opened this issue Jul 15, 2018 · 1 comment

Comments

@jariq
Copy link
Owner

jariq commented Jul 15, 2018

IPwatchD 1.2.1 released back in 2011 was designed with "System V" init system in mind. As of 2018, the majority of Linux distributions (including Debian, Ubuntu, Fedora, CentOS and RHEL) have adopted systemd as their default init system so adapting IPwatchD to systemd seems to be inevitable.

Fedora package already includes following patch which adds basic systemd support:

diff -uNr ipwatchd-1.2.1/src/daemonize.c ipwatchd-1.2.1-systemd/src/daemonize.c
--- ipwatchd-1.2.1/src/daemonize.c	2011-07-24 16:39:03.000000000 +0200
+++ ipwatchd-1.2.1-systemd/src/daemonize.c	2013-10-09 14:17:19.381133164 +0200
@@ -41,12 +41,13 @@
 		return (IPWD_RV_ERROR);
 	}
 
-	/* If parent of this process is init we are already in daemon mode */
-	if (getppid () == 1)
-	{
-		ipwd_message (IPWD_MSG_TYPE_INFO, "Already running as daemon");
-		return (IPWD_RV_SUCCESS);
-	}
+	// Commented out so systemd can treat ipwatchd as "forking" service
+	///* If parent of this process is init we are already in daemon mode */
+	//if (getppid () == 1)
+	//{
+	//	ipwd_message (IPWD_MSG_TYPE_INFO, "Already running as daemon");
+	//	return (IPWD_RV_SUCCESS);
+	//}
 
 	/* Fork child process */
 	pid_t pid = fork ();
diff -uNr ipwatchd-1.2.1/src/ipwatchd.service ipwatchd-1.2.1-systemd/src/ipwatchd.service
--- ipwatchd-1.2.1/src/ipwatchd.service	1970-01-01 01:00:00.000000000 +0100
+++ ipwatchd-1.2.1-systemd/src/ipwatchd.service	2013-10-09 14:17:41.919028973 +0200
@@ -0,0 +1,10 @@
+[Unit]
+Description=IP conflict detection daemon
+After=syslog.target network.target
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/ipwatchd -c /etc/ipwatchd.conf
+
+[Install]
+WantedBy=multi-user.target
diff -uNr ipwatchd-1.2.1/src/Makefile ipwatchd-1.2.1-systemd/src/Makefile
--- ipwatchd-1.2.1/src/Makefile	2011-07-24 16:39:03.000000000 +0200
+++ ipwatchd-1.2.1-systemd/src/Makefile	2013-10-09 14:12:29.492616767 +0200
@@ -43,14 +43,15 @@
 
 
 install:
-	mkdir -p $(DESTDIR)/etc/init.d
+	mkdir -p $(DESTDIR)/etc
+	mkdir -p $(DESTDIR)/usr/lib/systemd/system
 	mkdir -p $(DESTDIR)/usr/sbin
 	mkdir -p $(DESTDIR)/usr/share/man/man8
 	mkdir -p $(DESTDIR)/usr/share/man/man5
 	mkdir -p $(DESTDIR)/usr/share/man/man1
 	cp ipwatchd $(DESTDIR)/usr/sbin
 	cp scripts/ipwatchd-script $(DESTDIR)/usr/sbin
-	cp scripts/ipwatchd $(DESTDIR)/etc/init.d
+	cp ipwatchd.service $(DESTDIR)/usr/lib/systemd/system/
 	cp ipwatchd.conf $(DESTDIR)/etc
 	cp ../doc/ipwatchd.8.gz $(DESTDIR)/usr/share/man/man8
 	cp ../doc/ipwatchd.conf.5.gz $(DESTDIR)/usr/share/man/man5
@@ -59,7 +60,7 @@
 uninstall:
 	rm $(DESTDIR)/usr/sbin/ipwatchd
 	rm $(DESTDIR)/usr/sbin/ipwatchd-script
-	rm $(DESTDIR)/etc/init.d/ipwatchd
+	rm $(DESTDIR)/usr/lib/systemd/system/ipwatchd.service
 	rm $(DESTDIR)/etc/ipwatchd.conf
 	rm $(DESTDIR)/usr/share/man/man8/ipwatchd.8.gz
 	rm $(DESTDIR)/usr/share/man/man5/ipwatchd.conf.5.gz
@jariq
Copy link
Owner Author

jariq commented Jul 17, 2018

Relevant systemd documentation: daemon, systemd.service

This was referenced Jul 21, 2018
@jariq jariq closed this as completed Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant