Compare commits

...

50 Commits
v0.1 ... master

Author SHA1 Message Date
9561a29e9d Update 'Dockerfile' 2021-06-06 12:09:19 +00:00
21023671f5 Update 'Dockerfile' 2021-06-06 12:04:54 +00:00
c1cb3885d7
short intervals
Some checks failed
continuous-integration/drone/push Build is failing
2020-10-06 23:15:22 +02:00
7d1d8453ce
update
Some checks failed
continuous-integration/drone/push Build is failing
2020-10-06 22:51:39 +02:00
0a7448aec4
tag as git 2020-10-06 22:51:18 +02:00
4dfc15fffd
healthchecks 2020-10-06 22:49:08 +02:00
65140c1986
webdav isn't using fcgi anymore
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-04-14 15:48:16 +02:00
3c42cff98d
Merge branch 'riffol' 2020-04-14 15:28:13 +02:00
33af52ff54
keep seafdav deps current
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-04-14 15:26:21 +02:00
5b07f77f53
keep python deps current
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-04-14 15:16:54 +02:00
6fabfb2aab
python3
Some checks reported errors
continuous-integration/drone/push Build was killed
2020-04-14 14:15:03 +02:00
19014932d1
install python3
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-04-10 15:03:00 +02:00
99748c70aa
update rust
All checks were successful
continuous-integration/drone/push Build is passing
2019-07-25 18:06:40 +02:00
e9e595ef68
use drone cache [CI SKIP] 2019-07-25 17:17:40 +02:00
d05de406f8
appropriate number for never
Some checks reported errors
continuous-integration/drone/push Build was killed
2019-07-25 17:10:30 +02:00
shimunn
1b4ad91a13 extended service file
Some checks are pending
continuous-integration/drone/push Build is failing
2019-04-20 21:44:11 +02:00
shimunn
d1ac73034b removed unimplemented checks [CI SKIP] 2019-04-20 15:43:17 +02:00
shimunn
6dea22e4dd print error msg
Some checks are pending
continuous-integration/drone/push Build is failing
2019-04-20 11:37:32 +02:00
shimunn
e1dc715dd0 fix css
Some checks are pending
continuous-integration/drone/push Build is failing
2019-04-20 00:58:28 +02:00
shimunn
7d6a2d243e Merge branch 'no_media' into riffol 2019-04-20 00:46:51 +02:00
shimunn
e0491a5b45 works
Some checks are pending
continuous-integration/drone/push Build is failing
2019-04-20 00:35:47 +02:00
shimunn
605b76798a fixed panic 2019-04-19 21:10:07 +02:00
shimunn
06f0703a89 fixed format error [CI SKIP] 2019-04-19 20:52:20 +02:00
shimunn
4ebc0bdf82 [CI SKIP] proper init
Some checks are pending
continuous-integration/drone/push Build is failing
2019-04-19 18:52:36 +02:00
shim_
c513f2ab95 no_media version 2018-11-11 18:32:35 +01:00
shim_
fb956cb777 reorganised nginx.conf
Some checks are pending
continuous-integration/drone/push Build is failing
2018-11-11 17:24:27 +01:00
shim_
bee6bd3200 mkdir pkg dir 2018-11-10 17:22:10 +01:00
shim_
6fb12158b0 Merge branch 'master' into nginx-deb 2018-11-10 15:36:29 +01:00
shim_
69824d3497 Merge branch 'pull_prev' into nginx-deb 2018-11-10 15:33:39 +01:00
shim_
2d20c8447d disable base image pull 2018-11-10 15:29:52 +01:00
shim_
3e8cadf6b8 utilise --cache-from PR 2018-11-10 15:23:41 +01:00
shim_
38da3057a3 more worker connections 2018-11-04 17:39:34 +01:00
shim_
8dc75bc553 improved commands 2018-11-03 21:11:55 +01:00
shim_
f3fde90cdc cache from 2018-11-03 20:00:46 +01:00
shim_
e65a401819 pull previous build 2018-11-03 18:24:15 +01:00
shim_
6250c23295 check nginx.conf 2018-11-03 17:52:36 +01:00
shim_
4683c54f44 media fallback 2018-11-03 17:52:16 +01:00
shim_
56dfa71a62 error codes 2018-11-03 15:13:46 +01:00
shim_
1b919a5c10 serve static 2018-10-04 16:31:17 +02:00
shim_
dabefc5047 improved systemd 2018-10-04 16:31:05 +02:00
shim_
9a62f2bc5e handle existing install 2018-10-04 16:30:46 +02:00
shim_
e72eb4b31f resume setup if possible 2018-09-13 21:25:25 +02:00
shim_
2f4724d0ad caching 2018-09-13 18:46:36 +02:00
shim_
a9763dcd8d keep resuming setup 2018-09-09 23:59:09 +02:00
shim_
e96bd34bf5 handle non existent env 2018-09-09 23:46:08 +02:00
shim_
2710feb490 include all options [CI SKIP] 2018-09-09 23:41:01 +02:00
shim_
fabee3bf11 can't download a tuple 2018-09-09 23:31:18 +02:00
shim_
52757828e5 sample systemd service 2018-09-09 23:15:54 +02:00
shim_
0c1f4f6c33 added array indices 2018-09-09 23:15:35 +02:00
shim_
27ec24d567 Merged working scripts into master(alpine) 2018-09-09 22:51:47 +02:00
16 changed files with 386 additions and 279 deletions

View File

@ -1,6 +1,17 @@
pipeline: pipeline:
nginx-conf:
image: nginx:mainline
commands:
- cp -r nginx /etc/nginx
- nginx -t
docker: docker:
image: plugins/docker image: plugins/docker
repo: repo.shimun.net/shimun/seafile repo: repo.shimun.net/shimun/seafile:git
registry: repo.shimun.net tag: riffol
secrets: ["docker_username", "docker_password"] registry: repo.shimun.net
storage_path: /drone/.docker
secrets: ["docker_username", "docker_password"]
storage_path: /drone/cache/.docker
cache_from: ["repo.shimun.net/shimun/seafile:git"]
use_cache: true
pull_image: false

View File

@ -1,3 +1,7 @@
FROM rust:1.36-slim AS riffol_build
RUN cargo install --git https://github.com/shimunn/riffol.git --branch print_error --locked
FROM nginx:mainline FROM nginx:mainline
VOLUME /opt/seafile VOLUME /opt/seafile
@ -8,21 +12,43 @@ ENV SEAF=/opt/seafile
COPY requirements.txt /tmp/requirements.txt COPY requirements.txt /tmp/requirements.txt
RUN apt update && apt install locales -y && apt install -y --no-install-recommends procps openssl python2.7 sqlite3 python-mysqldb python-pil curl libjansson4 libfuse2 python-pip python-pip-whl python-setuptools \ RUN apt update && apt install locales -y && apt install -y procps libmariadb-dev-compat openssl python2.7 sqlite3 python-mysqldb python-pil curl libjansson4 libfuse2 python-pip python-pip-whl python-setuptools python3 sqlite3 python3 python3-pip python3-setuptools python3-ldap \
&& pip install -r /tmp/requirements.txt && apt remove -y python-pip \
&& rm -rf /var/lib/apt/lists/* /tmp/requirements.txt && rm -rf /var/lib/apt/lists/* /tmp/requirements.txt
RUN python3 -m pip install --upgrade pip && rm -r /root/.cache/pip
RUN pip3 install --timeout=3600 click termcolor colorlog pymysql \
django && rm -r /root/.cache/pip
ADD https://raw.githubusercontent.com/haiwen/seahub/master/requirements.txt /tmp/hub-requirements.txt
RUN pip3 install --timeout=3600 -r /tmp/hub-requirements.txt
ADD https://raw.githubusercontent.com/haiwen/seafdav/master/requirements.txt /tmp/dav-requirements.txt
RUN pip3 install --timeout=3600 -r /tmp/dav-requirements.txt
COPY --from=riffol_build /usr/local/cargo/bin/riffol /usr/sbin/
RUN ln -s /opt/seafile/seafile-server-latest/seafile.sh /usr/bin/seafile && \
ln -s /opt/seafile/seafile-server-latest/seahub.sh /usr/bin/seahub && \
ln -s /opt/seafile/pids /var/run/seafile
COPY riffol.conf /etc/riffol.conf
COPY conf /opt/seafile/conf COPY conf /opt/seafile/conf
COPY conf /etc/seafile COPY conf /etc/seafile
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx /etc/nginx
COPY scripts/upgrade.py /usr/local/sbin/upgrade COPY scripts/upgrade.py /usr/local/sbin/upgrade
COPY scripts/seafile-server.sh /sbin/seafile-server COPY scripts/setup.sh /usr/bin/setup
RUN ulimit -n 30000 && mkdir -p $SEAF/pids && \ RUN ulimit -n 30000 && mkdir -p $SEAF/pids && \
chmod +x /usr/local/sbin/upgrade /sbin/seafile-server chmod +x /usr/local/sbin/upgrade /usr/bin/setup
RUN pip2 install requests scriptine
ENV SEAF_UPGRADE_INTERVAL=3 ENV SEAF_UPGRADE_INTERVAL=3
ENTRYPOINT ["/sbin/seafile-server"] HEALTHCHECK --interval=30s --timeout=30s --start-period=30s CMD (curl http://localhost:8000 || (echo "failed seahub"; exit 1)) && (curl http://localhost:8082 || (echo "failed seafhttp"; exit 1)) && (bash -c '[ $(curl --silent --output /dev/null --write-out "%{http_code}" http://localhost:8080) -eq 401 ]' || (echo "failed seafdav"; exit 1)) || exit 1
#Defaults to run-upgrade options include: run, run-upgrade, upgrade, stop, stop-upgrade
CMD ["run-upgrade"] ENTRYPOINT ["/usr/sbin/riffol", "-f", "/etc/riffol.conf"]

View File

@ -1,83 +0,0 @@
events {
worker_connections 12;
}
http{
upstream hub {
server 127.0.0.1:8000;
keepalive 2;
}
upstream files {
server 127.0.0.1:8082;
keepalive 4;
}
upstream webdav {
server 127.0.0.1:8080;
keepalive 2;
}
disable_symlinks off;
server {
listen 80;
error_log syslog:server=unix:/dev/log;
access_log syslog:server=unix:/dev/log;
proxy_set_header X-Forwarded-For $remote_addr;
location / {
proxy_pass http://hub;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_read_timeout 1200s;
# used for view/edit office file via Office Online Server
client_max_body_size 0;
}
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_pass http://files;
proxy_http_version 1.1;
client_max_body_size 0;
proxy_connect_timeout 3s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
send_timeout 3600s;
}
location /seafdav {
fastcgi_pass webdav;
fastcgi_keep_conn on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
client_max_body_size 0;
}
# location /media {
# root /opt/seafile/seafile-server-latest/seahub;
# }
}
}

14
nginx/backends.conf Normal file
View File

@ -0,0 +1,14 @@
upstream hub {
server 127.0.0.1:8000;
keepalive 2;
}
upstream files {
server 127.0.0.1:8082;
keepalive 4;
}
upstream webdav {
server 127.0.0.1:8080;
keepalive 2;
}

0
nginx/extra.conf Normal file
View File

22
nginx/nginx.conf Normal file
View File

@ -0,0 +1,22 @@
events {
worker_connections 64;
}
http {
include backends.conf;
disable_symlinks off;
server {
listen 80;
error_log /dev/stderr;
include seafile/*.conf;
include extra.conf;
}
}

0
nginx/seafile/media.conf Normal file
View File

View File

@ -0,0 +1,5 @@
location /seafdav {
proxy_pass http://webdav;
client_max_body_size 0;
}

View File

@ -0,0 +1,10 @@
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_pass http://files;
proxy_http_version 1.1;
client_max_body_size 0;
proxy_connect_timeout 3s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
send_timeout 3600s;
}

14
nginx/seafile/seahub.conf Normal file
View File

@ -0,0 +1,14 @@
location / {
proxy_pass http://hub;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_read_timeout 1200s;
# used for view/edit office file via Office Online Server
client_max_body_size 0;
access_log /dev/stdout;
}

View File

@ -4,3 +4,4 @@ setuptools
simplejson simplejson
python-memcached python-memcached
urllib3 urllib3
lxml

115
riffol.conf Normal file
View File

@ -0,0 +1,115 @@
init seafile {
application_groups [seafile]
}
application_group seafile {
applications [
setup
seafile
seahub
nginx
]
}
init seafile {
application_groups [seafile]
}
application_group seafile {
applications [
setup
seafile
seahub
nginx
]
}
application setup {
mode oneshot
start [ /usr/bin/setup ]
dir /opt/seafile
env {
new {
SEAF /opt/seafile
}
pass {
SEAF_UPGRADE_INTERVAL SEAF_UPGRADE_INTERVAL
SEAF_VERSION SEAF_VERSION
SEAF_NAME SEAF_NAME
SEAF_MYSQL SEAF_MYSQL
SEAF_MYSQL_HOST SEAF_MYSQL_HOST
SEAF_MYSQL_PORT SEAF_MYSQL_PORT
SEAF_MYSQL_USER SEAF_MYSQL_USER
SEAF_MYSQL_DB_SEAF SEAF_MYSQL_DB_SEAF
SEAF_MYSQL_DB_HUB SEAF_MYSQL_DB_HUB
SEAF_MYSQL_DB_CCNET SEAF_MYSQL_DB_CCNET
}
}
}
application seafile {
mode forking
pidfile /var/run/seafile/seaf-server.pid
requires [ setup ]
start [ /usr/bin/seafile, start ]
stop [ /usr/bin/seafile, stop ]
dir /opt/seafile
healthcheck [ server ]
healthcheckfail restart
}
application seahub {
mode forking
requires [ setup, seafile ]
pidfile /var/run/seafile/seahub.pid
start [ /usr/bin/seahub, start, 8000 ]
stop [ /usr/bin/seahub, stop ]
dir /opt/seafile
healthcheck [ hub ]
healthcheckfail restart
}
application nginx {
mode forking
pidfile /var/run/nginx.pid
requires [ setup, seahub ]
start [ /usr/sbin/nginx ]
dir /opt/seafile
healthcheck [ http, hub ]
healthcheckfail restart
}
healthchecks riffol {
checks [
proc://riffol
]
timeout 2
interval 1000
}
healthcheck http {
checks [
tcp://127.0.0.1:80
]
interval 30
timeout 20
}
healthcheck hub {
checks [
tcp://127.0.0.1:8000
tcp://127.0.0.1:8080
]
interval 80
timeout 60
}
healthcheck server {
checks [
tcp://127.0.0.1:8082
proc://ccnet-server
proc://seaf-server
]
interval 10
timeout 5
}

View File

@ -1,168 +0,0 @@
#!/bin/bash
LATEST=$SEAF/seafile-server-latest
PIDS=$SEAF/pids
PIDFILES=("$PIDS" "$LATEST/runtime" "/var/run/nginx")
COMMANDS=("seaf-server $LATEST/seafile.sh start" "seahub $LATEST/seahub.sh ${SEAF_HUB_MODE:-start} 8000" "nginx /usr/sbin/nginx")
function stop {
#Kill when hitting CTRL+C repeatedly
trap stop_kill SIGTERM
$0 stop
}
function stop_kill {
$0 kill
}
function ext_url {
echo "${SEAF_URL:-http://$(hostname)}/seafhttp"
}
function patch_seahub_conf {
KEY="FILE_SERVER_ROOT"
ENTRY="$KEY = '$(ext_url)'"
CONF="$SEAF/conf/seahub_settings.py"
grep "$KEY" -i "$CONF"
if [ $? -eq 1 ]; then
echo "Patched seahub_settings.py: set $ENTRY"
echo -e "\n$ENTRY" >> "$CONF"
fi
}
function last_update {
if [ -e "$LATEST/install_date" ]; then
date -d $(cat "$LATEST/install_date") "+%s"
else
echo 0
fi
}
function pid {
for LOC in ${PIDFILES[@]}; do
if [ -e "$LOC/$1.pid" ]; then
cat "$LOC/$1.pid"
return 0
fi
done
pgrep -f "/$1"
}
case "$1" in
run)
if [ ! -e "$LATEST" ]; then
(>&2 echo This appears to be the fist run, installing..)
mkdir -p $SEAF/conf
cp /etc/seafile/* $SEAF/conf/* -rf
$0 run-upgrade
exit
else
patch_seahub_conf
for CMD in "${COMMANDS[@]}"; do
INFO=($CMD)
$0 manage-component "${INFO[0]}" start "${INFO[1]}" "${INFO[@]:2}"
done
wait
fi
trap stop SIGINT SIGQUIT SIGTERM
LAST_UPGRADE=$(last_update)
UPGRADE=0
while eval "$0 status > /dev/null"; do
sleep 10;
SINCE_UPGRADE=$(((($(date "+%s") - $LAST_UPGRADE))/(60*60*24)))
if [ $LAST_UPGRADE -gt 0 ] && [ "0$SEAF_UPGRADE_INTERVAL" -gt 0 ] && [ $SINCE_UPGRADE -gt "0$SEAF_UPGRADE_INTERVAL" ]; then
echo "It's been $SINCE_UPGRADE days since the last Upgrade\nSTOPPING TO PERFORM UPGRADE NOW\nSet SEAF_UPGRADE_INTERVAL=0 disable automatic updates"
UPGRADE=1
$0 stop
fi
done
if [ $UPGRADE -eq 1 ]; then
$0 stop-upgrade-run
else
echo "Terminated"
fi
;;
run-upgrade)
$0 upgrade
RES=$?
if [ $RES -eq 127 ]; then
#No upgrade
true
fi
if [ $RES -eq 126 ] && [ ! -e "$LATEST/install_date" ]; then
date +%Y-%m-%d > "$LATEST/install_date"
fi
$0 run
;;
stop)
PIDS=""
for CMD in seafile-controller ccnet seafdav "${COMMANDS[@]}" seafile-controller ccnet; do
$0 manage-component $(echo $CMD | cut -d' ' -f1) stop &
PIDS="$PIDS $!"
done
wait $PIDS
;;
kill)
export SEAF_STOP_TRIES=0
$0 stop
;;
stop-upgrade-run)
$0 stop && $0 upgrade && $0 run
;;
upgrade)
/usr/local/sbin/upgrade main
kill -SIGHUP $(pgrep -o nginx) #Reload nginx
;;
status)
RUNNING=1
for CMD in seafile-controller ccnet "${COMMANDS[@]}"; do
SERVICE="$(echo $CMD | cut -d' ' -f1)"
echo -n "$SERVICE: "
$0 manage-component $SERVICE status
[ $? -eq 0 ] || [ $RUNNING -eq 0 ]
RUNNING=$?
done
[ $RUNNING -eq 0 ]
;;
manage-component)
mkdir -p /var/run/seafile
NAME="$2"
PID=$(pid $NAME)
case "$3" in
start)
CMD="$4"
ARGS="$5"
eval "$CMD $ARGS"
sleep 1
( ! eval "$0 $1 $NAME status" ) && ((>&2 echo Failed to start $NAME); exit 1)
;;
status)
(kill -0 $PID 2> /dev/null && echo Running) || (echo Stopped && exit 1)
;;
stop)
QUERY="$0 $1 $NAME status > /dev/null"
if eval "$QUERY"; then
kill $PID
TRIES=${SEAF_STOP_TRIES:-30}
while eval "$QUERY"; do
TRIES=$((TRIES - 1))
if [ $TRIES -lt 1 ]; then
(>&2 echo Failed to stop gracefully $NAME)
kill -9 $PID
exit 1
else
kill $PID
[ $? -eq 1 ] && break
fi
sleep 1
done
(>&2 echo $NAME has been stopped)
else
(>&2 echo $NAME is not running)
fi
;;
*)
echo "You're doing wrong pal"
;;
esac
;;
*)
(>&2 echo Unknown option $1 options include: run, run-upgrade, upgrade, stop, stop-upgrade)
;;
esac

75
scripts/setup.sh Normal file
View File

@ -0,0 +1,75 @@
#!/bin/bash
set -x
LATEST=$SEAF/seafile-server-latest
function ext_url {
echo "${SEAF_URL:-http://$(hostname)}/seafhttp"
}
function patch_seahub_conf {
KEY="FILE_SERVER_ROOT"
ENTRY="$KEY = '$(ext_url)'"
CONF="$SEAF/conf/seahub_settings.py"
grep "$KEY" -i "$CONF"
if [ $? -eq 1 ]; then
echo "Patched seahub_settings.py: set $ENTRY"
echo -e "\n$ENTRY" >> "$CONF"
fi
}
function last_update {
if [ -e "$LATEST/install_date" ]; then
date -d $(cat "$LATEST/install_date") "+%s"
else
echo 1000000
fi
}
function timestamp {
date +%Y-%m-%d > "$LATEST/install_date"
}
function revert {
rm -rf "$LATEST"
}
### Setup ###
if [ ! -e "$LATEST" ]; then
(>&2 echo This appears to be the fist run, installing..)
trap revert ERR
mkdir -p $SEAF/conf
cp -f /etc/seafile/* /opt/seafile/conf/
/usr/local/sbin/upgrade main
RES="$?"
if [ "$RES" -eq 126 ]; then
(>&2 echo Entering setup)
INSTALLDIR=$(cat $SEAF/ahead)
rm -rf $SEAF/ahead
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
cp -f /etc/seafile/* /opt/seafile/conf/
timestamp
exit 0
fi
if [ ! "$RES" -eq 1 ]; then
exit 0
fi
(>&2 echo "Installation failed")
exit 1
else
LAST_UPGRADE=$(last_update)
SINCE_UPGRADE=$(((($(date "+%s") - $LAST_UPGRADE))/(60*60*24)))
if [ $LAST_UPGRADE -gt 0 ] && [ "0$SEAF_UPGRADE_INTERVAL" -gt 0 ] && [ $SINCE_UPGRADE -gt "0$SEAF_UPGRADE_INTERVAL" ]; then
(>&2 echo "It's been $SINCE_UPGRADE days since the last Upgrade\nPERFORMING UPGRADE NOW\nSet SEAF_UPGRADE_INTERVAL=0 disable automatic updates")
/usr/local/sbin/upgrade main
timestamp
fi
patch_seahub_conf
fi

View File

@ -37,6 +37,14 @@ def list_command(page="https://www.seafile.com/en/download/"):
def current_version_command(): def current_version_command():
print(current_version()) 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(): def current_version():
current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest")) current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest"))
res = re.findall(version_re,current) res = re.findall(version_re,current)
@ -47,12 +55,14 @@ def perform_upgrade_command(version,mysql=False,yes=True):
scripts = os.path.join(seaf_home,"seafile-server-%s" % version, "upgrade") scripts = os.path.join(seaf_home,"seafile-server-%s" % version, "upgrade")
current = map(lambda x: int(x), current_version().split(".")) current = map(lambda x: int(x), current_version().split("."))
target = map(lambda x: int(x), version.split(".")) 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 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 "")) #if not call(["seafile-server","setup", os.path.join(seaf_home,"seafile-server-%s" % version) ],stdout=sys.stdout, stdin=sys.stdin):
call(["sh","-c",installer],stdout=sys.stdout, stdin=sys.stdin) # sys.exit(1)
return 0 crumb = open(seaf_home + "/ahead", 'w')
crumb.write(os.path.join(seaf_home,"seafile-server-%s" % version))
crumb.close()
sys.exit(126)
script_re = "^upgrade_(\d+).(\d+)_(\d+).(\d+)\.sh$" script_re = "^upgrade_(\d+).(\d+)_(\d+).(\d+)\.sh$"
run = [] run = []
last = None last = None
@ -70,20 +80,43 @@ def perform_upgrade_command(version,mysql=False,yes=True):
cmd.append(script) cmd.append(script)
call(["/bin/sh", "-c", ''.join(cmd)], stdout=sys.stdout, stdin=(None if yes else sys.stdin)) call(["/bin/sh", "-c", ''.join(cmd)], stdout=sys.stdout, stdin=(None if yes else sys.stdin))
def install_command(url): def download(url, version):
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
if call(["/bin/sh", "-c", 'cd %s; curl %s | tar xzv' % (tmp, url)]) == 0: filename = "server_%s.tar.gz" % version
pks = os.path.join(seaf_home, "pkg")
if not os.path.exists(pks):
os.mkdir(pks)
dest = os.path.join(pks, filename)
if os.path.exists(dest):
return dest
if call(["/bin/sh", "-c", 'curl %s --output %s/%s' % (url, tmp, filename)]) == 0:
shutil.move(os.path.join(tmp,filename), dest)
call(["/bin/chmod", "-w", dest])
return dest
else:
print("Download failed")
sys.exit(1)
return 0
def install_command(url, version):
pkg = download(url, version)
tmp = tempfile.mkdtemp()
if pkg and call(["/bin/sh", "-c", 'cd %s; tar xzvf %s' % (tmp, pkg)]) == 0:
for f in os.listdir(tmp): for f in os.listdir(tmp):
dest = os.path.join(seaf_home, os.path.basename(f))
if len(re.findall(version_re, f)) > 0: if len(re.findall(version_re, f)) > 0:
dest = os.path.join(seaf_home, os.path.basename(f)) if not os.path.exists(dest):
shutil.move(os.path.join(tmp,f), dest) shutil.move(os.path.join(tmp,f), dest)
else:
shutil.rmtree(tmp)
print("Found previous installation, resuming setup")
current = current_version() current = current_version()
target_version = ''.join(re.findall(version_re,dest)) target_version = ''.join(re.findall(version_re,dest))
if len(current) == 1: current = current[0] if len(current) == 1: current = current[0]
else: current = "0.0.0" else: current = "0.0.0"
print("Upgrading from: %s -> %s" % (current, target_version)) print("Upgrading from: %s -> %s" % (current, target_version))
perform_upgrade_command(target_version,mysql=(os.environ["SEAF_MYSQL"] or False)) perform_upgrade_command(target_version,mysql=("SEAF_MYSQL" in os.environ and os.environ["SEAF_MYSQL"]))
if len(os.listdir(tmp)) != 0: if os.path.exists(tmp) and len(os.listdir(tmp)) != 0:
print("Failed to unpack update") print("Failed to unpack update")
os.rmdir(tmp) os.rmdir(tmp)
return 1 return 1
@ -95,19 +128,21 @@ def main_command(version="latest",page="https://www.seafile.com/en/download/"):
avail = available(page) avail = available(page)
install = None install = None
if version == "latest": if version == "latest":
(install,version) = avail.items() (version,install) = avail.items()[0]
else: else:
if version in dict(avail.items()): if version in dict(avail.items()):
install = dict(avail.items())[version] install = dict(avail.items())[version]
if version_int(current_version()) == version_int(version): if version_int(current_version()) == version_int(version):
print("%s(%s) is already installed" % (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: if install:
print("Installing: %s" % install[1]) print("Installing: %s" % version)
return install_command(install[1]) sys.exit(install_command(install, version))
else: else:
print("Couldn't determine download for %s" % version) print("Couldn't determine download for %s" % version)
return 1 sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
import scriptine import scriptine

30
seafile.service Normal file
View File

@ -0,0 +1,30 @@
[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"
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