| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | TIGASEDIR="/usr/local/tigase" |
|---|
| 4 | LOGDIR="/var/log/tigase" |
|---|
| 5 | RUNDIR="/var/run/tigase" |
|---|
| 6 | DYNSTORE="/var/lib/tigase" |
|---|
| 7 | CONFDIR="/etc/tigase" |
|---|
| 8 | TIGASEUSER=tigase |
|---|
| 9 | TIGASEGROUP=tigase |
|---|
| 10 | |
|---|
| 11 | # Sanity check, can everything from tigase be found? |
|---|
| 12 | |
|---|
| 13 | for FILE in "$TIGASEDIR/etc/init.properties" \ |
|---|
| 14 | "$TIGASEDIR/etc/tigase.conf" \ |
|---|
| 15 | "$TIGASEDIR/scripts/tigase.sh"; do |
|---|
| 16 | if [ ! -f "$FILE" ]; then |
|---|
| 17 | echo "Aborting: $FILE not found (looking in: $TIGASEDIR)" |
|---|
| 18 | exit 1 |
|---|
| 19 | fi |
|---|
| 20 | done |
|---|
| 21 | |
|---|
| 22 | # first create /var/lib/tigase so it will be empty when creating user |
|---|
| 23 | if [ ! -d "$DYNSTORE" ]; then |
|---|
| 24 | echo "creating $DYNSTORE" |
|---|
| 25 | mkdir "$DYNSTORE" |
|---|
| 26 | fi |
|---|
| 27 | |
|---|
| 28 | if [ -z `id -un $TIGASEUSER` ]; then |
|---|
| 29 | echo "Creating tigase user: $TIGASEUSER (group: $TIGASEGROUP)" |
|---|
| 30 | addgroup --system $TIGASEGROUP |
|---|
| 31 | adduser --system --ingroup $TIGASEGROUP --home $DYNSTORE--disabled-password $TIGASEUSER |
|---|
| 32 | fi |
|---|
| 33 | |
|---|
| 34 | # make sure permissions on /var/lib/tigase are correct |
|---|
| 35 | chmod 700 "$DYNSTORE" |
|---|
| 36 | chown tigase:tigase "$DYNSTORE" |
|---|
| 37 | |
|---|
| 38 | # give tigase write permissions in /usr/local/tigase/logs |
|---|
| 39 | # this due to a bug in tigase 4.3.1, it shouldn't write there |
|---|
| 40 | chgrp $TIGASEGROUP "$TIGASEDIR"/logs |
|---|
| 41 | chgrp $TIGASEGROUP "$TIGASEDIR"/logs/* |
|---|
| 42 | chmod g+wx "$TIGASEDIR"/logs |
|---|
| 43 | chmod g+w "$TIGASEDIR"/logs/* |
|---|
| 44 | |
|---|
| 45 | # Make other dirs |
|---|
| 46 | if [ ! -d "$LOGDIR" ]; then |
|---|
| 47 | echo "creating $LOGDIR" |
|---|
| 48 | mkdir "$LOGDIR" |
|---|
| 49 | chmod 750 "$LOGDIR" |
|---|
| 50 | chown $TIGASEUSER:adm "$LOGDIR" |
|---|
| 51 | fi |
|---|
| 52 | |
|---|
| 53 | for DIR in "$RUNDIR" "$CONFDIR"; do |
|---|
| 54 | if [ ! -d "$DIR" ]; then |
|---|
| 55 | echo "creating $DIR" |
|---|
| 56 | mkdir "$DIR" |
|---|
| 57 | chmod 700 "$DIR" |
|---|
| 58 | chown $TIGASEUSER:$TIGASEGROUP "$DIR" |
|---|
| 59 | fi |
|---|
| 60 | done |
|---|
| 61 | |
|---|
| 62 | # Move tigase.conf and init.properties to confdir: |
|---|
| 63 | if [ ! -f "$CONFDIR/tigase.conf" ]; then |
|---|
| 64 | cp "$TIGASEDIR/etc/tigase.conf" "$CONFDIR/" |
|---|
| 65 | chown $TIGASEUSER:$TIGASEGROUP "$CONFDIR/tigase.conf" |
|---|
| 66 | fi |
|---|
| 67 | if [ ! -f "$CONFDIR/init.properties" ]; then |
|---|
| 68 | cp "$TIGASEDIR/etc/init.properties" "$CONFDIR/" |
|---|
| 69 | chown $TIGASEUSER:$TIGASEGROUP "$CONFDIR/init.properties" |
|---|
| 70 | fi |
|---|
| 71 | |
|---|
| 72 | # And the needed lines to init.properties: |
|---|
| 73 | |
|---|
| 74 | if ! grep -q "\--comp-name-[0-9]*=muc" "$CONFDIR/init.properties"; then |
|---|
| 75 | echo "--comp-name-1=muc" >> "$CONFDIR/init.properties" |
|---|
| 76 | fi |
|---|
| 77 | |
|---|
| 78 | if ! grep -q "\--comp-class-[0-9]*=tigase.muc.MUCComponent" "$CONFDIR/init.properties"; then |
|---|
| 79 | echo "--comp-class-1=tigase.muc.MUCComponent" >> "$CONFDIR/init.properties" |
|---|
| 80 | fi |
|---|
| 81 | |
|---|
| 82 | if ! grep -q "muc/muc-allow-chat-states[B]=true" "$CONFDIR/init.properties"; then |
|---|
| 83 | echo "muc/muc-allow-chat-states[B]=true" >> "$CONFDIR/init.properties" |
|---|
| 84 | fi |
|---|
| 85 | |
|---|
| 86 | if ! grep -q "muc/muc-lock-new-room[B]=false" "$CONFDIR/init.properties"; then |
|---|
| 87 | echo "muc/muc-lock-new-room[B]=false" >> "$CONFDIR/init.properties" |
|---|
| 88 | fi |
|---|
| 89 | |
|---|
| 90 | if ! grep -q "message-router/components/msg-receivers/s2s.active[B]=false" "$CONFDIR/init.properties"; then |
|---|
| 91 | echo "message-router/components/msg-receivers/s2s.active[B]=false" >> "$CONFDIR/init.properties" |
|---|
| 92 | fi |
|---|
| 93 | |
|---|
| 94 | if ! grep -q "basic-conf/logging/java.util.logging.FileHandler.pattern=$LOGDIR/tigase.log" "$CONFDIR/init.properties"; then |
|---|
| 95 | echo "basic-conf/logging/java.util.logging.FileHandler.pattern=$LOGDIR/tigase.log" >> "$CONFDIR/init.properties" |
|---|
| 96 | fi |
|---|
| 97 | |
|---|
| 98 | # lower the loglevel: |
|---|
| 99 | if grep -q "^--debug = server" "$CONFDIR/init.properties"; then |
|---|
| 100 | sed -i "s,^--debug = server,#--debug = server,g" "$CONFDIR/init.properties" |
|---|
| 101 | fi |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | # Change tigase.conf |
|---|
| 105 | |
|---|
| 106 | # sedding pathes goes wrong, needs escaping |
|---|
| 107 | if grep -q "TIGASE_CONFIG" "$CONFDIR/tigase.conf"; then |
|---|
| 108 | sed -i "s,TIGASE_CONFIG=.*,TIGASE_CONFIG=\"$DYNSTORE\/tigase.xml\",g" "$CONFDIR/tigase.conf" |
|---|
| 109 | else |
|---|
| 110 | echo "TIGASE_CONFIG=\"$DYNSTORE/tigase.xml\"" >> "$CONFDIR/tigase.conf" |
|---|
| 111 | fi |
|---|
| 112 | |
|---|
| 113 | if grep -q "TIGASE_OPTIONS" "$CONFDIR/tigase.conf"; then |
|---|
| 114 | sed -i "s,TIGASE_OPTIONS=.*,TIGASE_OPTIONS=\" --property-file $CONFDIR\/init.properties\",g" "$CONFDIR/tigase.conf" |
|---|
| 115 | else |
|---|
| 116 | echo "TIGASE_OPTIONS=\" --property-file $CONFDIR/init.properties\"" >> "$CONFDIR/tigase.conf" |
|---|
| 117 | fi |
|---|
| 118 | |
|---|
| 119 | if grep -q "TIGASE_CONSOLE_LOG" "$CONFDIR/tigase.conf"; then |
|---|
| 120 | sed -i "s,TIGASE_CONSOLE_LOG=.*,TIGASE_CONSOLE_LOG=\"$LOGDIR\/console.log\",g" "$CONFDIR/tigase.conf" |
|---|
| 121 | else |
|---|
| 122 | echo "TIGASE_CONSOLE_LOG=\"$LOGDIR/console.log\"" >> "$CONFDIR/tigase.conf" |
|---|
| 123 | fi |
|---|
| 124 | |
|---|
| 125 | if grep -q "TIGASE_PID" "$CONFDIR/tigase.conf"; then |
|---|
| 126 | sed -i "s,TIGASE_PID=.*,TIGASE_PID=\"$RUNDIR\/tigase.pid\",g" "$CONFDIR/tigase.conf" |
|---|
| 127 | else |
|---|
| 128 | echo "TIGASE_PID=\"$RUNDIR/tigase.pid\"" >> "$CONFDIR/tigase.conf" |
|---|
| 129 | fi |
|---|
| 130 | |
|---|
| 131 | if grep -q "TIGASE_HOME" "$CONFDIR/tigase.conf"; then |
|---|
| 132 | sed -i "s,TIGASE_HOME=.*,TIGASE_HOME=\"$TIGASEDIR\",g" "$CONFDIR/tigase.conf" |
|---|
| 133 | else |
|---|
| 134 | echo "TIGASE_HOME=\"$TIGASEDIR\"" >> "$CONFDIR/tigase.conf" |
|---|
| 135 | fi |
|---|
| 136 | |
|---|
| 137 | if grep -q "HOME" "$CONFDIR/tigase.conf"; then |
|---|
| 138 | sed -i "s,HOME=.*,HOME=\"$TIGASEDIR\",g" "$CONFDIR/tigase.conf" |
|---|
| 139 | else |
|---|
| 140 | echo "HOME=\"$TIGASEDIR\"" >> "$CONFDIR/tigase.conf" |
|---|
| 141 | fi |
|---|
| 142 | |
|---|
| 143 | if [ ! -f "/etc/init.d/tigase" ]; then |
|---|
| 144 | cat > /etc/init.d/tigase <<EOF |
|---|
| 145 | #!/bin/sh |
|---|
| 146 | # |
|---|
| 147 | # Quick and dirty tigase start/stop script |
|---|
| 148 | # |
|---|
| 149 | |
|---|
| 150 | ### BEGIN INIT INFO |
|---|
| 151 | # Provides: tigase |
|---|
| 152 | # Required-Start: \$remote_fs \$network |
|---|
| 153 | # Required-Stop: \$remote_fs \$network |
|---|
| 154 | # Default-Start: 2 3 4 5 |
|---|
| 155 | # Default-Stop: 0 1 6 |
|---|
| 156 | # Short-Description: Starts tigase jabber server |
|---|
| 157 | # Description: Starts tigase jabber server, an high performance XMPP |
|---|
| 158 | # compliant server written in Java. |
|---|
| 159 | ### END INIT INFO |
|---|
| 160 | |
|---|
| 161 | TIGASE=$TIGASEDIR/scripts/tigase.sh |
|---|
| 162 | TIGASECONF=$CONFDIR/tigase.conf |
|---|
| 163 | TIGASEUSER=$TIGASEUSER |
|---|
| 164 | case "\$1" in |
|---|
| 165 | start) |
|---|
| 166 | sudo -u \$TIGASEUSER \$TIGASE start \$TIGASECONF |
|---|
| 167 | ;; |
|---|
| 168 | stop) |
|---|
| 169 | sudo -u \$TIGASEUSER \$TIGASE stop \$TIGASECONF |
|---|
| 170 | ;; |
|---|
| 171 | restart|force-reload) |
|---|
| 172 | sudo -u \$TIGASEUSER \$TIGASE restart \$TIGASECONF |
|---|
| 173 | ;; |
|---|
| 174 | *) |
|---|
| 175 | echo "Usage: \$0 {start|stop|restart|force-reload}" >&2 |
|---|
| 176 | exit 1 |
|---|
| 177 | ;; |
|---|
| 178 | esac |
|---|
| 179 | |
|---|
| 180 | exit 0 |
|---|
| 181 | |
|---|
| 182 | EOF |
|---|
| 183 | chmod 755 /etc/init.d/tigase |
|---|
| 184 | update-rc.d tigase defaults 80 10 |
|---|
| 185 | fi |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | exit 0 |
|---|