Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
2d20c8447d | |||
3e8cadf6b8 | |||
f3fde90cdc | |||
e65a401819 | |||
6250c23295 | |||
4683c54f44 | |||
56dfa71a62 | |||
1b919a5c10 | |||
dabefc5047 | |||
9a62f2bc5e | |||
e72eb4b31f | |||
2f4724d0ad | |||
a9763dcd8d | |||
e96bd34bf5 | |||
2710feb490 | |||
fabee3bf11 | |||
52757828e5 | |||
0c1f4f6c33 |
18
.drone.yml
18
.drone.yml
@ -1,6 +1,16 @@
|
||||
pipeline:
|
||||
nginx-conf:
|
||||
image: nginx:mainline
|
||||
commands:
|
||||
- cp nginx.conf /etc/nginx/
|
||||
- nginx -t
|
||||
docker:
|
||||
image: plugins/docker
|
||||
repo: repo.shimun.net/shimun/seafile
|
||||
registry: repo.shimun.net
|
||||
secrets: ["docker_username", "docker_password"]
|
||||
image: plugins/docker
|
||||
repo: repo.shimun.net/shimun/seafile
|
||||
registry: repo.shimun.net
|
||||
storage_path: /drone/.docker
|
||||
secrets: ["docker_username", "docker_password"]
|
||||
storage_path: /drone/.docker
|
||||
cache_from: ["repo.shimun.net/shimun/seafile", "repo.shimun.net/shimun/seafile:nginx-deb", "repo.shimun.net/shimun/seafile:alpine"]
|
||||
use_cache: true
|
||||
pull_image: false
|
||||
|
@ -75,9 +75,9 @@ http{
|
||||
|
||||
}
|
||||
|
||||
# location /media {
|
||||
# root /opt/seafile/seafile-server-latest/seahub;
|
||||
# }
|
||||
location /media {
|
||||
try_files /var/www /opt/seafile/seafile-server-latest/seahub;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ case "$1" in
|
||||
mkdir -p $SEAF/conf
|
||||
cp /etc/seafile/* $SEAF/conf/* -rf
|
||||
$0 run-upgrade
|
||||
exit
|
||||
exit $?
|
||||
else
|
||||
patch_seahub_conf
|
||||
for CMD in "${COMMANDS[@]}"; do
|
||||
@ -81,6 +81,10 @@ case "$1" in
|
||||
run-upgrade)
|
||||
$0 upgrade
|
||||
RES=$?
|
||||
if [ $RES -eq 1 ]; then
|
||||
echo "Failed upgrade"
|
||||
exit 1
|
||||
fi
|
||||
if [ $RES -eq 127 ]; then
|
||||
#No upgrade
|
||||
true
|
||||
@ -109,6 +113,22 @@ case "$1" in
|
||||
/usr/local/sbin/upgrade main
|
||||
kill -SIGHUP $(pgrep -o nginx) #Reload nginx
|
||||
;;
|
||||
maintanance)
|
||||
$0 stop
|
||||
$LATEST/seaf-gc.sh
|
||||
$0 start
|
||||
;;
|
||||
setup)
|
||||
INSTALLDIR=$2
|
||||
SETUP_ARGS="auto -n ${SEAF_NAME:-$(hostname)} -i $(hostname) -p 8082"
|
||||
if [ ! -z "$SEAF_MYSQL" ]; then
|
||||
$INSTALLDIR/setup-seafile-mysql.sh $SETUP_ARGS -o $SEAF_MYSQL_HOST -t ${SEAF_MYSQL_PORT:-3306} -u "${SEAF_MYSQL_USER:-root}" \
|
||||
-w "$SEAF_MYSQL_PASS" -r "${SEAF_MYSQL_ROOT_PASS:-$SEAF_MYSQL_PASS}" -c ${SEAF_MYSQL_DB_CCNET:-ccnet} -s ${SEAF_MYSQL_DB_SEAF:-seafile} \
|
||||
-b ${SEAF_MYSQL_DB_HUB:-seahub}
|
||||
else
|
||||
$INSTALLDIR/setup-seafile.sh $SETUP_ARGS
|
||||
fi
|
||||
;;
|
||||
status)
|
||||
RUNNING=1
|
||||
for CMD in seafile-controller ccnet "${COMMANDS[@]}"; do
|
||||
|
@ -37,6 +37,14 @@ def list_command(page="https://www.seafile.com/en/download/"):
|
||||
def current_version_command():
|
||||
print(current_version())
|
||||
|
||||
def installed_versions():
|
||||
installed = []
|
||||
for f in os.listdir(seaf_home):
|
||||
m = re.findall(version_re,f)
|
||||
if len(m) > 0:
|
||||
installed.append(m[0])
|
||||
return installed
|
||||
|
||||
def current_version():
|
||||
current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest"))
|
||||
res = re.findall(version_re,current)
|
||||
@ -49,10 +57,11 @@ def perform_upgrade_command(version,mysql=False,yes=True):
|
||||
target = map(lambda x: int(x), version.split("."))
|
||||
print len(current) == 1 and current[0] == 0
|
||||
if len(current) == 1 and current[0] == 0: #Not installed
|
||||
print("Running installer, please don't change any default values regarding ports.")
|
||||
print("Running installer.")
|
||||
installer = os.path.join(seaf_home,"seafile-server-%s" % version,"setup-seafile%s.sh" % ("-mysql" if mysql else ""))
|
||||
call(["sh","-c",installer],stdout=sys.stdout, stdin=sys.stdin)
|
||||
return 0
|
||||
if not call(["seafile-server","setup"],stdout=sys.stdout, stdin=sys.stdin):
|
||||
sys.exit(1)
|
||||
sys.exit(126)
|
||||
script_re = "^upgrade_(\d+).(\d+)_(\d+).(\d+)\.sh$"
|
||||
run = []
|
||||
last = None
|
||||
@ -74,16 +83,20 @@ def install_command(url):
|
||||
tmp = tempfile.mkdtemp()
|
||||
if call(["/bin/sh", "-c", 'cd %s; curl %s | tar xzv' % (tmp, url)]) == 0:
|
||||
for f in os.listdir(tmp):
|
||||
dest = os.path.join(seaf_home, os.path.basename(f))
|
||||
if len(re.findall(version_re, f)) > 0:
|
||||
dest = os.path.join(seaf_home, os.path.basename(f))
|
||||
shutil.move(os.path.join(tmp,f), dest)
|
||||
if not os.path.exists(dest):
|
||||
shutil.move(os.path.join(tmp,f), dest)
|
||||
else:
|
||||
shutil.rmtree(tmp)
|
||||
print("Found previous installation, resuming setup")
|
||||
current = current_version()
|
||||
target_version = ''.join(re.findall(version_re,dest))
|
||||
if len(current) == 1: current = current[0]
|
||||
else: current = "0.0.0"
|
||||
print("Upgrading from: %s -> %s" % (current, target_version))
|
||||
perform_upgrade_command(target_version,mysql=(os.environ["SEAF_MYSQL"] or False))
|
||||
if len(os.listdir(tmp)) != 0:
|
||||
perform_upgrade_command(target_version,mysql=("SEAF_MYSQL" in os.environ and os.environ["SEAF_MYSQL"]))
|
||||
if os.exists(tmp) and len(os.listdir(tmp)) != 0:
|
||||
print("Failed to unpack update")
|
||||
os.rmdir(tmp)
|
||||
return 1
|
||||
@ -95,19 +108,21 @@ def main_command(version="latest",page="https://www.seafile.com/en/download/"):
|
||||
avail = available(page)
|
||||
install = None
|
||||
if version == "latest":
|
||||
(install,version) = avail.items()
|
||||
(version,install) = avail.items()[0]
|
||||
else:
|
||||
if version in dict(avail.items()):
|
||||
install = dict(avail.items())[version]
|
||||
if version_int(current_version()) == version_int(version):
|
||||
print("%s(%s) is already installed" % (version,version_int(version)))
|
||||
return 1
|
||||
sys.exit(126)
|
||||
if version in installed_versions():
|
||||
return perform_upgrade_command(version)
|
||||
if install:
|
||||
print("Installing: %s" % install[1])
|
||||
return install_command(install[1])
|
||||
print("Installing: %s" % version)
|
||||
sys.exit(install_command(install))
|
||||
else:
|
||||
print("Couldn't determine download for %s" % version)
|
||||
return 1
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import scriptine
|
||||
|
31
seafile.service
Normal file
31
seafile.service
Normal file
@ -0,0 +1,31 @@
|
||||
[Unit]
|
||||
Description=Seafile container https://git.shimun.net/shimun/docker-seafile
|
||||
|
||||
[Service]
|
||||
Slice=machine.slice
|
||||
# Resource limits
|
||||
Delegate=true
|
||||
CPUShares=256
|
||||
MemoryLimit=512M
|
||||
|
||||
Environment=ROOT_DIR=/srv/seafile
|
||||
Environment=SEAF_MYSQL="" #Empty = Sqlite
|
||||
Environment=SEAF_URL="https://seaf.example.com"
|
||||
Environment=SEAF_UPGRADE_INTERVAL=10
|
||||
|
||||
#Run first once to setup
|
||||
#rkt --insecure-options=image run --dns 8.8.8.8 --volume volume-opt-seafile,kind=host,source=${ROOT_DIR} docker://repo.shimun.net/shimun/seafile --environment=SEAF_URL="https://seaf.example.com" --interactive
|
||||
|
||||
ExecStartPre=/bin/mkdir -p ${ROOT_DIR}
|
||||
ExecStart=/usr/bin/rkt --insecure-options=image run --uuid-file-save=${ROOT_DIR}/container.uuid --dns 8.8.8.8 --inherit-env --volume volume-opt-seafile,kind=host,source=${ROOT_DIR} --port 80-tcp:8080 \
|
||||
docker://repo.shimun.net/shimun/seafile --environment=SEAF_UPGRADE_INTERVAL=${SEAF_UPGRADE_INTERVAL}
|
||||
ExecStartPost=/bin/bash -c "echo 'rkt enter --app=seafile $(cat '${ROOT_DIR}'/container.uuid)' > ${ROOT_DIR}/enter.sh && chmod +x ${ROOT_DIR}/enter.sh"
|
||||
ExecStopPre=/bin/bash -c "rkt enter --app=seafile $(cat ${ROOT_DIR}/container.uuid) 'seafile-server stop'"
|
||||
ExecStopPost=/bin/bash -c "rkt rm $(cat ${ROOT_DIR}/container.uuid)"
|
||||
ExecStopPost=/bin/rm ${ROOT_DIR}/container.uuid
|
||||
KillMode=mixed
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Reference in New Issue
Block a user