| 1 | #!/sbin/openrc-run |
| 2 | # Copyright 1999-2008 Gentoo Foundation |
| 3 | # Author Geaaru |
| 4 | # Distributed under the terms of the GNU General Public License v2 |
| 5 | |
| 6 | extra_stopped_commands="zap" |
| 7 | |
| 8 | depend() { |
| 9 | use lo |
| 10 | } |
| 11 | |
| 12 | checkconfig() { |
| 13 | ebegin "Checking hylafax server configuration" |
| 14 | |
| 15 | if [ x$spooldir == x ] ; then |
| 16 | eerror "No spooldir directory defined" |
| 17 | return 1 |
| 18 | else |
| 19 | SPOOL=$spooldir |
| 20 | einfo "Use spool directory $SPOOL" |
| 21 | fi |
| 22 | |
| 23 | if [ x$mode == x ] ; then |
| 24 | eerror "No mode defined" |
| 25 | return 1 |
| 26 | fi |
| 27 | |
| 28 | if [ ! -f $SPOOL/lib/hfaxd.conf ] ; then |
| 29 | eerror "No $SPOOL/lib/hfaxd.conf file found. Rename and modify the hfaxd.conf.default" |
| 30 | return 1 |
| 31 | fi |
| 32 | |
| 33 | if [ ! -f $SPOOL/etc/setup.cache ] ; then |
| 34 | eerror "No $SPOOL/etc/setup.cache file found. Use faxsetup command" |
| 35 | return 1 |
| 36 | fi |
| 37 | |
| 38 | if [[ x$hfaxd == x || ! -f $hfaxd ]] ; then |
| 39 | eerror "No hfaxd daemon found" |
| 40 | return 1 |
| 41 | fi |
| 42 | |
| 43 | if [[ x$faxq == x || ! -f $faxq ]] ; then |
| 44 | eerror "No faxq program found" |
| 45 | return 1 |
| 46 | fi |
| 47 | |
| 48 | if [[ x$faxgetty == x || ! -f $faxgetty ]] ; then |
| 49 | eerror "No faxgetty program found" |
| 50 | return 1 |
| 51 | fi |
| 52 | |
| 53 | if [ x$faxbind == x ] ; then |
| 54 | eerror "No binding address supply" |
| 55 | return 1 |
| 56 | fi |
| 57 | |
| 58 | if [ x$piddir == x ] ; then |
| 59 | PIDDIR=$SPOOL |
| 60 | else |
| 61 | PIDDIR=$piddir |
| 62 | fi |
| 63 | |
| 64 | |
| 65 | hfaxd_args="-l $faxbind -q $SPOOL" |
| 66 | |
| 67 | case $mode in |
| 68 | newproto) |
| 69 | if [[ x$faxport == x ]] ; then |
| 70 | eerror "No faxport defined" |
| 71 | return 1 |
| 72 | fi |
| 73 | hfaxd_args="$hfaxd_args -i $faxport" |
| 74 | ;; |
| 75 | oldproto) |
| 76 | if [[ x$oldprotoport == x ]] ; then |
| 77 | eerror "No oldprotoport defined" |
| 78 | return 1 |
| 79 | fi |
| 80 | hfaxd_args="$hfaxd_args -o $oldprotoport" |
| 81 | ;; |
| 82 | snpp) |
| 83 | if [[ x$snppport == x ]] ; then |
| 84 | eerror "No snppport defined" |
| 85 | return 1 |
| 86 | fi |
| 87 | hfaxd_args="$hfaxd_args -s $snppport" |
| 88 | ;; |
| 89 | any) |
| 90 | if [[ x$faxport == x || x$snppport == x || x$oldprotoport == x ]] ; then |
| 91 | eerror "No port data found for old services" |
| 92 | return 1 |
| 93 | fi |
| 94 | hfaxd_args="$hfaxd_args -i $faxport -s $snppport -o $oldprotoport" |
| 95 | ;; |
| 96 | *) |
| 97 | eerror "Invalid mode" |
| 98 | return 1 |
| 99 | ;; |
| 100 | |
| 101 | esac |
| 102 | |
| 103 | faxq_args="-q $SPOOL" |
| 104 | |
| 105 | # workaround for manage save of pidfile with start-stop-daemon |
| 106 | hfaxd_args="$hfaxd_args -d" |
| 107 | faxq_args="$faxq_args -D" |
| 108 | |
| 109 | return 0 |
| 110 | } |
| 111 | |
| 112 | start() { |
| 113 | local result |
| 114 | |
| 115 | checkconfig || return 1 |
| 116 | |
| 117 | ebegin "Starting HylaFAX server daemons" |
| 118 | |
| 119 | start_faxq |
| 120 | result=$? |
| 121 | |
| 122 | if [ $result -ne 0 ] ; then |
| 123 | eerror "Error on start $faxq daemon" |
| 124 | return 1 |
| 125 | fi |
| 126 | |
| 127 | start_hfaxd |
| 128 | result=$? |
| 129 | |
| 130 | eend $result |
| 131 | } |
| 132 | |
| 133 | start_hfaxd() { |
| 134 | local arguments="--start \ |
| 135 | --make-pidfile --pidfile $PIDDIR/hfaxd.pid" |
| 136 | |
| 137 | einfo "Starting $hfaxd with args $hfaxd_args" |
| 138 | |
| 139 | start-stop-daemon -b ${arguments} --exec $hfaxd -- $hfaxd_args > /dev/null 2>&1 |
| 140 | |
| 141 | return $?; |
| 142 | } |
| 143 | |
| 144 | start_faxq() { |
| 145 | local arguments="--start \ |
| 146 | --make-pidfile --pidfile $PIDDIR/faxq.pid" |
| 147 | einfo "Starting $faxq ... " |
| 148 | |
| 149 | start-stop-daemon -b ${arguments} --exec $faxq -- $faxq_args > /dev/null 2>&1 |
| 150 | |
| 151 | return $? |
| 152 | } |
| 153 | |
| 154 | stop() { |
| 155 | checkconfig || return 1 |
| 156 | |
| 157 | ebegin "Stopping HylaFAX server daemons" |
| 158 | |
| 159 | start-stop-daemon --stop --quiet --pidfile $PIDDIR/hfaxd.pid |
| 160 | start-stop-daemon --stop --quiet --pidfile $PIDDIR/faxq.pid |
| 161 | eend $? |
| 162 | } |
| 163 | |
| 164 | zap() { |
| 165 | checkconfig || return 1 |
| 166 | |
| 167 | ebegin "Zap HylaFAX server daemon files" |
| 168 | |
| 169 | if [ -f $PIDFILE/hfaxd.pid ] ; then |
| 170 | rm -f $PIDFILE/hfaxd.pid |
| 171 | fi |
| 172 | |
| 173 | if [ -f $PIDFILE/faxq.pid ] ; then |
| 174 | rm -f $PIDFILE/faxq.pid |
| 175 | fi |
| 176 | } |
| 177 | |
| 178 | restart() { |
| 179 | stop |
| 180 | start |
| 181 | } |
| 182 | |