File: kopano-server.init.rhel

package info (click to toggle)
kopanocore 8.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 15,400 kB
  • sloc: cpp: 175,422; python: 24,623; perl: 7,319; php: 6,056; sh: 2,172; makefile: 1,294; xml: 45; ansic: 1
file content (145 lines) | stat: -rw-r--r-- 3,063 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
#
# kopano-server Kopano Groupware Core MAPI Server
#
# chkconfig: 345 85 25
# processname: /usr/sbin/kopano-server
# config: /etc/kopano/server.cfg
# pidfile: /var/run/kopano/server.pid
# SPDX-License-Identifier: AGPL-3.0-only
### BEGIN INIT INFO
# Provides: kopano-server
# Required-Start: $local_fs $network $remote_fs $syslog
# Required-Stop: $local_fs $network $remote_fs $syslog
# Should-Start: mysqld
# Should-Stop: mysqld
# Short-Description: Kopano Core MAPI Server
### END INIT INFO

SERVERCONFIG=/etc/kopano/server.cfg
SERVERPROGRAM=/usr/sbin/kopano-server

# Sanity checks.
[ -x $SERVERPROGRAM ] || exit 0

SERVERCONFIG_OPT=""
[ ! -z $SERVERCONFIG -a -f $SERVERCONFIG ] && SERVERCONFIG_OPT="-c $SERVERCONFIG"

# Switch to C, like at boot time.
unset LANG LC_CTYPE LC_NUMERIC LC_COLLATE LC_MESSAGES LC_ALL

# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=0
server=`basename $SERVERPROGRAM`
lockfile=/var/lock/subsys/$server
pidfile=/var/run/kopano/server.pid

start() {
	# Start in background, always succeeds
	echo -n $"Starting $server: "
	install -dm0775 -o kopano -g kopano /var/run/kopano
	daemon --pidfile="$pidfile" $SERVERPROGRAM $SERVERCONFIG_OPT
	RETVAL=$?
	unset LC_ALL LANG
	echo
	[ $RETVAL -eq 0 ] && touch $lockfile

	return $RETVAL
}

stop() {
	if [ -f /tmp/zarafa-upgrade-lock -o -f /tmp/kopano-upgrade-lock ]; then
		echo
		echo "Server database upgrade is taking place."
		echo "Do not stop this process bacause it may render your database unusable."
		echo
		exit 1
	fi
	# Cannot use killproc, because it has no timeout feature;
	# the server may take up to 60 seconds to shutdown.
	SPID=`cat /var/run/kopano/server.pid 2>/dev/null`
	if [ -z "$SPID" -o ! -n "$SPID" ]; then
		echo -n "Program ID of $server not found, trying to stop anyway: "
		killall $SERVERPROGRAM >/dev/null 2>&1
		RETVAL=$?
		echo
		if [ $RETVAL -eq 0 ]; then
			failure $"Stopping $server: "
		else
			success $"Stopping $server: "
		fi
		RETVAL=0
	else
		echo -n $"Stopping $server: "
		TIMEOUT=65
		/bin/kill $SPID >/dev/null 2>&1
		if [ $? -eq 0 ]; then
			while [ $TIMEOUT -gt 0 ]; do
				/bin/kill -0 $SPID >/dev/null 2>&1 || break
				sleep 1
				TIMEOUT=$(($TIMEOUT-1))
			done
			if [ $TIMEOUT -eq 0 ]; then
				failure $"Timeout on stopping $server"
				RETVAL=1
			else
				success $"Stopping $server: "
				RETVAL=0
			fi
		else
			failure $"Stopping $server: "
		fi
		echo
	fi
	[ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile

	return $RETVAL
}

restart() {
	stop
	start
}

reload() {
	echo -n $"Restarting $server: "
	killproc -p "$pidfile" $SERVERPROGRAM -SIGHUP
	RETVAL=$?
	echo

	return $RETVAL
}

# See how we were called.
case "$1" in
    start)
		start
		;;
    stop)
		stop
		;;
    status)
		status $server
		RETVAL=$?
		;;
    restart|force-reload)
		restart
		;;
    condrestart|try-restart)
		if [ -f ${pidfile} ]; then
			stop
			start
		fi
		;;
    reload)
		reload
		;;
    *)
		echo $"Usage: $server {start|stop|status|reload|restart|condrestart|force-reload|try-restart}"
		RETVAL=1
		;;
esac

exit $RETVAL