Browse Source

refactor: update debian script. (#965)

Bo-Yi Wu 2 years ago
parent
commit
252adc912d
1 changed files with 42 additions and 82 deletions
  1. 42 82
      scripts/init/debian/gitea

+ 42 - 82
scripts/init/debian/gitea

@@ -1,4 +1,4 @@
1
-#! /bin/sh
1
+#!/bin/sh
2 2
 ### BEGIN INIT INFO
3 3
 # Provides:          gitea
4 4
 # Required-Start:    $syslog $network
@@ -24,6 +24,8 @@ WORKINGDIR=/home/git/gitea
24 24
 DAEMON=$WORKINGDIR/$NAME
25 25
 DAEMON_ARGS="web"
26 26
 USER=git
27
+USERBIND="setcap cap_net_bind_service=+ep"
28
+STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/1/KILL/5}"
27 29
 
28 30
 # Read configuration variable file if it is present
29 31
 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
@@ -31,96 +33,54 @@ USER=git
31 33
 # Exit if the package is not installed
32 34
 [ -x "$DAEMON" ] || exit 0
33 35
 
34
-# Load the VERBOSE setting and other rcS variables
35
-. /lib/init/vars.sh
36
-
37
-# Define LSB log_* functions.
38
-# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
39
-# and status_of_proc is working.
40
-. /lib/lsb/init-functions
41
-
42
-#
43
-# Function that starts the daemon/service
44
-#
45 36
 do_start()
46 37
 {
47
-	# Return
48
-	#   0 if daemon has been started
49
-	#   1 if daemon was already running
50
-	#   2 if daemon could not be started
51
-	sh -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
52
-			--test --chdir $WORKINGDIR --chuid $USER \\
53
-			--exec $DAEMON -- $DAEMON_ARGS > /dev/null \\
54
-			|| return 1"
55
-	sh -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
56
-			--background --chdir $WORKINGDIR --chuid $USER \\
57
-			--exec $DAEMON -- $DAEMON_ARGS \\
58
-			|| return 2"
38
+    $USERBIND $DAEMON
39
+    sh -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
40
+        --background --chdir $WORKINGDIR --chuid $USER \\
41
+        --exec $DAEMON -- $DAEMON_ARGS"
59 42
 }
60 43
 
61
-#
62
-# Function that stops the daemon/service
63
-#
64 44
 do_stop()
65 45
 {
66
-	# Return
67
-	#   0 if daemon has been stopped
68
-	#   1 if daemon was already stopped
69
-	#   2 if daemon could not be stopped
70
-	#   other if a failure occurred
71
-	start-stop-daemon --stop --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE --name $NAME
72
-	RETVAL="$?"
73
-	[ "$RETVAL" = 2 ] && return 2
74
-	start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON
75
-	[ "$?" = 2 ] && return 2
76
-	# Many daemons don't delete their pidfiles when they exit.
77
-	rm -f $PIDFILE
78
-	return "$RETVAL"
46
+    start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PIDFILE --name $NAME --oknodo
47
+    rm -f $PIDFILE
79 48
 }
80 49
 
50
+do_status()
51
+{
52
+    if [ -f $PIDFILE ]; then
53
+        if kill -0 $(cat "$PIDFILE"); then
54
+            echo "$NAME is running, PID is $(cat $PIDFILE)"
55
+        else
56
+            echo "$NAME process is dead, but pidfile exists"
57
+        fi
58
+    else
59
+        echo "$NAME is not running"
60
+    fi
61
+}
81 62
 
82 63
 case "$1" in
83
-  start)
84
-	[ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
85
-	do_start
86
-	case "$?" in
87
-		0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
88
-		2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
89
-	esac
90
-	;;
91
-  stop)
92
-	[ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
93
-	do_stop
94
-	case "$?" in
95
-		0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
96
-		2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
97
-	esac
98
-	;;
99
-  status)
100
-	status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
101
-	;;
102
-  restart|force-reload)
103
-	log_daemon_msg "Restarting $DESC" "$NAME"
104
-	do_stop
105
-	case "$?" in
106
-	  0|1)
107
-		do_start
108
-		case "$?" in
109
-			0) log_end_msg 0 ;;
110
-			1) log_end_msg 1 ;; # Old process is still running
111
-			*) log_end_msg 1 ;; # Failed to start
112
-		esac
113
-		;;
114
-	  *)
115
-		# Failed to stop
116
-		log_end_msg 1
117
-		;;
118
-		esac
119
-	;;
120
-  *)
121
-		echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
122
-		exit 3
123
-		;;
64
+    start)
65
+        echo "Starting $DESC" "$NAME"
66
+        do_start
67
+        ;;
68
+    stop)
69
+        echo "Stopping $DESC" "$NAME"
70
+        do_stop
71
+        ;;
72
+    status)
73
+        do_status
74
+        ;;
75
+    restart)
76
+        echo "Restarting $DESC" "$NAME"
77
+        do_stop
78
+        do_start
79
+        ;;
80
+    *)
81
+        echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
82
+        exit 2
83
+        ;;
124 84
 esac
125 85
 
126
-:
86
+exit 0