Advertisement
Guest User

tempfs sync

a guest
Oct 3rd, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.72 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          tempfs
  4. # Required-Start:    $remote_fs
  5. # Required-Stop:     $remote_fs
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Example initscript
  9. # Description:       This file move the /var/log on tempfs, and copy them to
  10. #                    harddrive on shutdown
  11.  
  12. #                    Create the link with :
  13. #                    #update-rc.d tempfs start 05 2 3 4 5 . stop 95 0 1 6 .
  14. ### END INIT INFO
  15.  
  16. # Author: Sébastien Dailly <sebastien@chimrod.com>
  17. #
  18.  
  19. # Do NOT "set -e"
  20.  
  21. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  22. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  23. DESC="Description of the service"
  24. NAME=tempfs
  25. SCRIPTNAME=/etc/init.d/$NAME
  26.  
  27. # Load the VERBOSE setting and other rcS variables
  28. . /lib/init/vars.sh
  29.  
  30. # Define LSB log_* functions.
  31. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  32. . /lib/lsb/init-functions
  33.  
  34. #
  35. # Function that starts the daemon/service
  36. #
  37. do_start()
  38. {
  39.     # Return
  40.     #   0 if daemon has been started
  41.     #   1 if daemon was already running
  42.     #   2 if daemon could not be started
  43.  
  44.     #C'est ici qu'on va définir le système à mettre en place ( creation des répertoires etc )
  45.  
  46.     #Creer les répertoires /devrait/ être inutile, puisque tout est sauvegardé sur
  47.     #la partition en dur
  48.     mkdir /tmp/log/fsck
  49.     mkdir /tmp/log/ksymoops
  50.     mkdir /tmp/log/news
  51.     mkdir /tmp/log/apt
  52.     mkdir /tmp/log/dbconfig-common
  53.     mkdir -p /tmp/log/debian-installer/cdebconf
  54.  
  55.     mkdir /tmp/log/ntpstats;        chown ntp       /tmp/log/ntpstats/
  56.     mkdir /tmp/log/exim4;           chown Debian-exim   /tmp/log/exim4
  57.     mkdir /tmp/log/mysql;           chown mysql     /tmp/log/mysql/
  58.     mkdir -p /tmp/log/apache2/evasive;  chown -R www-data:www-data /tmp/log/apache2/
  59.     mkdir /tmp/log/pure-ftpd
  60.     mkdir /tmp/log/mldonkey;        chown mldonkey      /tmp/log/mldonkey/
  61.     mkdir /tmp/log/mpd;         chown mpd       /tmp/log/mpd/
  62.     mkdir /tmp/log/lastfm;          chown lastfm        /tmp/log/lastfm/
  63.     chgrp -R adm /tmp/log/
  64.     mkdir /tmp/log/tor;         chown debian-tor    /tmp/log/tor/
  65.     mkdir /tmp/uptimed;
  66.  
  67.     mkdir -p /tmp/mysql/wp_blog_chimrod/
  68.  
  69.     chown debian-tor    /var/lib/tor/
  70.     chown daemon:daemon /var/spool/uptimed/
  71.     chown ntp       /var/lib/ntp
  72.  
  73.     chmod 775       /var/run/screen
  74.  
  75.     #Lie les répertoires
  76.     cp -af /var/log/ /tmp/
  77.     cp -af /var/spool/uptimed/ /tmp/
  78.     cp -af /var/lib/mysql/wp_blog_chimrod /tmp/mysql/
  79.     mount --bind /tmp/log/ /var/log/
  80.     mount --bind /tmp/mysql/wp_blog_chimrod/ /var/lib/mysql/wp_blog_chimrod/
  81.     mount --bind /tmp/uptimed/ /var/spool/uptimed
  82.  
  83.     test -d /tmp/php_session/ || mkdir /tmp/php_session/
  84.     chmod 777 /tmp/php_session/
  85.  
  86.     #Pour les partitions sur la clef USB on n'a pas besoin de copier lors de l'initialisation
  87.     #mount /dev/disk/by-id/usb-EMTEC_U3_Smart_Drive_0700077B0C440397-0:0-part1 /mnt/data/
  88.     #mount --bind /mnt/data/site/wordpress/wp-content/ /usr/share/wordpress/wp-content/
  89.     #mount --bind /mnt/data/site/main/ /var/www/main/
  90. }
  91.  
  92. #
  93. # Function that stops the daemon/service
  94. #
  95. do_stop()
  96. {
  97.     #Sauvegarde les logs points de sauvegarde avant d'eteindre
  98.     #monter avec bind permet d'outrepasser le point de montage
  99.     #On utilise rsync pour se synchroniser
  100.     #   (   ne pas oublier le / final
  101.     #       sur le nom de fichier )
  102.     mkdir /tmp/$$
  103.     mount --bind /var/ /tmp/$$
  104.  
  105.     rsync -a --del /tmp/uptimed/ /tmp/$$/spool/uptimed/
  106.     rsync -a --del /tmp/log/ /tmp/$$/log/
  107.     rsync -a --del /tmp/mysql/wp_blog_chimrod/ /tmp/$$/lib/mysql/wp_blog_chimrod/
  108.     #rsync -a --del /mnt/data/site/main/ /tmp/$$/www/main/
  109.  
  110.     #rsync -a --del /mnt/data/site/wordpress/wp-content/ /usr/share/wordpress/wp-content/
  111.  
  112.     umount /tmp/$$ && rm -r /tmp/$$
  113. }
  114.  
  115. case "$1" in
  116.   start)
  117.     do_start
  118.     ;;
  119.   stop)
  120.     do_stop
  121.     ;;
  122.   *)
  123.     echo "Usage: $SCRIPTNAME {start|stop}" >&2
  124.     exit 3
  125.     ;;
  126. esac
  127. :
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement