| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | # ispCP ω (OMEGA) a Virtual Hosting Control System |
|---|
| 4 | # Copyright (c) 2007 by ispCP |
|---|
| 5 | # http://www.isp-control.net |
|---|
| 6 | # |
|---|
| 7 | # |
|---|
| 8 | # License: |
|---|
| 9 | # This program is free software; you can redistribute it and/or |
|---|
| 10 | # modify it under the terms of the MPL Mozilla Public License |
|---|
| 11 | # as published by the Free Software Foundation; either version 1.1 |
|---|
| 12 | # of the License, or (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # This program is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # MPL Mozilla Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You may have received a copy of the MPL Mozilla Public License |
|---|
| 20 | # along with this program. |
|---|
| 21 | # |
|---|
| 22 | # An on-line copy of the MPL Mozilla Public License can be found |
|---|
| 23 | # http://www.mozilla.org/MPL/MPL-1.1.html |
|---|
| 24 | # |
|---|
| 25 | # |
|---|
| 26 | # The ispCP Home Page is at: |
|---|
| 27 | # |
|---|
| 28 | # http://www.isp-control.net |
|---|
| 29 | # |
|---|
| 30 | ### BEGIN INIT INFO |
|---|
| 31 | # Provides: ispcp_daemon |
|---|
| 32 | # Required-Start: $network $local_fs $remote_fs |
|---|
| 33 | # Required-Stop: |
|---|
| 34 | # Should-Stop: $local_fs |
|---|
| 35 | # Default-Start: 2 3 4 5 |
|---|
| 36 | # Default-Stop: 0 1 6 |
|---|
| 37 | # Short-Description: ispCP GUI-Backend communication Daemon |
|---|
| 38 | ### END INIT INFO |
|---|
| 39 | # Note: do not modify any of these vars here, use /etc/default/$NAME instead |
|---|
| 40 | |
|---|
| 41 | PATH=/sbin:/bin:/usr/sbin:/usr/bin |
|---|
| 42 | NAME=ispcp_daemon |
|---|
| 43 | DAEMON=/var/www/ispcp/daemon/$NAME |
|---|
| 44 | PID=/var/run/$NAME.pid |
|---|
| 45 | DESC="ispCP GUI-Backend communication Daemon" |
|---|
| 46 | LOGDIR=/var/log/ispcp |
|---|
| 47 | LOGFILE=${LOGDIR}/${NAME}.log |
|---|
| 48 | DIETIME=3 |
|---|
| 49 | |
|---|
| 50 | START=1 |
|---|
| 51 | |
|---|
| 52 | # Debian LSB extensions (will be used if init-functions doesn't override them): |
|---|
| 53 | log_daemon_msg() { |
|---|
| 54 | if [ ! -z "${2:-}" ]; then |
|---|
| 55 | log_success_msg "${1:-}: ${2:-}" |
|---|
| 56 | else |
|---|
| 57 | log_success_msg "${1:-}" |
|---|
| 58 | fi |
|---|
| 59 | } |
|---|
| 60 | log_end_msg() { |
|---|
| 61 | local status="$1" |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | # if not present (e.g. *BSD) make sure to provide compatible methods via /etc/default/$NAME |
|---|
| 65 | if [ -f /lib/lsb/init-functions ]; then |
|---|
| 66 | . /lib/lsb/init-functions |
|---|
| 67 | fi |
|---|
| 68 | |
|---|
| 69 | test -x $DAEMON || { |
|---|
| 70 | if [ "$1" = "stop" ]; then |
|---|
| 71 | log_warning_msg "$DAEMON not installed, but stopping anyway." |
|---|
| 72 | else |
|---|
| 73 | exit 5 |
|---|
| 74 | fi } |
|---|
| 75 | |
|---|
| 76 | # Read config file if present. |
|---|
| 77 | if [ -r /etc/default/$NAME ]; then |
|---|
| 78 | . /etc/default/$NAME |
|---|
| 79 | fi |
|---|
| 80 | |
|---|
| 81 | if [ $START -eq 0 ]; then |
|---|
| 82 | log_warning_msg "Not starting $DESC: edit /etc/default/$NAME." |
|---|
| 83 | exit 1 |
|---|
| 84 | fi |
|---|
| 85 | |
|---|
| 86 | case "$1" in |
|---|
| 87 | start) |
|---|
| 88 | log_daemon_msg "Starting $DESC" "$NAME" |
|---|
| 89 | |
|---|
| 90 | start_daemon -p $PID $DAEMON -p $PID |
|---|
| 91 | |
|---|
| 92 | log_end_msg $? |
|---|
| 93 | ;; |
|---|
| 94 | stop) |
|---|
| 95 | log_daemon_msg "Stopping $DESC" "$NAME" |
|---|
| 96 | |
|---|
| 97 | killproc -p $PID $DAEMON |
|---|
| 98 | |
|---|
| 99 | log_end_msg $? |
|---|
| 100 | |
|---|
| 101 | [ ! -f "$PID" ] || rm -f $PID |
|---|
| 102 | ;; |
|---|
| 103 | restart|force-reload) |
|---|
| 104 | log_daemon_msg "Stopping $DESC" "$NAME" |
|---|
| 105 | |
|---|
| 106 | killproc -p $PID $DAEMON |
|---|
| 107 | |
|---|
| 108 | log_end_msg $? |
|---|
| 109 | |
|---|
| 110 | [ ! -f "$PID" ] || rm -f $PID |
|---|
| 111 | |
|---|
| 112 | [ -n "$DIETIME" ] && sleep "$DIETIME" |
|---|
| 113 | |
|---|
| 114 | log_daemon_msg "Starting $DESC" "$NAME" |
|---|
| 115 | |
|---|
| 116 | start_daemon -p $PID $DAEMON -- -p $PID |
|---|
| 117 | |
|---|
| 118 | log_end_msg $? |
|---|
| 119 | ;; |
|---|
| 120 | status) |
|---|
| 121 | log_daemon_msg "Checking status of $DESC" |
|---|
| 122 | |
|---|
| 123 | pidofproc $DAEMON |
|---|
| 124 | |
|---|
| 125 | status="$?" |
|---|
| 126 | log_end_msg "$status" |
|---|
| 127 | |
|---|
| 128 | case "$status" in |
|---|
| 129 | 0) |
|---|
| 130 | log_success_msg "$NAME running" |
|---|
| 131 | ;; |
|---|
| 132 | 1) |
|---|
| 133 | log_warning_msg "$NAME not running (but pid file found)" |
|---|
| 134 | ;; |
|---|
| 135 | 2) |
|---|
| 136 | log_warning_msg "$NAME not running (but lock file found)" |
|---|
| 137 | ;; |
|---|
| 138 | 3) |
|---|
| 139 | log_warning_msg "$NAME not running" |
|---|
| 140 | ;; |
|---|
| 141 | 4|*) |
|---|
| 142 | log_failure_msg "Service status is unknown" |
|---|
| 143 | exit 1 |
|---|
| 144 | ;; |
|---|
| 145 | esac |
|---|
| 146 | ;; |
|---|
| 147 | |
|---|
| 148 | *) |
|---|
| 149 | N=/etc/init.d/$NAME |
|---|
| 150 | echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 |
|---|
| 151 | exit 1 |
|---|
| 152 | ;; |
|---|
| 153 | esac |
|---|
| 154 | |
|---|
| 155 | exit 0 |
|---|