summaryrefslogtreecommitdiff
path: root/net-misc/hylafaxplus/files/hylafaxplus-init-r1
blob: 9a602b44aa70fef976f101eeba74b0dc695bccd2 (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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/sbin/openrc-run
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

extra_commands="zap"

depend() {
	use lo
}

checkconfig() {
	ebegin "Check hylafax server configuration..."

	if [ x${spooldir} = x ] ; then
		eerror "No spooldir directory defined"
		return 1
	else
		SPOOL=${spooldir}
		einfo "Use spool directory ${SPOOL}"
	fi

	if [ x${mode} = x ] ; then
		eerror "No mode defined"
		return 1
	fi

	if [ ! -f ${SPOOL}/etc/setup.cache ] ; then
		eerror "No ${SPOOL}/etc/setup.cache file found. Use faxsetup command"
		return 1
	fi

	if [ x${hfaxd} = x ] || [ ! -f ${hfaxd} ] ; then
		eerror "No hfaxd daemon found"
		return 1
	fi

	if [ x${faxq} = x ] || [ ! -f ${faxq} ] ; then
		eerror "No faxq program found"
		return 1
	fi

	if [ x${faxgetty} = x ] || [ ! -f ${faxgetty} ] ; then
		eerror "No faxgetty program found"
		return 1
	fi

	if [ x${faxbind} = x ] ; then
		eerror "No binding address supplied"
		return 1
	fi

	if [ x${PIDDIR} = x ] ; then
		PIDDIR=${SPOOL}
	else
		PIDDIR=${piddir}
	fi


	hfaxd_args="-l ${faxbind} -q ${SPOOL}"

	case ${mode} in
		newproto)
			if [ x${faxport} = x ] ; then
				eerror "No faxport defined"
				return 1
			fi
			hfaxd_args="${hfaxd_args} -i ${faxport}"
			;;
		oldproto)
			if [ x${oldprotoport} = x ] ; then
				eerror "No oldprotoport defined"
				return 1
			fi
			hfaxd_args="${hfaxd_args} -o ${oldprotoport}"
			;;
		snpp)
			if [ x${snppport} = x ] ; then
				eerror "No snppport defined"
				return 1
			fi
			hfaxd_args="${hfaxd_args} -s ${snppport}"
			;;
		any)
			if [ x${faxport} = x ] || [ x${snppport} = x ] || [ x${oldprotoport} = x ] ; then
				eerror "No port data founded for old services"
				return 1
			fi
			hfaxd_args="${hfaxd_args} -i ${faxport} -s ${snppport} -o ${oldprotoport}"
			;;
		*)
			eerror "Invalid mode"
			return 1
			;;

	esac

	faxq_args="-q ${SPOOL}"

	# workaround for manage save of pidfile with start-stop-daemon
	hfaxd_args="${hfaxd_args} -d"
	faxq_args="${faxq_args} -D"

	return 0
}

start() {
	local result

	checkconfig || return 1

	ebegin "Starting HylaFAX server daemons"

	start_faxq
	result=$?

	if [ ${result} -ne 0 ]  ; then
		eerror "Error on start ${faxq} daemon"
		return 1
	fi

	start_hfaxd
	result=$?

	eend ${result}
}

start_hfaxd() {
	local arguments="--start \
			 --make-pidfile --pidfile ${PIDDIR}/hfaxd.pid"
	einfo "Starting ${hfaxd} with args ${hfaxd_args}"

	start-stop-daemon -b ${arguments} --exec ${hfaxd} -- ${hfaxd_args} > /dev/null 2>&1

	return $?;
}

start_faxq() {
	local arguments="--start \
			 --make-pidfile --pidfile ${PIDDIR}/faxq.pid"
	einfo "Starting ${faxq} ... "

	start-stop-daemon -b ${arguments} --exec ${faxq} -- ${faxq_args} > /dev/null 2>&1

	return $?
}

stop() {
	checkconfig || return 1

	ebegin "Stopping HylaFAX server daemons"

	start-stop-daemon --stop --quiet --pidfile ${PIDDIR}/hfaxd.pid
	start-stop-daemon --stop --quiet --pidfile ${PIDDIR}/faxq.pid
	eend $?
}

zap() {
	checkconfig || return 1

	ebegin "Zap HylaFAX server daemon files"

	if [ -f ${PIDDIR}/hfaxd.pid ] ; then
		rm -f ${PIDDIR}/hfaxd.pid
	fi

	if [ -f ${PIDDIR}/faxq.pid ] ; then
		rm -f ${PIDDIR}/faxq.pid
	fi
}

restart() {
	stop
	start
}