Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. collectCrashReport() {
  4. # teleport to cache dir
  5. cd /mnt/cache
  6. # remove any previous report
  7. rm -rf crash/crashreport_*
  8. # create report directory
  9. directory=crashreport_`cat /etc/hostname`_$(date +%Y%m%d%H%M%S)
  10. mkdir $directory
  11. cd $directory
  12. # snatch all the logs
  13. cp -r /var/log/ .
  14. ps --no-headers -ax > processes.dump
  15. # dump dmesg to file
  16. dmesg > dmesg.dump
  17. # create crash dir
  18. mkdir crash
  19. # zip the whole thing
  20. zip -qr /mnt/cache/crash/"$directory.zip" .
  21. # remove collection dir
  22. rm -rf /mnt/cache/crashreport_*
  23. # done and done
  24. }
  25.  
  26. # check if already running and kill
  27. PIDFILE=/var/run/crashcollector.pid
  28. # check if already running
  29. if [ -f $PIDFILE ]; then
  30. kill `cat $PIDFILE`
  31. fi
  32. echo $$ > $PIDFILE
  33.  
  34. cleanup() {
  35. rm -f $PIDFILE
  36. exit 0
  37. }
  38. # trap them signals
  39. trap "cleanup" INT TERM EXIT
  40.  
  41. that_awesome_pipe="CCPipe"
  42. [ -p $that_awesome_pipe ] || mkfifo $that_awesome_pipe
  43. chmod 766 $that_awesome_pipe
  44. while :; do
  45. if read line; then
  46. case $line in
  47. "collect")
  48. collectCrashReport
  49. ;;
  50. *)
  51. log "Received bad command $line, ignoring..."
  52. ;;
  53. esac
  54. fi
  55. done <"$that_awesome_pipe"
  56.  
  57. [Unit]
  58. Description=Crash report collector
  59. After=network.target
  60.  
  61. [Service]
  62. Type=simple
  63. ExecStart=/usr/bin/crashCollector
  64. ExecStop=/usr/bin/kill -9 `cat /var/run/crashcollector.pid`
  65. KillMode=process
  66. Restart=always
  67. RestartSec=3
  68.  
  69. [Install]
  70. WantedBy=multi-user.target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement