mirror of
https://github.com/tuna/tunasync.git
synced 2025-06-15 14:12:47 +00:00
refactor: remove part of unneeded files
This commit is contained in:
parent
3d38e413ce
commit
96f38363ea
@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
echo $TUNASYNC_WORKING_DIR
|
|
||||||
echo $TUNASYNC_LOG_FILE
|
|
||||||
echo $TUNASYNC_UPSTREAM_URL
|
|
||||||
echo $REPO
|
|
||||||
sleep 5
|
|
||||||
exit 1
|
|
@ -1,75 +0,0 @@
|
|||||||
[global]
|
|
||||||
log_dir = "/var/log/tunasync"
|
|
||||||
# mirror_root = /srv/mirror_disk
|
|
||||||
mirror_root = "/mnt/sdb1/mirror"
|
|
||||||
use_btrfs = false
|
|
||||||
local_dir = "{mirror_root}/_working/{mirror_name}/"
|
|
||||||
status_file = "/tmp/tunasync.json"
|
|
||||||
# maximum numbers of running jobs
|
|
||||||
concurrent = 2
|
|
||||||
# interval in minutes
|
|
||||||
interval = 1
|
|
||||||
max_retry = 2
|
|
||||||
ctrl_addr = "/tmp/tunasync.sock"
|
|
||||||
|
|
||||||
[btrfs]
|
|
||||||
service_dir = "{mirror_root}/_current/{mirror_name}"
|
|
||||||
working_dir = "{mirror_root}/_working/{mirror_name}"
|
|
||||||
gc_root = "{mirror_root}/_garbage/"
|
|
||||||
gc_dir = "{mirror_root}/_garbage/_gc_{mirror_name}_{{timestamp}}"
|
|
||||||
|
|
||||||
# [[mirrors]]
|
|
||||||
# name = "archlinux"
|
|
||||||
# provider = "rsync"
|
|
||||||
# upstream = "rsync://mirror.us.leaseweb.net/archlinux/"
|
|
||||||
# log_file = "/tmp/archlinux-{date}.log"
|
|
||||||
# use_ipv6 = true
|
|
||||||
|
|
||||||
[[mirrors]]
|
|
||||||
name = "arch1"
|
|
||||||
provider = "shell"
|
|
||||||
command = "sleep 10"
|
|
||||||
local_dir = "/mnt/sdb1/mirror/archlinux/current/"
|
|
||||||
# log_file = "/dev/null"
|
|
||||||
exec_post_sync = "/bin/bash -c 'date --utc \"+%s\" > ${TUNASYNC_WORKING_DIR}/.timestamp'"
|
|
||||||
|
|
||||||
[[mirrors]]
|
|
||||||
name = "arch2"
|
|
||||||
provider = "shell"
|
|
||||||
command = "sleep 20"
|
|
||||||
local_dir = "/mnt/sdb1/mirror/archlinux/current/"
|
|
||||||
# log_file = "/dev/null"
|
|
||||||
|
|
||||||
|
|
||||||
[[mirrors]]
|
|
||||||
name = "arch3"
|
|
||||||
provider = "two-stage-rsync"
|
|
||||||
stage1_profile = "debian"
|
|
||||||
upstream = "/tmp/rsync_test/src/"
|
|
||||||
local_dir = "/tmp/rsync_test/dst/"
|
|
||||||
log_file = "/tmp/rsync_test/log"
|
|
||||||
# log_file = "/dev/null"
|
|
||||||
no_delay = true
|
|
||||||
|
|
||||||
[[mirrors]]
|
|
||||||
name = "arch4"
|
|
||||||
provider = "shell"
|
|
||||||
command = "./shell_provider.sh"
|
|
||||||
upstream = "https://pypi.python.org/"
|
|
||||||
# log_file = "/tmp/arch4-{date}.log"
|
|
||||||
use_btrfs = false
|
|
||||||
# set environment varialbes
|
|
||||||
[mirrors.env]
|
|
||||||
REPO = "/usr/local/bin/repo"
|
|
||||||
|
|
||||||
[[mirrors]]
|
|
||||||
name = "arch5"
|
|
||||||
provider = "shell"
|
|
||||||
command = "./shell_provider.sh"
|
|
||||||
upstream = "https://pypi.python.org/"
|
|
||||||
# log_file = "/tmp/arch4-{date}.log"
|
|
||||||
use_btrfs = false
|
|
||||||
[mirrors.env]
|
|
||||||
REPO = "/usr/local/bin/repo2"
|
|
||||||
|
|
||||||
# vim: ft=toml ts=2 sts=2 sw=2
|
|
@ -1,3 +0,0 @@
|
|||||||
setproctitle==1.1.9
|
|
||||||
sh==1.11
|
|
||||||
toml==0.9.1
|
|
@ -1,11 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Delete garbage subvolumes generated by tunasync
|
|
||||||
Requires = network.target
|
|
||||||
After = network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/home/tuna/.virtualenvs/tunasync/bin/python -u /home/tuna/tunasync/tunasync_snapshot_gc.py -c /etc/tunasync.ini
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy = multi-user.target
|
|
@ -1,8 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=TUNAsync GC every 10 minutes
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
OnUnitActiveSec=10min
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
@ -1,13 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description = TUNA mirrors sync daemon
|
|
||||||
Requires = network.target
|
|
||||||
After = network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ExecStart = /home/tuna/.virtualenvs/tunasync/bin/python -u /home/tuna/tunasync/tunasync.py -c /etc/tunasync.ini
|
|
||||||
KillSignal = SIGTERM
|
|
||||||
ExecReload = /bin/kill -SIGUSR1 $MAINPID
|
|
||||||
Environment = "HOME=/home/tuna"
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy = multi-user.target
|
|
28
tunasync.py
28
tunasync.py
@ -1,28 +0,0 @@
|
|||||||
#!/usr/bin/env python2
|
|
||||||
# -*- coding:utf-8 -*-
|
|
||||||
import os
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
from tunasync import TUNASync
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
here = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog="tunasync")
|
|
||||||
parser.add_argument("-c", "--config",
|
|
||||||
default="tunasync.ini", help="config file")
|
|
||||||
parser.add_argument("--pidfile", default="/run/tunasync/tunasync.pid",
|
|
||||||
help="pidfile")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
with open(args.pidfile, 'w') as f:
|
|
||||||
f.write("{}".format(os.getpid()))
|
|
||||||
|
|
||||||
tunaSync = TUNASync()
|
|
||||||
tunaSync.read_config(args.config)
|
|
||||||
|
|
||||||
tunaSync.run_jobs()
|
|
||||||
|
|
||||||
# vim: ts=4 sw=4 sts=4 expandtab
|
|
@ -1,43 +0,0 @@
|
|||||||
#!/usr/bin/env python2
|
|
||||||
# -*- coding:utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sh
|
|
||||||
import os
|
|
||||||
import argparse
|
|
||||||
import toml
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser(prog="tunasync_snapshot_gc")
|
|
||||||
parser.add_argument("--max-level", type=int, default=1, help="max walk level to find garbage snapshots")
|
|
||||||
parser.add_argument("--pattern", default=r"^_gc_.+_\d+", help="pattern to match garbage snapshots")
|
|
||||||
parser.add_argument("-c", "--config", help="tunasync config file")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
pattern = re.compile(args.pattern)
|
|
||||||
|
|
||||||
def walk(_dir, level=1):
|
|
||||||
if level > args.max_level:
|
|
||||||
return
|
|
||||||
|
|
||||||
for fname in os.listdir(_dir):
|
|
||||||
abs_fname = os.path.join(_dir, fname)
|
|
||||||
if os.path.isdir(abs_fname):
|
|
||||||
if pattern.match(fname):
|
|
||||||
print("GC: {}".format(abs_fname))
|
|
||||||
try:
|
|
||||||
sh.btrfs("subvolume", "delete", abs_fname)
|
|
||||||
except sh.ErrorReturnCode as e:
|
|
||||||
print("Error: {}".format(e.stderr))
|
|
||||||
else:
|
|
||||||
walk(abs_fname, level+1)
|
|
||||||
|
|
||||||
with open(args.config) as f:
|
|
||||||
settings = toml.loads(f.read())
|
|
||||||
|
|
||||||
mirror_root = settings["global"]["mirror_root"]
|
|
||||||
gc_root = settings["btrfs"]["gc_root"].format(mirror_root=mirror_root)
|
|
||||||
|
|
||||||
walk(gc_root)
|
|
||||||
|
|
||||||
# vim: ts=4 sw=4 sts=4 expandtab
|
|
@ -1,64 +0,0 @@
|
|||||||
#!/usr/bin/env python2
|
|
||||||
# -*- coding:utf-8 -*-
|
|
||||||
import sys
|
|
||||||
import socket
|
|
||||||
import argparse
|
|
||||||
import json
|
|
||||||
import struct
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser(prog="tunasynctl")
|
|
||||||
parser.add_argument("-s", "--socket",
|
|
||||||
default="/run/tunasync/tunasync.sock", help="socket file")
|
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(dest="command", help='sub-command help')
|
|
||||||
|
|
||||||
sp = subparsers.add_parser('start', help="start job")
|
|
||||||
sp.add_argument("target", help="mirror job name")
|
|
||||||
|
|
||||||
sp = subparsers.add_parser('stop', help="stop job")
|
|
||||||
sp.add_argument("target", help="mirror job name")
|
|
||||||
|
|
||||||
sp = subparsers.add_parser('restart', help="restart job")
|
|
||||||
sp.add_argument("target", help="mirror job name")
|
|
||||||
|
|
||||||
sp = subparsers.add_parser('status', help="show mirror status")
|
|
||||||
sp.add_argument("target", nargs="?", default="__ALL__", help="mirror job name")
|
|
||||||
|
|
||||||
sp = subparsers.add_parser('log', help="return log file path")
|
|
||||||
sp.add_argument("-n", type=int, default=0, help="last n-th log, default 0 (latest)")
|
|
||||||
sp.add_argument("target", help="mirror job name")
|
|
||||||
|
|
||||||
sp = subparsers.add_parser('help', help="show help message")
|
|
||||||
|
|
||||||
args = vars(parser.parse_args())
|
|
||||||
|
|
||||||
if args['command'] == "help":
|
|
||||||
parser.print_help()
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
||||||
|
|
||||||
try:
|
|
||||||
sock.connect(args.pop("socket"))
|
|
||||||
except socket.error as msg:
|
|
||||||
print(msg)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
pack = json.dumps({
|
|
||||||
"cmd": args.pop("command"),
|
|
||||||
"target": args.pop("target"),
|
|
||||||
"kwargs": args,
|
|
||||||
})
|
|
||||||
|
|
||||||
try:
|
|
||||||
sock.sendall(struct.pack('!H', len(pack)) + pack)
|
|
||||||
length = struct.unpack('!H', sock.recv(2))[0]
|
|
||||||
print(sock.recv(length))
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
finally:
|
|
||||||
sock.close()
|
|
||||||
|
|
||||||
# vim: ts=4 sw=4 sts=4 expandtab
|
|
Loading…
x
Reference in New Issue
Block a user