unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
unrealircd.in (11023B)
1 #!/bin/sh 2 3 PID_FILE="@PIDFILE@" 4 PID_BACKUP="@PIDFILE@.bak" 5 BINDIR="@BINDIR@" 6 UNREALIRCDCTL="$BINDIR/unrealircdctl" 7 IRCD="$BINDIR/unrealircd" 8 BUILDDIR="@BUILDDIR@" 9 CONFDIR="@CONFDIR@" 10 TMPDIR="@TMPDIR@" 11 SCRIPTDIR="@SCRIPTDIR@" 12 MODULESDIR="@MODULESDIR@" 13 14 # When built with --with-asan, ASan does not dump core by default because 15 # older gcc/clang might dump a 16TB core file. We explicitly enable it here. 16 export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0:unmap_shadow_on_exit=1:log_path=$TMPDIR/unrealircd_asan:detect_leaks=0" 17 18 if [ ! -f $IRCD ]; then 19 echo "ERROR: Could not find the IRCd binary ($IRCD)" 20 echo "This could mean two things:" 21 echo "1) You forgot to run 'make install' after running 'make'" 22 echo "2) You answered a ./Config question incorrectly" 23 exit 24 fi 25 if [ ! -d "$TMPDIR" ]; then 26 mkdir "$TMPDIR" 27 fi 28 29 if [ "$1" = "start" ] ; then 30 if [ -r $PID_FILE ] ; then 31 if kill -CHLD `cat $PID_FILE` 1>/dev/null 2>&1; then 32 if $UNREALIRCDCTL status 1>/dev/null 2>&1; then 33 echo "UnrealIRCd is already running (PID `cat $PID_FILE`)." 34 echo "To restart UnrealIRCd, use: $0 restart" 35 exit 1 36 fi 37 fi 38 fi 39 if [ -r $PID_FILE ] ; then 40 mv -f $PID_FILE $PID_BACKUP 41 fi 42 43 # Check if ~/Unrealxxx/unrealircd.conf exists but the file 44 # ~/unrealircd/conf/unrealircd.conf does not. 45 # If so, then assume a user-build and give the user a nice hint... 46 if [ ! -f $CONFDIR/unrealircd.conf -a -f $BUILDDIR/unrealircd.conf ]; then 47 echo "" 48 echo "There is no unrealircd.conf in $CONFDIR" 49 echo "However I did find an unrealircd.conf in $BUILDDIR" 50 echo "With UnrealIRCd 4 you should no longer run the IRCd from $BUILDDIR." 51 echo "You should 'cd $SCRIPTDIR' and work from there." 52 echo "See https://www.unrealircd.org/docs/UnrealIRCd_files_and_directories" 53 exit 1 54 fi 55 if [ ! -f $CONFDIR/unrealircd.conf ]; then 56 echo "" 57 echo "The configuration file does not exist ($CONFDIR/unrealircd.conf)." 58 echo "Create one using the example configuration file, see the documentation:" 59 echo "https://www.unrealircd.org/docs/Installing_from_source#Creating_a_configuration_file" 60 exit 1 61 fi 62 63 echo "Starting UnrealIRCd" 64 65 $IRCD 66 if [ $? -ne 0 ] ; then 67 if [ -r $PID_BACKUP ] ; then 68 mv -f $PID_BACKUP $PID_FILE 69 fi 70 # Try to be helpful... 71 if ldd $IRCD 2>&1|grep -qF '=> not found'; then 72 echo "========================================================" 73 echo "UnrealIRCd failed to start due to missing libraries." 74 echo "Maybe you need to recompile UnrealIRCd? See" 75 echo "https://www.unrealircd.org/docs/FAQ#shared-library-error" 76 echo "========================================================" 77 else 78 echo "=====================================================" 79 echo "UnrealIRCd failed to start. Check above for possible errors." 80 echo "If you don't understand the problem, then have a look at our:" 81 echo "* FAQ (Frequently Asked Questions): https://www.unrealircd.org/docs/FAQ" 82 echo "* Documentation: https://www.unrealircd.org/docs/" 83 echo "=====================================================" 84 fi 85 exit 1 86 fi 87 # Now check if we need to create a crash report. 88 $IRCD -R 89 elif [ "$1" = "stop" ] ; then 90 echo -n "Stopping UnrealIRCd" 91 if [ ! -r $PID_FILE ] ; then 92 echo 93 echo "ERROR: UnrealIRCd is not running" 94 exit 1 95 fi 96 kill -15 `cat $PID_FILE` 97 if [ "$?" != 0 ]; then 98 echo 99 echo "ERROR: UnrealIRCd is not running" 100 exit 1 101 fi 102 # Wait for UnrealIRCd to terminate, but wait 10 seconds max 103 n="0" 104 while [ "$n" -lt 10 ] 105 do 106 echo -n "." 107 if [ ! -r $PID_FILE ] ; then 108 break 109 fi 110 if ! kill -0 `cat $PID_FILE`; then 111 break 112 fi 113 n=`expr $n + 1` 114 sleep 1 115 done 116 echo 117 # In case it is still running, kill it for good. 118 if [ -r $PID_FILE ] ; then 119 kill -9 `cat $PID_FILE` 1>/dev/null 2>&1 120 fi 121 elif [ "$1" = "rehash" ] ; then 122 $UNREALIRCDCTL $* 123 elif [ "$1" = "status" ] ; then 124 $UNREALIRCDCTL $* 125 elif [ "$1" = "module-status" ] ; then 126 $UNREALIRCDCTL $* 127 elif [ "$1" = "reloadtls" ] ; then 128 $UNREALIRCDCTL $* 129 elif [ "$1" = "restart" ] ; then 130 echo "Validating configuration..." 131 TMPF="$TMPDIR/configtest.txt" 132 if ! $0 configtest 1>$TMPF 2>&1; then 133 cat $TMPF 134 rm -f $TMPF 135 echo "" 136 echo "Configuration test failed. Server is NOT restarted." 137 exit 1 138 fi 139 echo "Configuration test OK." 140 $0 stop 141 $0 start 142 elif [ "$1" = "croncheck" ] ; then 143 if [ -r $PID_FILE ] ; then 144 kill -CHLD `cat $PID_FILE` 1>/dev/null 2>&1 145 if [ "$?" = 0 ]; then 146 # IRCd is running, bail out silently. 147 exit 0 148 fi 149 fi 150 # PID file not found or found but stale 151 echo "UnrealIRCd is not running. Starting now..." 152 $0 start 153 elif [ "$1" = "configtest" ] ; then 154 $IRCD -c 155 elif [ "$1" = "module" ] ; then 156 shift 157 $IRCD -m $* 158 elif [ "$1" = "mkpasswd" ] ; then 159 $UNREALIRCDCTL $* 160 elif [ "$1" = "version" ] ; then 161 $IRCD -v 162 elif [ "$1" = "gencloak" ] ; then 163 $UNREALIRCDCTL $* 164 elif [ "$1" = "backtrace" ] ; then 165 cd $TMPDIR 166 167 # Find the corefile 168 echo "Core files available:" 169 n="0" 170 for i in `echo *core*` 171 do 172 ls -l $i 173 n=`expr $n + 1` 174 done 175 176 if [ "$n" -gt 1 ]; then 177 echo "Type the name of the core file you want to research:" 178 read corefile 179 elif [ "$i" = "*core*" -o "$n" -eq 0 ]; then 180 echo 'No core files found... Nothing to do' 181 echo '' 182 echo 'If you are sure UnrealIRCd crashed, then verify that unreal' 183 echo 'has permission to dump core (type "ulimit -c unlimited" and see' 184 echo 'if you get permission denied errors). Also verify that you did' 185 echo 'not run out of quota.' 186 echo 'If all that is ok, then it might be that UnrealIRCd did not crash but' 187 echo 'got killed by the OS (eg: cpu/mem resource limits), the syadmin,' 188 echo 'or an automated process.' 189 exit 1 190 else 191 corefile="$i" 192 fi 193 194 if [ ! -f "$corefile" ]; then 195 echo "Core file '$corefile' not found" 196 fi 197 if [ ! -s "$corefile" ]; then 198 echo 'Seems the corefile is 0 bytes' 199 echo 'This usually means you need to relax the core file resource limit' 200 echo '(type "ulimit -c unlimited"), or you might have ran out of quota.' 201 exit 1 202 fi 203 204 # This is needed for the script below and is probably also helpful for the 205 # bug report since you usually want to paste this to the development team. 206 export LANG=C 207 export LC_ALL=C 208 209 # The tmp/*.so files are often already deleted. Here we have some 210 # (ugly) scripting to recreate the tmp/*.so links to the modules *.so files... 211 echo 'info sharedlibrary'|gdb $IRCD $corefile 2>/dev/null|\ 212 grep No|grep tmp/|awk '{ print $2 }'|\ 213 awk -F '.' "{ system(\"[ -f $MODULESDIR/\" \$2 \"/\" \$3 \".so ] && ln -s $MODULESDIR/\" \$2 \"/\" \$3 \".so \" \$0 \" || ln -s $MODULESDIR/\" \$2 \".so \" \$0) }" 214 215 echo "" 216 echo "=================== START HERE ======================" 217 echo "BACKTRACE:" 218 219 cat >$TMPDIR/gdb.commands << __EOF__ 220 bt 221 echo \n 222 frame 223 echo \n 224 x/s backupbuf 225 echo \n 226 bt 3 full 227 quit 228 __EOF__ 229 230 gdb -batch -x $TMPDIR/gdb.commands $IRCD $corefile 231 rm -f $TMPDIR/gdb.commands 232 echo "GCC: `gcc -v 2>&1|tail -n 1`" 233 echo "UNAME: `uname -a`" 234 echo "UNREAL: `$0 version`" 235 echo "CORE: `ls -al $corefile`" 236 echo "=================== STOP HERE ======================" 237 echo "" 238 echo "Copy the parts between the START HERE and STOP HERE marker" 239 echo "and report it on https://bugs.unrealircd.org/" 240 echo "" 241 echo 'But before you do, note the following:' 242 echo '1. We do not support modifications of any unrealircd code' 243 echo ' (except for config.h changes).' 244 echo '2. If you are using 3rd party modules we might request you' 245 echo ' to run without them and verify you still crash. This is' 246 echo ' to eleminate any loss of time due to bugs made by others' 247 echo '3. Use a reasonably recent UnrealIRCd version. We fix (crash)bugs' 248 echo ' all the time so your bug might as well be fixed already.' 249 echo "" 250 echo "Thanks!" 251 elif [ "$1" = "spki" -o "$1" = "spkifp" ] ; then 252 $UNREALIRCDCTL $* 253 elif [ "$1" = "hot-patch" -o "$1" = "cold-patch" ] ; then 254 if [ ! -d "$BUILDDIR" ]; then 255 echo "UnrealIRCd source not found. Sorry, it is not possible to patch." 256 exit 1 257 fi 258 if [ "$2" = "" ]; then 259 echo "Argument required: ./unrealircd <hot-patch|cold-patch> <name-of-patch>" 260 exit 1 261 fi 262 if ! wget --help 1>/dev/null 2>&1; then 263 echo "The tool 'wget' is missing, which is used by this script." 264 echo "On Linux consider running 'apt install wget' or a similar command." 265 exit 1 266 fi 267 cd "$BUILDDIR" || exit 1 268 269 # Weird way to get version, but ok. 270 UNREALVER="`./configure --version|head -n1|awk '{ print $3 }'`" 271 wget -O patch "https://www.unrealircd.org/patch?type=$1&patch=$2&version=$UNREALVER" || exit 1 272 273 # A patch file of 0 bytes means the patch is not needed 274 if [ -f patch -a ! -s patch ]; then 275 echo "This UnrealIRCd version does not require that patch" 276 fi 277 278 if patch --dry-run -p1 -R <patch 1>/dev/null 2>&1; then 279 echo "Patch already applied. Nothing to do." 280 exit 1 281 fi 282 283 if ! patch --dry-run -p1 -N <patch 1>/dev/null 2>&1; then 284 echo "Patch failed to apply (no files changed)" 285 exit 1 286 fi 287 288 if ! patch -p1 <patch; then 289 echo "Patch failed to apply" 290 exit 1 291 fi 292 293 echo "Patch applied successfully. Now recompiling..." 294 make || gmake || exit 1 295 make install || gmake install || exit 1 296 297 cd $SCRIPTDIR 298 if [ "$1" = "hot-patch" ]; then 299 echo "Patch applied successfully and installed. Rehashing your IRCd..." 300 if ./unrealircd rehash; then 301 echo "Patch installed and server rehashed correctly. All should be good now!" 302 else 303 echo "Patching the source code and recompiling succeeded," 304 echo "however rehashing the current UnrealIRCd process FAILED" 305 echo "so it is NOT running the patched code yet." 306 echo "IMPORTANT: Check error output above!" 307 exit 1 308 fi 309 else 310 echo "Patch applied successfully. You must now restart your IRC server." 311 fi 312 elif [ "$1" = "upgrade" ] ; then 313 $BINDIR/unrealircd-upgrade-script $* 314 exit 315 elif [ "$1" = "genlinkblock" ] ; then 316 $IRCD -L 317 else 318 if [ "$1" = "" ]; then 319 echo "This script expects a parameter. Use:" 320 else 321 echo "Unrecognized parameter '$1'. Use:" 322 fi 323 echo "unrealircd configtest Test the configuration file" 324 echo "unrealircd start Start the IRC Server" 325 echo "unrealircd stop Stop (kill) the IRC Server" 326 echo "unrealircd rehash Reload the configuration file" 327 echo "unrealircd reloadtls Reload the SSL/TLS certificates" 328 echo "unrealircd restart Restart the IRC Server (stop+start)" 329 echo "unrealircd status Show current status of the IRC Server" 330 echo "unrealircd module-status Show all currently loaded modules" 331 echo "unrealircd upgrade Upgrade UnrealIRCd to the latest version" 332 echo "unrealircd mkpasswd Hash a password" 333 echo "unrealircd version Display the UnrealIRCd version" 334 echo "unrealircd module Install and uninstall 3rd party modules" 335 echo "unrealircd croncheck For use in crontab: this checks if the server" 336 echo " is running. If not, the server is started." 337 echo "unrealircd genlinkblock Generate link { } block for the other side." 338 echo "unrealircd gencloak Display 3 random cloak keys" 339 echo "unrealircd spkifp Display SPKI Fingerprint" 340 fi