Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2012
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.97 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## SYNOPSIS ##
  4. #
  5. # Based on http://wiki.natenom.name/mumble/tools/mumble-db-tmpfs
  6. #
  7. # This scripts copies your mumble database and log from a backup directory into a tmpfs and dumps them with unmount
  8. # switching between two ini files so mumble could run from ram and from sd as well.
  9. # I decided to put the log file too in the ram disk because the life span of a SD card is severely related to the write cycles.
  10. # You can run this script on boot/shutdown (google a bit to know how)
  11. #
  12. # Run this script as a SuperUser
  13. #
  14. # A big thank to Natenom!
  15.  
  16.  
  17. ## PREPARATION ##
  18. #
  19. # Make a directory where tmpfs will be mounted (i.e. /var/tmp/ or /home/pi/tmpfs/)
  20. #
  21. # In /etc/ make two copies of your mumble-server.ini named mumble-server.ram and mumble-server.sd
  22. # in the first one you have to replace the path in "database=" and "logfile=" with your tmpfs directory
  23. # in the second one set your backup directory path
  24. #
  25. # Now copy your database and log files in the backup directory (you can find their location in the original .ini file)
  26. #
  27. # It's good if you make a backup of mumble-server.ini and mumble-server.sqlite
  28.  
  29.  
  30.  
  31. _tmpfs_dir="[tmpfs location]"                   # Must be the same as database="[path of file] and logfile=[path of file] in mumble-server.ram
  32. _database_backup_dir="[backup location]"        # The same path as in mumble-server.sd
  33. _mumble_ini_dir="/etc"                          # *.ini file location. /etc by default
  34. _owner="mumble-server"                          # Name of the user the mumble-server runs as (to set file permissions), you can get it from mumble-server.ini
  35.  
  36. case $1 in
  37.   start)
  38.       if [ "$(mount | grep ${_tmpfs_dir})" != "" ]; then        # Checking if _tmpfs_dir is already mounted... you have to use an empty ramdisk, this script may unmount
  39.           echo "tmpfs partition already exists. Script halted." # the partition causing data loss if other process uses the same tmpfs!
  40.       else
  41.  
  42.           echo "${_tmpfs_dir} is not mounted. Mounting..."
  43.           mount tmpfs -t tmpfs "${_tmpfs_dir}"                  # Mounting tmpfs in _tmpfs_dir
  44.  
  45.           #if you use debian < 6.x, remove -n
  46.           cp ${_mumble_ini_dir}/mumble-server.ram ${_mumble_ini_dir}/mumble-server.ini  # Using mumble-server.ram as *.ini file
  47.           cp -n ${_database_backup_dir}/mumble-server.sqlite ${_tmpfs_dir}/             # Putting database and logfile in the tmpfs
  48.           cp -n ${_database_backup_dir}/mumble-server.log ${_tmpfs_dir}/
  49.  
  50.           chown ${_owner} ${_tmpfs_dir}/mumble-server.sqlite                            # Fixing permissions
  51.           chgrp ${_owner} ${_tmpfs_dir}/mumble-server.sqlite
  52.           chown ${_owner} ${_tmpfs_dir}/mumble-server.log
  53.           chgrp ${_owner} ${_tmpfs_dir}/mumble-server.log
  54.           /etc/init.d/mumble-server restart                                             # Mumble server restart
  55.           echo "Mumble server is up, database running from ram."
  56.       fi
  57.       ;;
  58.   stop)
  59.       if [ "$(mount | grep ${_tmpfs_dir})" != "" ]; then
  60.           cp ${_tmpfs_dir}/mumble-server.sqlite ${_database_backup_dir}/                # Dumping database and logfile to disk
  61.           cp ${_tmpfs_dir}/mumble-server.log ${_database_backup_dir}/
  62.  
  63.           chown ${_owner} ${_database_backup_dir}/mumble-server.sqlite                  # Fixing permissions
  64.           chgrp ${_owner} ${_database_backup_dir}/mumble-server.sqlite
  65.           chown ${_owner} ${_database_backup_dir}/mumble-server.log
  66.           chgrp ${_owner} ${_database_backup_dir}/mumble-server.log
  67.  
  68.           /etc/init.d/mumble-server stop                                                # Shutting down mumble server
  69.           cp ${_mumble_ini_dir}/mumble-server.sd ${_mumble_ini_dir}/mumble-server.ini   # Using mumble-server.sd as *.ini file
  70.                                                                                         # so if you run mumble now it'll works (slowly)
  71.           umount "${_tmpfs_dir}"                                                        # Unmounting tmpfs
  72.           echo "Mumble server halted and tmpfs unmounted."
  73.           echo "You can now reboot your system safely or restart mumble-server from sd"
  74.       else
  75.           echo "${_tmpfs_dir} is not mounted."
  76.       fi
  77.       ;;
  78.   *)
  79.       echo "$0 start|stop"
  80.       ;;
  81. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement