win: added stop/restart/destroy/logs/enter commands.

This commit is contained in:
Shuai Lin 2016-12-08 17:47:57 +08:00
parent b4da59b93a
commit 6a748a936f

View file

@ -66,7 +66,13 @@ function main() {
switch ($action) { switch ($action) {
"bootstrap" { do_bootstrap } "bootstrap" { do_bootstrap }
"start" { do_start } "start" { do_start }
"stop" { do_stop }
"restart" { do_restart }
"enter" { do_enter }
"destroy" { do_destroy }
"logs" { do_logs }
"rebuild" { do_rebuild } "rebuild" { do_rebuild }
"manual-upgrade" { do_manual_upgrade }
default { usage } default { usage }
} }
} }
@ -322,7 +328,7 @@ function parse_seafile_container([array]$lines) {
# Equivalent of `docker ps | awk '{ print $1, $(NF) }' | grep " seafile$" | awk '{ print $1 }' || true` # Equivalent of `docker ps | awk '{ print $1, $(NF) }' | grep " seafile$" | awk '{ print $1 }' || true`
function set_running_container() { function set_running_container() {
try { try {
$script:existing = $(parse_seafile_container $(docker ps)) $script:existing = $(parse_seafile_container $(check_output docker ps))
} catch [System.Management.Automation.RemoteException] { } catch [System.Management.Automation.RemoteException] {
$script:existing = "" $script:existing = ""
} }
@ -337,6 +343,13 @@ function set_existing_container() {
} }
} }
function ensure_container_running() {
set_existing_container
if (!($script:existing)) {
err_and_quit "seafile was not started !"
}
}
function ignore_error($cmd) { function ignore_error($cmd) {
if ($args) { if ($args) {
Start-Process -NoNewWindow -Wait -FilePath "$cmd" -ArgumentList $args Start-Process -NoNewWindow -Wait -FilePath "$cmd" -ArgumentList $args
@ -491,7 +504,7 @@ function check_upgrade() {
# use_manual_upgrade=true # use_manual_upgrade=true
if ("true".Equals($use_manual_upgrade)) { if ("true".Equals($use_manual_upgrade)) {
loginfo "Now you can run './launcher manual-upgrade' to do manual upgrade." loginfo "Now you can run './launcher.ps1 manual-upgrade' to do manual upgrade."
exit 0 exit 0
} else { } else {
loginfo "Going to launch the docker container for manual upgrade" loginfo "Going to launch the docker container for manual upgrade"
@ -502,8 +515,10 @@ function check_upgrade() {
function _launch_for_upgrade([switch]$auto) { function _launch_for_upgrade([switch]$auto) {
if ($auto) { if ($auto) {
$script:on_call_error = 'Failed to upgrade to latest version. You can try run it manually by "./launcher.ps1 manual-upgrade"'
$cmd="/scripts/upgrade.py" $cmd="/scripts/upgrade.py"
} else { } else {
$script:on_call_error = "Upgrade failed"
$cmd="/bin/bash" $cmd="/bin/bash"
} }
@ -512,11 +527,48 @@ function _launch_for_upgrade([switch]$auto) {
remove_container seafile-upgrade remove_container seafile-upgrade
$script:on_call_error = 'Failed to upgrade to latest version. You can try run it manually by "./launcher.ps1 manual-upgrade"'
check_call docker run ` check_call docker run `
-it -rm --name seafile-upgrade -h seafile ` -it -rm --name seafile-upgrade -h seafile `
@script:envs @script:volumes $local_image ` @script:envs @script:volumes $local_image `
@script:my_init -- $cmd @script:my_init -- $cmd
} }
function do_manual_upgrade() {
_launch_for_upgrade
loginfo "If you have manually upgraded the server, please update the version stamp by:"
loginfo
loginfo " Set-Content -Path ""$version_stamp_file"" -Value $version"
loginfo " ./launcher.ps1 start"
loginfo
}
function do_stop() {
ensure_container_running
loginfo "Stopping seafile container"
check_call docker stop -t 10 seafile
}
function do_restart() {
do_stop
do_start
}
function do_enter() {
ensure_container_running
loginfo "Launching a linux bash shell in the seafile container"
docker exec -it seafile /bin/bash
}
function do_destroy() {
loginfo "Stopping seafile container"
ignore_error docker stop -t 10 seafile
ignore_error docker rm seafile
}
function do_logs() {
ensure_container_running
docker logs --tail=20 -f seafile
}
main @args main @args