Ver código fonte

Add Red Hat-style init script

Thanks to @timeos for the initial version (#4)
tags/1.1
Timo Röhling 10 anos atrás
pai
commit
dabac67c35
4 arquivos alterados com 112 adições e 6 exclusões
  1. 9
    4
      CMakeLists.txt
  2. 10
    2
      postinstall.cmake.in
  3. 0
    0
      postsrsd.lsb_init.in
  4. 93
    0
      postsrsd.rh_init.in

+ 9
- 4
CMakeLists.txt Ver arquivo

@@ -10,14 +10,18 @@ find_program(HELP2MAN help2man DOC "path to help2man executable")
10 10
 find_program(DD dd DOC "path to dd executable")
11 11
 find_program(BASE64 base64 DOC "path to base64 executable")
12 12
 find_program(INSSERV insserv DOC "path to insserv executable")
13
+find_program(CHKCONFIG chkconfig DOC "path to chkconfig executable")
13 14
 
14 15
 if(NOT DEFINED INIT_FLAVOR)
15 16
     if(IS_DIRECTORY "/etc/init" AND EXISTS "/lib/init/upstart-job")
16 17
         message(STATUS "Detected init flavor: upstart")
17 18
         set(INIT_FLAVOR "upstart" CACHE STRING "Init daemon of this system")
18
-    elseif(IS_DIRECTORY "/etc/init.d")
19
-        message(STATUS "Detected init flavor: sysv")
20
-        set(INIT_FLAVOR "sysv" CACHE STRING "Init daemon of this system")
19
+    elseif(IS_DIRECTORY "/etc/init.d" AND EXISTS "/lib/lsb/init-functions")
20
+        message(STATUS "Detected init flavor: sysv-lsb")
21
+        set(INIT_FLAVOR "sysv-lsb" CACHE STRING "Init daemon of this system")
22
+    elseif(IS_DIRECTORY "/etc/init.d" AND EXISTS "/etc/init.d/functions")
23
+        message(STATUS "Detected init flavor: sysv-redhat")
24
+        set(INIT_FLAVOR "sysv-redhat" CACHE STRING "Init daemon of this system")
21 25
     else()
22 26
         message(STATUS "Detected init flavor: none")
23 27
         message(STATUS "System startup files will not be installed")
@@ -33,7 +37,8 @@ set(APPARMOR_PROFILE "${CMAKE_INSTALL_PREFIX}/sbin/${POSTSRSD}")
33 37
 string(REGEX REPLACE "^/+" "" APPARMOR_PROFILE "${APPARMOR_PROFILE}")
34 38
 string(REPLACE "/" "." APPARMOR_PROFILE "${APPARMOR_PROFILE}")
35 39
 
36
-configure_file(${PROJECT_NAME}.init.in ${PROJECT_NAME}.init @ONLY)
40
+configure_file(${PROJECT_NAME}.lsb_init.in ${PROJECT_NAME}.lsb_init @ONLY)
41
+configure_file(${PROJECT_NAME}.rh_init.in ${PROJECT_NAME}.rh_init @ONLY)
37 42
 configure_file(${PROJECT_NAME}.upstart.in ${PROJECT_NAME}.upstart @ONLY)
38 43
 configure_file(${PROJECT_NAME}.apparmor.in ${PROJECT_NAME}.apparmor @ONLY)
39 44
 configure_file(postinstall.cmake.in postinstall.cmake @ONLY)

+ 10
- 2
postinstall.cmake.in Ver arquivo

@@ -5,6 +5,7 @@ set(SECRET_FILE "@PROJECT_NAME@.secret")
5 5
 set(DD "@DD@")
6 6
 set(BASE64 "@BASE64@")
7 7
 set(INSSERV "@INSSERV@")
8
+set(CHKCONFIG "@CHKCONFIG@")
8 9
 
9 10
 if(CHROOT_DIR AND NOT EXISTS "$ENV{DESTDIR}${CHROOT_DIR}")
10 11
 	message(STATUS "Chroot jail: $ENV{DESTDIR}${CHROOT_DIR}")
@@ -15,13 +16,20 @@ if(INIT_FLAVOR AND NOT EXISTS "$ENV{DESTDIR}/etc/default/@PROJECT_NAME@")
15 16
 	file(INSTALL FILES "@CMAKE_CURRENT_SOURCE_DIR@/@PROJECT_NAME@.default" DESTINATION "/etc/default" RENAME "@PROJECT_NAME@")
16 17
 endif()
17 18
 
18
-if(INIT_FLAVOR STREQUAL "sysv")
19
-	file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@")
19
+if(INIT_FLAVOR STREQUAL "sysv-lsb")
20
+	file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.lsb_init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@")
20 21
 	if(INSSERV)
21 22
 		execute_process(
22 23
 			COMMAND ${INSSERV} -p "$ENV{DESTDIR}/etc/init.d" @PROJECT_NAME@
23 24
 		)
24 25
 	endif()
26
+elseif(INIT_FLAVOR STREQUAL "sysv-redhat")
27
+	file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.rh_init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@")
28
+	if(CHKCONFIG AND NOT "$ENV{DESTDIR}")
29
+		execute_process(
30
+			COMMAND ${CHKCONFIG} --add @PROJECT_NAME@
31
+		)
32
+	endif()
25 33
 elseif(INIT_FLAVOR STREQUAL "upstart")
26 34
 	file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.upstart" DESTINATION "/etc/init" RENAME "@PROJECT_NAME@.conf")
27 35
 endif()

postsrsd.init.in → postsrsd.lsb_init.in Ver arquivo


+ 93
- 0
postsrsd.rh_init.in Ver arquivo

@@ -0,0 +1,93 @@
1
+#! /bin/sh
2
+#
3
+# @PROJECT_NAME@
4
+#               start/stop the @PROJECT_NAME@ daemon for Postfix
5
+#
6
+# chkconfig: 2345 75 35
7
+# description: Sender Rewriting Scheme (SRS) for Postfix.
8
+# processname: @POSTSRSD@
9
+# pidfile: /var/run/@PROJECT_NAME@.pid
10
+# config: /etc/default/@PROJECT_NAME@
11
+
12
+set -e
13
+
14
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
15
+DAEMON=@CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@
16
+prog=@PROJECT_NAME@
17
+DESC="Postfix Sender Rewriting Scheme daemon"
18
+
19
+PIDFILE=/var/run/$prog.pid
20
+SCRIPTNAME=/etc/init.d/$prog
21
+
22
+# Gracefully exit if the package has been removed.
23
+test -x $DAEMON || exit 0
24
+
25
+. /etc/init.d/functions
26
+
27
+# Default configuration
28
+SRS_DOMAIN=`postconf -h mydomain || true`
29
+SRS_FORWARD_PORT=10001
30
+SRS_REVERSE_PORT=10002
31
+SRS_SECRET=/etc/@PROJECT_NAME@.secret
32
+RUN_AS=nobody
33
+CHROOT=@CHROOT_DIR@
34
+
35
+# Read config file if it is present.
36
+if [ -r /etc/default/$prog ]
37
+then
38
+    . /etc/default/$prog
39
+fi
40
+
41
+test -r "$SRS_SECRET" -a -n "$SRS_DOMAIN" || exit 0
42
+
43
+do_start()
44
+{
45
+	echo -n "Starting $DESC: "
46
+	daemon $prog -4 -f"$SRS_FORWARD_PORT" -r"$SRS_REVERSE_PORT" -d"$SRS_DOMAIN" -s"$SRS_SECRET" \
47
+	             -u"$RUN_AS" -p"$PIDFILE" -c"$CHROOT" -X"$SRS_EXCLUDE_DOMAINS" -D
48
+	RETVAL=$?
49
+	echo
50
+    	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
51
+    	return $RETVAL
52
+}
53
+
54
+do_stop()
55
+{
56
+	echo -n "Stopping $DESC: "
57
+	killproc $prog
58
+        RETVAL=$?
59
+        echo
60
+        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
61
+        return $RETVAL
62
+}
63
+
64
+case "$1" in
65
+  start)
66
+	do_start
67
+	;;
68
+  stop)
69
+	do_stop
70
+	;;
71
+  status)
72
+	status $prog
73
+	;;
74
+  restart|force-reload)
75
+	do_stop
76
+	do_start
77
+	;;
78
+  reload)
79
+	;;
80
+  condrestart|try-restart)
81
+	if [ -f /var/lock/subsys/$prog ]; then
82
+		do_stop
83
+		do_start
84
+	fi
85
+	;;
86
+  *)
87
+	echo "Usage: $prog {start|stop|restart|condrestart|try-restart|reload|force-reload|status|usage}"
88
+	[ "$1" = "usage" ] && exit 0
89
+	exit 2
90
+	;;
91
+esac
92
+exit $?
93
+

Carregando…
Cancelar
Salvar