From 6c5bf2d17c0f1bed5a0a1745d602921d4e2168ef Mon Sep 17 00:00:00 2001 From: tan Date: Thu, 29 Oct 2020 19:51:56 +0530 Subject: [PATCH] use artifacts use artifacts, remove BinaryProvider dependency --- .travis.yml | 3 +-- Project.toml | 8 ++++---- deps/.gitignore | 3 --- deps/build.jl | 37 ------------------------------------ src/Openresty.jl | 49 ++++++++++++++++++++++-------------------------- 5 files changed, 27 insertions(+), 73 deletions(-) delete mode 100644 deps/.gitignore delete mode 100644 deps/build.jl diff --git a/.travis.yml b/.travis.yml index 4561712..3a972f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,9 @@ os: - linux julia: - - 1.1 - - 1.2 - 1.3 - 1.4 + - 1.5 - nightly # # Uncomment the following lines to allow failures on nightly julia diff --git a/Project.toml b/Project.toml index fa18501..d307e9d 100644 --- a/Project.toml +++ b/Project.toml @@ -3,14 +3,14 @@ uuid = "7d4ad63e-389f-5fab-a457-725f5c98637d" keywords = ["openresty", "nginx", "julia"] license = "MIT" desc = "Launch and manage Openresty (Nginx) from Julia" -version = "0.1.6" +version = "0.2.0" [deps] -BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" +Openresty_jll = "87da34d4-7b1b-5a94-8376-8cb65bf3132c" [compat] -julia = "≥ 1.1.0" +julia = "≥ 1.3.0" +Openresty_jll = "1.15.8" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/deps/.gitignore b/deps/.gitignore deleted file mode 100644 index 959dddf..0000000 --- a/deps/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -build.log -deps.jl -usr diff --git a/deps/build.jl b/deps/build.jl deleted file mode 100644 index 418eef4..0000000 --- a/deps/build.jl +++ /dev/null @@ -1,37 +0,0 @@ -using BinaryProvider # requires BinaryProvider 0.3.0 or later - -# Parse some basic command-line arguments -const verbose = "--verbose" in ARGS -const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr"))) -products = [ - ExecutableProduct(prefix, "openresty", :openresty), -] - -# Download binaries from hosted location -bin_prefix = "https://github.com/tanmaykm/OpenrestyBuilder/releases/download/v1.15.8" - -# Listing of files generated by BinaryBuilder: -download_info = Dict( - Linux(:x86_64, libc=:glibc) => ("$bin_prefix/OpenrestyBuilder.v1.15.8.x86_64-linux-gnu.tar.gz", "d3557fe9cf0c04b78ece3061ad85c4123970626c63f0731255d1006e7a8104e2"), - Linux(:x86_64, libc=:musl) => ("$bin_prefix/OpenrestyBuilder.v1.15.8.x86_64-linux-musl.tar.gz", "50e0c5b241d15cb911317c1ed4a1496956f1d9704a8b3c3e3fd076eeb131a319"), -) - -# Install unsatisfied or updated dependencies: -unsatisfied = any(!satisfied(p; verbose=verbose) for p in products) -dl_info = choose_download(download_info, platform_key_abi()) -if dl_info === nothing && unsatisfied - # If we don't have a compatible .tar.gz to download, complain. - # Alternatively, you could attempt to install from a separate provider, - # build from source or something even more ambitious here. - error("Your platform (\"$(Sys.MACHINE)\", parsed as \"$(triplet(platform_key_abi()))\") is not supported by this package!") -end - -# If we have a download, and we are unsatisfied (or the version we're -# trying to install is not itself installed) then load it up! -if unsatisfied || !isinstalled(dl_info...; prefix=prefix) - # Download and install binaries - install(dl_info...; prefix=prefix, force=true, verbose=verbose) -end - -# Write out a deps.jl file that will contain mappings for our products -write_deps_file(joinpath(@__DIR__, "deps.jl"), products, verbose=verbose) diff --git a/src/Openresty.jl b/src/Openresty.jl index 63d22e2..c5bb3c9 100644 --- a/src/Openresty.jl +++ b/src/Openresty.jl @@ -1,25 +1,15 @@ module Openresty -include("../deps/deps.jl") +using Openresty_jll export OpenrestyCtx export setup, start, stop, restart, isrunning, reopen, reload -const nginxbindir = abspath(joinpath(dirname(@__FILE__), "../deps/usr/nginx/sbin")) -const htmltemplatedir = abspath(joinpath(dirname(@__FILE__), "../deps/usr/nginx/html")) -const conftemplatedir = abspath(joinpath(dirname(@__FILE__), "../deps/usr/nginx/conf")) -const luapath = joinpath(dirname(dirname(nginxbindir)), "lualib", "?.lua") -const luacpath = joinpath(dirname(dirname(nginxbindir)), "lualib", "?.so") - -function __init__() - check_deps() - if !isdir(htmltemplatedir) - error("$(htmltemplatedir) does not exist, Please re-run Pkg.build(\"Openresty\"), and restart Julia.") - end - if !isdir(conftemplatedir) - error("$(conftemplatedir) does not exist, Please re-run Pkg.build(\"Openresty\"), and restart Julia.") - end -end +const nginxbindir = joinpath(nginx_dir, "sbin") +const htmltemplatedir = joinpath(nginx_dir, "html") +const conftemplatedir = joinpath(nginx_dir, "conf") +const luapath = joinpath(lualib_dir, "?.lua") +const luacpath = joinpath(lualib_dir, "?.so") mutable struct OpenrestyCtx workdir::String @@ -97,13 +87,15 @@ end function start(ctx::OpenrestyCtx; accesslog=nothing, errorlog=nothing, append::Bool=(isa(accesslog,AbstractString)||isa(errorlog,AbstractString))) config = conffile(ctx) - @debug("starting", openresty, workdir=ctx.workdir, nginxbindir, sudo=ctx.sudo) - command = Cmd(ctx.sudo ? `sudo $openresty -p $(ctx.workdir)` : `$openresty -p $(ctx.workdir)`; detach=true, dir=nginxbindir) - if (accesslog === nothing) && (errorlog === nothing) - proc = run(command; wait=false) - else - redirected_command = pipeline(command, stdout=accesslog, stderr=errorlog, append=append) - proc = run(redirected_command; wait=false) + proc = openresty() do openresty_path + @debug("starting", openresty_path, workdir=ctx.workdir, nginxbindir, sudo=ctx.sudo) + command = Cmd(ctx.sudo ? `sudo $openresty_path -p $(ctx.workdir)` : `$openresty_path -p $(ctx.workdir)`; detach=true, dir=nginxbindir) + if (accesslog === nothing) && (errorlog === nothing) + run(command; wait=false) + else + redirected_command = pipeline(command, stdout=accesslog, stderr=errorlog, append=append) + run(redirected_command; wait=false) + end end for idx in 1:15 @@ -118,10 +110,11 @@ isrunning(ctx::OpenrestyCtx) = (ctx.pid !== nothing) ? isrunning(ctx, ctx.pid) : function isrunning(ctx::OpenrestyCtx, pid::Int) # we do have read permission on cmdline even if process was started with sudo cmdlinefile = "/proc/$pid/cmdline" + openresty_path = openresty(p->p) if isfile(cmdlinefile) cmdline = read(cmdlinefile, String) - @debug("found command line", cmdlinefile, cmdline , openresty, ctx.workdir) - if occursin(openresty, cmdline) && occursin(ctx.workdir, cmdline) + @debug("found command line", cmdlinefile, cmdline , openresty_path, ctx.workdir) + if occursin(openresty_path, cmdline) && occursin(ctx.workdir, cmdline) # process still running return true end @@ -160,8 +153,10 @@ signalreload(ctx::OpenrestyCtx) = signal(ctx, "reload") function signal(ctx::OpenrestyCtx, signal::String) if isrunning(ctx) @debug("sending signal $signal") - command = Cmd(ctx.sudo ? `sudo $openresty -p $(ctx.workdir) -s $signal` : `$openresty -p $(ctx.workdir) -s $signal`; dir=nginxbindir) - run(command) + openresty() do openresty_path + command = Cmd(ctx.sudo ? `sudo $openresty_path -p $(ctx.workdir) -s $signal` : `$openresty_path -p $(ctx.workdir) -s $signal`; dir=nginxbindir) + run(command) + end end nothing end