]>
Commit | Line | Data |
---|---|---|
29b7ea7e | 1 | #!/bin/sh |
2 | ||
5e94fc9c BM |
3 | PID_FILE="@PIDFILE@" |
4 | PID_BACKUP="@PIDFILE@.bak" | |
4992804f BM |
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@" | |
11507b3f BM |
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. | |
4992804f | 16 | export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0:unmap_shadow_on_exit=1:log_path=$TMPDIR/unrealircd_asan:detect_leaks=0" |
11507b3f | 17 | |
4992804f BM |
18 | if [ ! -f $IRCD ]; then |
19 | echo "ERROR: Could not find the IRCd binary ($IRCD)" | |
5e94fc9c BM |
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" | |
fb68c66f BM |
23 | exit |
24 | fi | |
4992804f BM |
25 | if [ ! -d "$TMPDIR" ]; then |
26 | mkdir "$TMPDIR" | |
27 | fi | |
28 | ||
29b7ea7e | 29 | if [ "$1" = "start" ] ; then |
4992804f BM |
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 | |
133eac27 | 39 | if [ -r $PID_FILE ] ; then |
6ccda4cc | 40 | mv -f $PID_FILE $PID_BACKUP |
41 | fi | |
953cb774 | 42 | |
507d88cf | 43 | # Check if ~/Unrealxxx/unrealircd.conf exists but the file |
bcc95f67 BM |
44 | # ~/unrealircd/conf/unrealircd.conf does not. |
45 | # If so, then assume a user-build and give the user a nice hint... | |
4992804f | 46 | if [ ! -f $CONFDIR/unrealircd.conf -a -f $BUILDDIR/unrealircd.conf ]; then |
bcc95f67 | 47 | echo "" |
4992804f BM |
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." | |
bcc95f67 BM |
52 | echo "See https://www.unrealircd.org/docs/UnrealIRCd_files_and_directories" |
53 | exit 1 | |
54 | fi | |
4992804f | 55 | if [ ! -f $CONFDIR/unrealircd.conf ]; then |
ad23afc8 | 56 | echo "" |
4992804f | 57 | echo "The configuration file does not exist ($CONFDIR/unrealircd.conf)." |
498f65aa BM |
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" | |
ad23afc8 BM |
60 | exit 1 |
61 | fi | |
4992804f BM |
62 | |
63 | echo "Starting UnrealIRCd" | |
64 | ||
65 | $IRCD | |
ad23afc8 | 66 | if [ $? -ne 0 ] ; then |
133eac27 | 67 | if [ -r $PID_BACKUP ] ; then |
68 | mv -f $PID_BACKUP $PID_FILE | |
69 | fi | |
b7f2ce9f | 70 | # Try to be helpful... |
4992804f | 71 | if ldd $IRCD 2>&1|grep -qF '=> not found'; then |
b7f2ce9f BM |
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 | |
2cb39521 | 85 | exit 1 |
6ccda4cc | 86 | fi |
2cb39521 | 87 | # Now check if we need to create a crash report. |
4992804f | 88 | $IRCD -R |
29b7ea7e | 89 | elif [ "$1" = "stop" ] ; then |
61e0ed3d | 90 | echo -n "Stopping UnrealIRCd" |
73c2f817 | 91 | if [ ! -r $PID_FILE ] ; then |
61e0ed3d | 92 | echo |
73c2f817 BM |
93 | echo "ERROR: UnrealIRCd is not running" |
94 | exit 1 | |
95 | fi | |
b1b771c4 BM |
96 | kill -15 `cat $PID_FILE` |
97 | if [ "$?" != 0 ]; then | |
61e0ed3d | 98 | echo |
b1b771c4 BM |
99 | echo "ERROR: UnrealIRCd is not running" |
100 | exit 1 | |
101 | fi | |
61e0ed3d BM |
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. | |
1fc6a0ef | 118 | if [ -r $PID_FILE ] ; then |
119 | kill -9 `cat $PID_FILE` 1>/dev/null 2>&1 | |
120 | fi | |
29b7ea7e | 121 | elif [ "$1" = "rehash" ] ; then |
92c81b19 | 122 | $UNREALIRCDCTL $* |
39688517 | 123 | elif [ "$1" = "status" ] ; then |
92c81b19 | 124 | $UNREALIRCDCTL $* |
f650239b BM |
125 | elif [ "$1" = "module-status" ] ; then |
126 | $UNREALIRCDCTL $* | |
39688517 | 127 | elif [ "$1" = "reloadtls" ] ; then |
92c81b19 | 128 | $UNREALIRCDCTL $* |
2a595d3a | 129 | elif [ "$1" = "restart" ] ; then |
4992804f BM |
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." | |
67deb7ec | 140 | $0 stop |
b1b771c4 | 141 | $0 start |
34285286 BM |
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 | |
fb8055c6 | 153 | elif [ "$1" = "configtest" ] ; then |
4992804f | 154 | $IRCD -c |
dfa83aa6 BM |
155 | elif [ "$1" = "module" ] ; then |
156 | shift | |
4992804f | 157 | $IRCD -m $* |
0171967e | 158 | elif [ "$1" = "mkpasswd" ] ; then |
92c81b19 | 159 | $UNREALIRCDCTL $* |
e7c7909d | 160 | elif [ "$1" = "version" ] ; then |
4992804f | 161 | $IRCD -v |
c20f7850 | 162 | elif [ "$1" = "gencloak" ] ; then |
92c81b19 | 163 | $UNREALIRCDCTL $* |
5fcd80e1 | 164 | elif [ "$1" = "backtrace" ] ; then |
4992804f | 165 | cd $TMPDIR |
5fcd80e1 BM |
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.' | |
a565a68f | 186 | echo 'If all that is ok, then it might be that UnrealIRCd did not crash but' |
5fcd80e1 BM |
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 | ||
6fcacdf1 BM |
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 | ||
564eef16 BM |
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... | |
4992804f | 211 | echo 'info sharedlibrary'|gdb $IRCD $corefile 2>/dev/null|\ |
564eef16 | 212 | grep No|grep tmp/|awk '{ print $2 }'|\ |
4992804f | 213 | awk -F '.' "{ system(\"[ -f $MODULESDIR/\" \$2 \"/\" \$3 \".so ] && ln -s $MODULESDIR/\" \$2 \"/\" \$3 \".so \" \$0 \" || ln -s $MODULESDIR/\" \$2 \".so \" \$0) }" |
5fcd80e1 BM |
214 | |
215 | echo "" | |
216 | echo "=================== START HERE ======================" | |
217 | echo "BACKTRACE:" | |
218 | ||
4992804f | 219 | cat >$TMPDIR/gdb.commands << __EOF__ |
5fcd80e1 BM |
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 | ||
4992804f BM |
230 | gdb -batch -x $TMPDIR/gdb.commands $IRCD $corefile |
231 | rm -f $TMPDIR/gdb.commands | |
5fcd80e1 BM |
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" | |
91e10849 | 239 | echo "and report it on https://bugs.unrealircd.org/" |
5fcd80e1 BM |
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' | |
2375c35f | 247 | echo '3. Use a reasonably recent UnrealIRCd version. We fix (crash)bugs' |
5fcd80e1 BM |
248 | echo ' all the time so your bug might as well be fixed already.' |
249 | echo "" | |
250 | echo "Thanks!" | |
9e1160b7 | 251 | elif [ "$1" = "spki" -o "$1" = "spkifp" ] ; then |
92c81b19 | 252 | $UNREALIRCDCTL $* |
ffd0acf5 | 253 | elif [ "$1" = "hot-patch" -o "$1" = "cold-patch" ] ; then |
4992804f | 254 | if [ ! -d "$BUILDDIR" ]; then |
ffd0acf5 BM |
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 | |
4992804f | 267 | cd "$BUILDDIR" || exit 1 |
ffd0acf5 BM |
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 | ||
17913151 BM |
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 | ||
ffd0acf5 BM |
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 | ||
4992804f | 297 | cd $SCRIPTDIR |
ffd0acf5 BM |
298 | if [ "$1" = "hot-patch" ]; then |
299 | echo "Patch applied successfully and installed. Rehashing your IRCd..." | |
fa15ea25 BM |
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 | |
ffd0acf5 BM |
309 | else |
310 | echo "Patch applied successfully. You must now restart your IRC server." | |
311 | fi | |
0e125abc | 312 | elif [ "$1" = "upgrade" ] ; then |
4992804f | 313 | $BINDIR/unrealircd-upgrade-script $* |
73be662d | 314 | exit |
870057d4 | 315 | elif [ "$1" = "genlinkblock" ] ; then |
4992804f | 316 | $IRCD -L |
ede774f5 VL |
317 | elif [ "$1" = "coffee" ] ; then |
318 | echo "Checking for ingredients..." | |
319 | sleep 1 | |
320 | echo "Running make && make coffee" | |
321 | echo "make coffee[1] Adding coffee to coffee grinder..." | |
322 | echo "make coffee[2] Grinding coffee..." | |
323 | sleep 2 | |
324 | echo "make coffee[3] Pre-heating french press..." | |
325 | sleep 3 | |
326 | echo "make coffee[4] Adding ground coffee to press..."; | |
327 | echo "make coffee[5] Saturating..." | |
328 | sleep 2 | |
329 | echo "make coffee[6] Securing lid..." | |
330 | echo "" | |
331 | echo "Do you want sugar? (Y/N)" | |
332 | read sugar | |
333 | echo "Do you want milk/cream? (Y/N)" | |
334 | read cream | |
335 | ||
336 | sugarc="-no-sugar " | |
337 | creamc="-no-cream " | |
338 | if [ "$sugar" = "Y" ] || [ "$sugar" = "y" ] ; then | |
339 | sugarc="-with-sugar " | |
340 | fi | |
341 | if [ "$cream" = "Y" ] || [ "$cream" = "y" ] ; then | |
342 | creamc="-with-cream " | |
343 | fi | |
344 | echo "Please wait while your coffee is being prepared..." | |
345 | echo "gcc $sugarc$creamc-Wno-format-overflow -fno-strict-overflow -be-careful-its-hot coffee.c" | |
346 | sleep 4 | |
347 | echo " {" | |
348 | echo " } } {" | |
349 | echo " { { } }" | |
350 | echo " } }{ {" | |
351 | echo " { }{ } }" | |
352 | echo " ( }{ }{ { )" | |
353 | echo " .- { { } { }} -." | |
354 | echo " ( ( } { } { } } )" | |
355 | echo " |\`-..________ ..-'|" | |
356 | echo " | |" | |
357 | echo " | ;--." | |
358 | echo " | (__ \\ " | |
359 | echo " | | ) )" | |
360 | echo " | |/ /" | |
361 | echo " | ( /" | |
362 | echo " | y'" | |
363 | echo " | |" | |
364 | echo " \`-.._________..-' Enjoy!" | |
365 | echo "" | |
29b7ea7e | 366 | else |
ffd0acf5 BM |
367 | if [ "$1" = "" ]; then |
368 | echo "This script expects a parameter. Use:" | |
369 | else | |
370 | echo "Unrecognized parameter '$1'. Use:" | |
371 | fi | |
dfa83aa6 BM |
372 | echo "unrealircd configtest Test the configuration file" |
373 | echo "unrealircd start Start the IRC Server" | |
374 | echo "unrealircd stop Stop (kill) the IRC Server" | |
375 | echo "unrealircd rehash Reload the configuration file" | |
0e125abc | 376 | echo "unrealircd reloadtls Reload the SSL/TLS certificates" |
dfa83aa6 | 377 | echo "unrealircd restart Restart the IRC Server (stop+start)" |
cd3b50d2 BM |
378 | echo "unrealircd status Show current status of the IRC Server" |
379 | echo "unrealircd module-status Show all currently loaded modules" | |
0e125abc | 380 | echo "unrealircd upgrade Upgrade UnrealIRCd to the latest version" |
dfa83aa6 BM |
381 | echo "unrealircd mkpasswd Hash a password" |
382 | echo "unrealircd version Display the UnrealIRCd version" | |
383 | echo "unrealircd module Install and uninstall 3rd party modules" | |
384 | echo "unrealircd croncheck For use in crontab: this checks if the server" | |
385 | echo " is running. If not, the server is started." | |
29e8c2c7 | 386 | echo "unrealircd genlinkblock Generate link { } block for the other side." |
dfa83aa6 BM |
387 | echo "unrealircd gencloak Display 3 random cloak keys" |
388 | echo "unrealircd spkifp Display SPKI Fingerprint" | |
29b7ea7e | 389 | fi |