4
mirror of git://git.acid.vegas/unrealircd.git synced 2024-12-26 00:06:38 +00:00
unrealircd/unrealircd.in

341 lines
11 KiB
Plaintext
Raw Normal View History

2020-03-29 09:16:53 +00:00
#!/bin/sh
PID_FILE="@PIDFILE@"
PID_BACKUP="@PIDFILE@.bak"
2023-05-05 22:12:01 +00:00
BINDIR="@BINDIR@"
UNREALIRCDCTL="$BINDIR/unrealircdctl"
IRCD="$BINDIR/unrealircd"
BUILDDIR="@BUILDDIR@"
CONFDIR="@CONFDIR@"
TMPDIR="@TMPDIR@"
SCRIPTDIR="@SCRIPTDIR@"
MODULESDIR="@MODULESDIR@"
2022-01-15 05:16:34 +00:00
# When built with --with-asan, ASan does not dump core by default because
# older gcc/clang might dump a 16TB core file. We explicitly enable it here.
2023-05-05 22:12:01 +00:00
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0:unmap_shadow_on_exit=1:log_path=$TMPDIR/unrealircd_asan:detect_leaks=0"
2022-01-15 05:16:34 +00:00
2023-05-05 22:12:01 +00:00
if [ ! -f $IRCD ]; then
echo "ERROR: Could not find the IRCd binary ($IRCD)"
2020-03-29 09:16:53 +00:00
echo "This could mean two things:"
echo "1) You forgot to run 'make install' after running 'make'"
echo "2) You answered a ./Config question incorrectly"
exit
fi
2023-05-05 22:12:01 +00:00
if [ ! -d "$TMPDIR" ]; then
mkdir "$TMPDIR"
fi
2020-03-29 09:16:53 +00:00
if [ "$1" = "start" ] ; then
2023-05-05 22:12:01 +00:00
if [ -r $PID_FILE ] ; then
if kill -CHLD `cat $PID_FILE` 1>/dev/null 2>&1; then
if $UNREALIRCDCTL status 1>/dev/null 2>&1; then
echo "UnrealIRCd is already running (PID `cat $PID_FILE`)."
echo "To restart UnrealIRCd, use: $0 restart"
exit 1
fi
fi
fi
2020-03-29 09:16:53 +00:00
if [ -r $PID_FILE ] ; then
mv -f $PID_FILE $PID_BACKUP
fi
# Check if ~/Unrealxxx/unrealircd.conf exists but the file
# ~/unrealircd/conf/unrealircd.conf does not.
# If so, then assume a user-build and give the user a nice hint...
2023-05-05 22:12:01 +00:00
if [ ! -f $CONFDIR/unrealircd.conf -a -f $BUILDDIR/unrealircd.conf ]; then
2020-03-29 09:16:53 +00:00
echo ""
2023-05-05 22:12:01 +00:00
echo "There is no unrealircd.conf in $CONFDIR"
echo "However I did find an unrealircd.conf in $BUILDDIR"
echo "With UnrealIRCd 4 you should no longer run the IRCd from $BUILDDIR."
echo "You should 'cd $SCRIPTDIR' and work from there."
2020-03-29 09:16:53 +00:00
echo "See https://www.unrealircd.org/docs/UnrealIRCd_files_and_directories"
exit 1
fi
2023-05-05 22:12:01 +00:00
if [ ! -f $CONFDIR/unrealircd.conf ]; then
2020-03-29 09:16:53 +00:00
echo ""
2023-05-05 22:12:01 +00:00
echo "The configuration file does not exist ($CONFDIR/unrealircd.conf)."
2020-04-20 19:12:33 +00:00
echo "Create one using the example configuration file, see the documentation:"
echo "https://www.unrealircd.org/docs/Installing_from_source#Creating_a_configuration_file"
2020-03-29 09:16:53 +00:00
exit 1
fi
2023-05-05 22:12:01 +00:00
echo "Starting UnrealIRCd"
$IRCD
2020-03-29 09:16:53 +00:00
if [ $? -ne 0 ] ; then
if [ -r $PID_BACKUP ] ; then
mv -f $PID_BACKUP $PID_FILE
fi
2023-05-05 22:12:01 +00:00
# Try to be helpful...
if ldd $IRCD 2>&1|grep -qF '=> not found'; then
echo "========================================================"
echo "UnrealIRCd failed to start due to missing libraries."
echo "Maybe you need to recompile UnrealIRCd? See"
echo "https://www.unrealircd.org/docs/FAQ#shared-library-error"
echo "========================================================"
else
echo "====================================================="
echo "UnrealIRCd failed to start. Check above for possible errors."
echo "If you don't understand the problem, then have a look at our:"
echo "* FAQ (Frequently Asked Questions): https://www.unrealircd.org/docs/FAQ"
echo "* Documentation: https://www.unrealircd.org/docs/"
echo "====================================================="
fi
2020-03-29 09:16:53 +00:00
exit 1
fi
# Now check if we need to create a crash report.
2023-05-05 22:12:01 +00:00
$IRCD -R
2020-03-29 09:16:53 +00:00
elif [ "$1" = "stop" ] ; then
2021-06-19 15:52:51 +00:00
echo -n "Stopping UnrealIRCd"
2020-03-29 09:16:53 +00:00
if [ ! -r $PID_FILE ] ; then
2021-06-19 15:52:51 +00:00
echo
2020-03-29 09:16:53 +00:00
echo "ERROR: UnrealIRCd is not running"
exit 1
fi
kill -15 `cat $PID_FILE`
if [ "$?" != 0 ]; then
2021-06-19 15:52:51 +00:00
echo
2020-03-29 09:16:53 +00:00
echo "ERROR: UnrealIRCd is not running"
exit 1
fi
2021-06-19 15:52:51 +00:00
# Wait for UnrealIRCd to terminate, but wait 10 seconds max
n="0"
while [ "$n" -lt 10 ]
do
echo -n "."
if [ ! -r $PID_FILE ] ; then
break
fi
if ! kill -0 `cat $PID_FILE`; then
break
fi
n=`expr $n + 1`
sleep 1
done
echo
# In case it is still running, kill it for good.
2020-03-29 09:16:53 +00:00
if [ -r $PID_FILE ] ; then
kill -9 `cat $PID_FILE` 1>/dev/null 2>&1
fi
elif [ "$1" = "rehash" ] ; then
2022-04-03 15:09:29 +00:00
$UNREALIRCDCTL $*
elif [ "$1" = "status" ] ; then
$UNREALIRCDCTL $*
elif [ "$1" = "module-status" ] ; then
$UNREALIRCDCTL $*
elif [ "$1" = "reloadtls" ] ; then
$UNREALIRCDCTL $*
2020-03-29 09:16:53 +00:00
elif [ "$1" = "restart" ] ; then
2023-05-05 22:12:01 +00:00
echo "Validating configuration..."
TMPF="$TMPDIR/configtest.txt"
if ! $0 configtest 1>$TMPF 2>&1; then
cat $TMPF
rm -f $TMPF
echo ""
echo "Configuration test failed. Server is NOT restarted."
exit 1
fi
echo "Configuration test OK."
2021-06-19 15:52:51 +00:00
$0 stop
2020-03-29 09:16:53 +00:00
$0 start
elif [ "$1" = "croncheck" ] ; then
if [ -r $PID_FILE ] ; then
kill -CHLD `cat $PID_FILE` 1>/dev/null 2>&1
if [ "$?" = 0 ]; then
# IRCd is running, bail out silently.
exit 0
fi
fi
# PID file not found or found but stale
echo "UnrealIRCd is not running. Starting now..."
$0 start
elif [ "$1" = "configtest" ] ; then
2023-05-05 22:12:01 +00:00
$IRCD -c
2020-03-29 09:16:53 +00:00
elif [ "$1" = "module" ] ; then
shift
2023-05-05 22:12:01 +00:00
$IRCD -m $*
2020-03-29 09:16:53 +00:00
elif [ "$1" = "mkpasswd" ] ; then
2022-04-03 15:09:29 +00:00
$UNREALIRCDCTL $*
2020-03-29 09:16:53 +00:00
elif [ "$1" = "version" ] ; then
2023-05-05 22:12:01 +00:00
$IRCD -v
2020-03-29 09:16:53 +00:00
elif [ "$1" = "gencloak" ] ; then
2022-04-03 15:09:29 +00:00
$UNREALIRCDCTL $*
2020-03-29 09:16:53 +00:00
elif [ "$1" = "backtrace" ] ; then
2023-05-05 22:12:01 +00:00
cd $TMPDIR
2020-03-29 09:16:53 +00:00
# Find the corefile
echo "Core files available:"
n="0"
for i in `echo *core*`
do
ls -l $i
n=`expr $n + 1`
done
if [ "$n" -gt 1 ]; then
echo "Type the name of the core file you want to research:"
read corefile
elif [ "$i" = "*core*" -o "$n" -eq 0 ]; then
echo 'No core files found... Nothing to do'
echo ''
echo 'If you are sure UnrealIRCd crashed, then verify that unreal'
echo 'has permission to dump core (type "ulimit -c unlimited" and see'
echo 'if you get permission denied errors). Also verify that you did'
echo 'not run out of quota.'
echo 'If all that is ok, then it might be that UnrealIRCd did not crash but'
echo 'got killed by the OS (eg: cpu/mem resource limits), the syadmin,'
echo 'or an automated process.'
exit 1
else
corefile="$i"
fi
if [ ! -f "$corefile" ]; then
echo "Core file '$corefile' not found"
fi
if [ ! -s "$corefile" ]; then
echo 'Seems the corefile is 0 bytes'
echo 'This usually means you need to relax the core file resource limit'
echo '(type "ulimit -c unlimited"), or you might have ran out of quota.'
exit 1
fi
# This is needed for the script below and is probably also helpful for the
# bug report since you usually want to paste this to the development team.
export LANG=C
export LC_ALL=C
# The tmp/*.so files are often already deleted. Here we have some
# (ugly) scripting to recreate the tmp/*.so links to the modules *.so files...
2023-05-05 22:12:01 +00:00
echo 'info sharedlibrary'|gdb $IRCD $corefile 2>/dev/null|\
2020-03-29 09:16:53 +00:00
grep No|grep tmp/|awk '{ print $2 }'|\
2023-05-05 22:12:01 +00:00
awk -F '.' "{ system(\"[ -f $MODULESDIR/\" \$2 \"/\" \$3 \".so ] && ln -s $MODULESDIR/\" \$2 \"/\" \$3 \".so \" \$0 \" || ln -s $MODULESDIR/\" \$2 \".so \" \$0) }"
2020-03-29 09:16:53 +00:00
echo ""
echo "=================== START HERE ======================"
echo "BACKTRACE:"
2023-05-05 22:12:01 +00:00
cat >$TMPDIR/gdb.commands << __EOF__
2020-03-29 09:16:53 +00:00
bt
echo \n
frame
echo \n
x/s backupbuf
echo \n
bt 3 full
quit
__EOF__
2023-05-05 22:12:01 +00:00
gdb -batch -x $TMPDIR/gdb.commands $IRCD $corefile
rm -f $TMPDIR/gdb.commands
2020-03-29 09:16:53 +00:00
echo "GCC: `gcc -v 2>&1|tail -n 1`"
echo "UNAME: `uname -a`"
echo "UNREAL: `$0 version`"
echo "CORE: `ls -al $corefile`"
echo "=================== STOP HERE ======================"
echo ""
echo "Copy the parts between the START HERE and STOP HERE marker"
echo "and report it on https://bugs.unrealircd.org/"
echo ""
echo 'But before you do, note the following:'
echo '1. We do not support modifications of any unrealircd code'
echo ' (except for config.h changes).'
echo '2. If you are using 3rd party modules we might request you'
echo ' to run without them and verify you still crash. This is'
echo ' to eleminate any loss of time due to bugs made by others'
2021-06-19 15:52:51 +00:00
echo '3. Use a reasonably recent UnrealIRCd version. We fix (crash)bugs'
2020-03-29 09:16:53 +00:00
echo ' all the time so your bug might as well be fixed already.'
echo ""
echo "Thanks!"
elif [ "$1" = "spki" -o "$1" = "spkifp" ] ; then
2022-04-03 15:09:29 +00:00
$UNREALIRCDCTL $*
2020-03-29 09:16:53 +00:00
elif [ "$1" = "hot-patch" -o "$1" = "cold-patch" ] ; then
2023-05-05 22:12:01 +00:00
if [ ! -d "$BUILDDIR" ]; then
2020-03-29 09:16:53 +00:00
echo "UnrealIRCd source not found. Sorry, it is not possible to patch."
exit 1
fi
if [ "$2" = "" ]; then
echo "Argument required: ./unrealircd <hot-patch|cold-patch> <name-of-patch>"
exit 1
fi
if ! wget --help 1>/dev/null 2>&1; then
echo "The tool 'wget' is missing, which is used by this script."
echo "On Linux consider running 'apt install wget' or a similar command."
exit 1
fi
2023-05-05 22:12:01 +00:00
cd "$BUILDDIR" || exit 1
2020-03-29 09:16:53 +00:00
# Weird way to get version, but ok.
UNREALVER="`./configure --version|head -n1|awk '{ print $3 }'`"
wget -O patch "https://www.unrealircd.org/patch?type=$1&patch=$2&version=$UNREALVER" || exit 1
# A patch file of 0 bytes means the patch is not needed
if [ -f patch -a ! -s patch ]; then
echo "This UnrealIRCd version does not require that patch"
fi
if patch --dry-run -p1 -R <patch 1>/dev/null 2>&1; then
echo "Patch already applied. Nothing to do."
exit 1
fi
2022-04-03 15:09:29 +00:00
if ! patch --dry-run -p1 -N <patch 1>/dev/null 2>&1; then
echo "Patch failed to apply (no files changed)"
exit 1
fi
2020-03-29 09:16:53 +00:00
if ! patch -p1 <patch; then
echo "Patch failed to apply"
exit 1
fi
echo "Patch applied successfully. Now recompiling..."
make || gmake || exit 1
make install || gmake install || exit 1
2023-05-05 22:12:01 +00:00
cd $SCRIPTDIR
2020-03-29 09:16:53 +00:00
if [ "$1" = "hot-patch" ]; then
echo "Patch applied successfully and installed. Rehashing your IRCd..."
2022-04-03 15:09:29 +00:00
if ./unrealircd rehash; then
echo "Patch installed and server rehashed correctly. All should be good now!"
else
echo "Patching the source code and recompiling succeeded,"
echo "however rehashing the current UnrealIRCd process FAILED"
echo "so it is NOT running the patched code yet."
echo "IMPORTANT: Check error output above!"
exit 1
fi
2020-03-29 09:16:53 +00:00
else
echo "Patch applied successfully. You must now restart your IRC server."
fi
2021-03-21 17:05:35 +00:00
elif [ "$1" = "upgrade" ] ; then
2023-05-05 22:12:01 +00:00
$BINDIR/unrealircd-upgrade-script $*
2022-01-15 05:16:34 +00:00
exit
2020-03-29 09:16:53 +00:00
elif [ "$1" = "genlinkblock" ] ; then
2023-05-05 22:12:01 +00:00
$IRCD -L
2020-03-29 09:16:53 +00:00
else
if [ "$1" = "" ]; then
echo "This script expects a parameter. Use:"
else
echo "Unrecognized parameter '$1'. Use:"
fi
echo "unrealircd configtest Test the configuration file"
echo "unrealircd start Start the IRC Server"
echo "unrealircd stop Stop (kill) the IRC Server"
echo "unrealircd rehash Reload the configuration file"
2021-03-21 17:05:35 +00:00
echo "unrealircd reloadtls Reload the SSL/TLS certificates"
2020-03-29 09:16:53 +00:00
echo "unrealircd restart Restart the IRC Server (stop+start)"
2022-04-03 15:09:29 +00:00
echo "unrealircd status Show current status of the IRC Server"
echo "unrealircd module-status Show all currently loaded modules"
2021-03-21 17:05:35 +00:00
echo "unrealircd upgrade Upgrade UnrealIRCd to the latest version"
2020-03-29 09:16:53 +00:00
echo "unrealircd mkpasswd Hash a password"
echo "unrealircd version Display the UnrealIRCd version"
echo "unrealircd module Install and uninstall 3rd party modules"
echo "unrealircd croncheck For use in crontab: this checks if the server"
echo " is running. If not, the server is started."
2021-03-21 17:05:35 +00:00
echo "unrealircd genlinkblock Generate link { } block for the other side."
2020-03-29 09:16:53 +00:00
echo "unrealircd gencloak Display 3 random cloak keys"
echo "unrealircd spkifp Display SPKI Fingerprint"
fi