Skip to content

Commit

Permalink
Merge pull request #9 from tanmaykm/tan/misc
Browse files Browse the repository at this point in the history
use artifacts (Openresty_jll)
  • Loading branch information
tanmaykm authored Oct 30, 2020
2 parents dedf19a + 6c5bf2d commit f89f680
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 73 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions deps/.gitignore

This file was deleted.

37 changes: 0 additions & 37 deletions deps/build.jl

This file was deleted.

49 changes: 22 additions & 27 deletions src/Openresty.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f89f680

Please sign in to comment.