overlay_syncd 1.3 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2 3 4 5 6
#!/bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=overlay_syncd
DESC="overlay sync"

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
7 8 9 10 11 12 13 14 15
# Possible problem with overlayfs:
#     when using overlays deleting existing in the lower layer dirs can cause error (hopefully it gets fixed someday):
#       example: 
#           * /mnt/sda1 exists in lower layer: /tmp/rootfs.ro/tmp
#           * upper layer is mounted to /
#       # rmdir /mnt/sda1
#       # mkdir /mnt/sda1
#       mkdir: cannot create directory '/mnt/sda1': Operation not supported

16 17 18 19
sync_files () {
  rsync -av --exclude=mnt --exclude=tmp --exclude=dev --exclude=var --exclude=run /tmp/rootfs.rw/upperdir/ /tmp/rootfs.ro/
}

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
20 21 22 23 24 25 26 27
case "$1" in
  start)
	echo -n "Starting $DESC: "
	echo "$NAME:"
	;;
  stop)
	echo -n "Stopping $DESC: "
	echo "$NAME."
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
28 29
	if [ -f /tmp/overlay_sync ]; then 
            if [ -d /tmp/rootfs.ro ]; then
30
              sync_files
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
31
            fi
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
32
	fi
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
	;;
  restart)
	echo -n "Restarting $DESC: "
	echo "$NAME."
	;;
  status)
	echo -n "$NAME status:"
	if [ -f /var/run/$NAME ]; then
	  echo -n "Running"
	else
	  echo -n "Not running"
	fi
	;;
  sync)
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
47 48
        if [ -f /tmp/overlay_sync ]; then 
            if [ -d /tmp/rootfs.ro ]; then
49
              sync_files
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
50
            fi
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
51
        fi
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
52 53 54 55 56 57 58 59 60
  ;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|status|sync}" >&2
	exit 1
	;;
esac

exit 0