summaryrefslogtreecommitdiff
path: root/add-install-section-in-src-CMakeList.txt-and-module-Makefile.patch
blob: 7d7f5779c9de8a649477a7fe904ea14fd127a752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
From 5f14b328ea78ea7b375c775d894dd987ce707fdb Mon Sep 17 00:00:00 2001
From: wangxiaomeng <wangxiaomeng@kylinos.cn>
Date: Thu, 23 May 2024 14:57:12 +0800
Subject: [PATCH] add install section in src/CMakeList.txt and module/Makefile

---
 module/Makefile    | 30 ++++++++++++++++++++++++------
 src/CMakeLists.txt | 27 +++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/module/Makefile b/module/Makefile
index 8030152..0ca0f86 100644
--- a/module/Makefile
+++ b/module/Makefile
@@ -3,19 +3,37 @@
 # Author: xuchunmei
 # Create: 2018-12-15
 
+KERNELVER?=$(shell uname -r)
+
 obj-m += sysmonitor.o
 sysmonitor-objs := sysmonitor_main.o signo_catch.o fdstat.o monitor_netdev.o
-KERNELDIR ?= /lib/modules/$(shell uname -r)/build
+KERNELDIR ?= /lib/modules/$(KERNELVER)/build
 PWD := $(shell pwd)
 EXTRA_CFLAGS += -Wall -Werror
 
-modules:
+default:
 	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
 
-modules_install:
-	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
-
 clean:
 	$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
+	rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.order .sysmonitor* .mo* .Module* .signo* sysmonitor.mod .fdstat.*
+
+install:
+	install -d -m 750 /lib/modules/sysmonitor
+	install -m 640 sysmonitor.ko /lib/modules/sysmonitor
+	lsmod | grep -qw sysmonitor && modprobe -r sysmonitor || true
+	if [ -e "/lib/modules/sysmonitor/sysmonitor.ko" ];then \
+		/sbin/depmod -aeF /boot/System.map-$(KERNELVER) $(KERNELVER) > /dev/null;\
+		insmod /lib/modules/sysmonitor/sysmonitor.ko 2>/dev/null 1>/dev/null;\
+		if [ $$? -ne 0 ];then { echo "sysmonitor.ko modprobe is failed.";exit 0;} fi;\
+	else\
+		echo "The /lib/modules/sysmonitor/sysmonitor.ko file does not exist in the sysmonitor rpm package";\
+		exit 0; \
+	fi
 
-.PHONY: modules modules_install clean
+uninstall:
+	if [ $(id -u) -ne 0 ]; then { echo "root permission is required to uninstall sysmonitor";exit 0;} fi
+	ps h -C sysmonitor -o pid && killall sysmonitor || true
+	lsmod | grep -qw sysmonitor && modprobe -r sysmonitor || true
+	rm -rf /lib/modules/sysmonitor
+	/sbin/depmod -aeF /boot/System.map-$(KERNELVER) $(KERNELVER) > /dev/null
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e5af612..4943c8f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,6 +6,12 @@
 project(sysmonitor)
 
 set(CMAKE_C_FLAGS "-Wall -Werror -D_FORTIFY_SOURCE=2 -O2 -fPIE -fstack-protector-strong -g")
+set(CMAKE_INSTALL_SYSCONFDIR "/etc")
+set(CMAKE_INSTALL_LIBEXECDIR "/usr/libexec")
+set(CMAKE_INSTALL_SYSLOGDIR "/etc/rsyslog.d")
+set(CMAKE_INSTALL_SBINDIR "/usr/sbin")
+set(CMAKE_INSTALL_BINDIR "/usr/bin")
+set(SYSTEMD_SERVICEDIR "/usr/lib/systemd/system/")
 
 if (VERSION)
   add_compile_options(-D ${VERSION})
@@ -18,3 +24,24 @@ endif(CUSTOM)
 add_executable(sysmonitor common.c custom.c disk.c fsmonitor.c filemonitor.c process.c sys_resources.c sys_event.c sysmonitor.c zombie.c monitor_thread.c)
 set_target_properties(sysmonitor PROPERTIES LINK_FLAGS "-Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now -Wtrampolines -pie")
 target_link_libraries(sysmonitor boundscheck pthread)
+install(TARGETS sysmonitor DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(DIRECTORY ../conf/ DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor PATTERN "rsyslog.d " EXCLUDE PATTERN "clock_transition" EXCLUDE PATTERN "io_monitor" EXCLUDE PATTERN "logind_monitor" EXCLUDE PATTERN "sysmonitor" EXCLUDE PATTERN "io_monitor" EXCLUDE)
+install(FILES ../conf/rsyslog.d/sysmonitor.conf DESTINATION ${CMAKE_INSTALL_SYSLOGDIR})
+install(FILES ../conf/logrotate.d/sysmonitor-logrotate DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/sysmonitor)
+install(FILES ../conf/clock_transition DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d)
+install(FILES ../conf/io_monitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d)
+install(FILES ../conf/logind_monitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d)
+install(FILES ../conf/sysmonitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysconfig)
+
+install(DIRECTORY ../script/ DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/sysmonitor PATTERN "iomonitor_daemon" EXCLUDE)
+install(PROGRAMS ../script/iomonitor_daemon  DESTINATION ${CMAKE_INSTALL_SBINDIR})
+install(FILES ../conf/io_monitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d)
+install(FILES ../service/sysmonitor.service DESTINATION ${SYSTEMD_SERVICEDIR})
+
+add_custom_target(uninstall
+	COMMAND rm -rf /etc/sysmonitor /usr/libexec/sysmonitor /etc/rsyslog.d/sysmonitor.conf /etc/sysmonitor.d/
+	COMMAND rm -rf /usr/lib/systemd/system/sysmonitor.service
+	COMMAND rm -rf /usr/sbin/iomonitor_daemon /usr/bin/sysmonitor
+	COMMENT "Uninstall sysmonitor"
+	VERBATIM
+)
-- 
2.43.0