-
Notifications
You must be signed in to change notification settings - Fork 18
/
s3ql
99 lines (86 loc) · 2.54 KB
/
s3ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
### BEGIN INIT INFO
# Provides: s3ql
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: S3QL is a filesystem that stores all its data online
# on Amazon s3 and other backends
### END INIT INFO
# init script for Debian 7
DESC="S3QL filesystem"
AUTHFILE="/root/.s3ql/authinfo2"
STORAGE_URL="s3://proxmoxchris"
MOUNTPOINT="/mnt/s3ql"
mkdir -p $MOUNTPOINT
# put all s3ql logs here
mkdir -p /var/log/s3ql
case "$1" in
start)
# Redirect stdout and stderr into the system log
DIR=$(mktemp -d)
mkfifo "$DIR/LOG_FIFO"
logger -t s3ql.mount -p local0.info < "$DIR/LOG_FIFO" &
exec > "$DIR/LOG_FIFO"
exec 2>&1
rm -rf "$DIR"
if mountpoint -q "$MOUNTPOINT"; then
echo "ERROR: $DESC $STORAGE_URL is already mounted on $MOUNTPOINT"
exit 1
fi
echo "Mounting $DESC" "$STORAGE_URL on $MOUNTPOINT"
# Check and mount file system
fsck.s3ql --batch --log /var/log/s3ql/fsck.log --authfile "$AUTHFILE" "$STORAGE_URL"
STA=$?
if [ $STA -eq 0 ]; then
echo "successfully checked filesystem"
else
echo "ERROR: this is the error code: $STA"
exit $STA
fi
mount.s3ql --log /var/log/s3ql/mount.log --authfile "$AUTHFILE" "$STORAGE_URL" "$MOUNTPOINT"
if [ $STA -eq 0 ]; then
echo "successfully mounted on $MOUNTPOINT"
else
echo "ERROR: this is the error code: $STA"
exit $STA
fi
;;
stop)
# Redirect stdout and stderr into the system log
DIR=$(mktemp -d)
mkfifo "$DIR/LOG_FIFO"
logger -t s3ql.unmount -p local0.info < "$DIR/LOG_FIFO" &
exec > "$DIR/LOG_FIFO"
exec 2>&1
rm -rf "$DIR"
if ! mountpoint -q "$MOUNTPOINT"; then
echo "ERROR: $DESC $STORAGE_URL is currently not mounted on $MOUNTPOINT"
exit 1
fi
echo "Unmounting $DESC $STORAGE_URL from $MOUNTPOINT"
s3qlctrl flushcache "$MOUNTPOINT"
s3qlctrl upload-meta "$MOUNTPOINT"
umount.s3ql "$MOUNTPOINT"
if [ $? -eq 0 ]; then
echo "successfully unmounted $MOUNTPOINT"
else
echo "ERROR: this is the error code: $STA"
exit $STA
fi
;;
status)
if ! mountpoint -q "$MOUNTPOINT"; then
echo "$DESC $STORAGE_URL is currently not mounted on $MOUNTPOINT"
exit 1
fi
echo "Status of $DESC $STORAGE_URL on $MOUNTPOINT"
s3qlstat "$MOUNTPOINT"
exit "$?"
;;
*)
echo "Usage: s3ql {start|stop|status}" >&2
exit 3
;;
esac