Guest User

Untitled

a guest
Apr 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: dpkg-squashfs
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Squashfsed /var/lib/dpkg
  9. # Description: Use squashfs to speedup dpkg cold start.
  10. # Required kernel modules: aufs, squashfs
  11. # Required packages: squashfs-tools
  12. ### END INIT INFO
  13.  
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="Squashfsed dpkg directory"
  16. SCRIPTNAME=/etc/init.d/$NAME
  17. . /lib/lsb/init-functions
  18.  
  19. DPKG_DIR=/var/lib/dpkg
  20. DPKG_RO=/var/lib/.dpkg.ro
  21. DPKG_RW=/var/lib/.dpkg.rw
  22. SQUASHFS_FILE=/var/lib/dpkg.squashfs
  23.  
  24. mount_squashfs()
  25. {
  26. mkdir -p ${DPKG_RO}
  27. mount -r -t squashfs -o loop ${SQUASHFS_FILE} ${DPKG_RO}
  28. }
  29.  
  30. squashfs_mounted()
  31. {
  32. mount | grep -q ${DPKG_RO}
  33. }
  34.  
  35. umount_squashfs()
  36. {
  37. umount ${DPKG_RO}
  38. }
  39.  
  40. mount_aufs()
  41. {
  42. mkdir -p ${DPKG_RW}
  43. mount -t aufs -o noplink,br:${DPKG_RW}=rw:${DPKG_RO}=rr dpkgfs ${DPKG_DIR} > /dev/null 2>&1
  44. }
  45.  
  46. aufs_mounted()
  47. {
  48. mount | grep -q ^dpkgfs
  49. }
  50.  
  51. umount_aufs()
  52. {
  53. umount ${DPKG_DIR}
  54. }
  55.  
  56. make_squashfs()
  57. {
  58. rm -f ${SQUASHFS_FILE}.new
  59. mksquashfs ${DPKG_DIR} ${SQUASHFS_FILE}.new -no-progress > /dev/null 2>&1
  60. }
  61.  
  62. silent_move()
  63. {
  64. if [ -e $1 ]; then
  65. rm -rf $2
  66. mv $1 $2
  67. fi
  68. }
  69.  
  70. do_start()
  71. {
  72. if ! [ -e ${SQUASHFS_FILE} ]; then
  73. make_squashfs
  74. silent_move ${SQUASHFS_FILE}.new ${SQUASHFS_FILE}
  75. fi
  76. mount_squashfs && mount_aufs
  77. }
  78.  
  79. do_stop()
  80. {
  81. if aufs_mounted; then
  82. make_squashfs
  83. fuser -k -m ${DPKG_DIR}
  84. umount_aufs
  85. fi
  86. squashfs_mounted && umount_squashfs
  87.  
  88. silent_move ${SQUASHFS_FILE}.new ${SQUASHFS_FILE}
  89. silent_move ${DPKG_RW} ${DPKG_RW}.old
  90.  
  91. rm -rf ${DPKG_RW}.old
  92. rm -rf ${DPKG_RO}
  93. return 0
  94. }
  95.  
  96. case "$1" in
  97. start)
  98. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  99. do_start
  100. case "$?" in
  101. 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  102. *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  103. esac
  104. ;;
  105. stop)
  106. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  107. do_stop
  108. case "$?" in
  109. 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  110. *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  111. esac
  112. ;;
  113. status)
  114. mount | grep ${DPKG_DIR}
  115. ;;
  116. restart|force-reload)
  117. log_daemon_msg "Restarting $DESC" "$NAME"
  118. do_stop
  119. case "$?" in
  120. 0|1)
  121. do_start
  122. case "$?" in
  123. 0) log_end_msg 0 ;;
  124. 1) log_end_msg 1 ;; # Old process is still running
  125. *) log_end_msg 1 ;; # Failed to start
  126. esac
  127. ;;
  128. *)
  129. # Failed to stop
  130. log_end_msg 1
  131. ;;
  132. esac
  133. ;;
  134. *)
  135. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  136. exit 3
  137. ;;
  138. esac
  139.  
  140. :
Add Comment
Please, Sign In to add comment