Replace Twenty::Path
This commit is contained in:
parent
e7f910be5f
commit
3105be205e
4 changed files with 49 additions and 51 deletions
|
@ -3,7 +3,7 @@
|
|||
class Twenty::Command::Down < Twenty::Command
|
||||
set_banner usage: "twenty down [OPTIONS]",
|
||||
description: "Stop the twenty web server"
|
||||
include Twenty::Path
|
||||
|
||||
prepend Twenty::Command::SQLiteMixin
|
||||
prepend Twenty::Command::RescueMixin
|
||||
|
||||
|
@ -15,19 +15,18 @@ class Twenty::Command::Down < Twenty::Command
|
|||
private
|
||||
|
||||
def run_command(options)
|
||||
if File.readable?(pidfile)
|
||||
Process.kill("SIGINT", Integer(pid))
|
||||
if File.readable?(pid)
|
||||
pid = Integer(File.binread(pid).gsub(/[^\d]/, ""))
|
||||
Process.kill("SIGINT", pid)
|
||||
else
|
||||
warn "PID file is not readable."
|
||||
warn "[x] #{pid} is not readable"
|
||||
end
|
||||
rescue Errno::ESRCH
|
||||
warn "No such process."
|
||||
FileUtils.rm(pidfile)
|
||||
warn "[x] Process not found"
|
||||
rm(pid)
|
||||
end
|
||||
|
||||
def pid
|
||||
@pid ||= File
|
||||
.binread(pidfile)
|
||||
.gsub(/[^\d]/, "")
|
||||
Twenty.pid
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,6 @@ class Twenty::Command::Up < Twenty::Command
|
|||
"Listen on a UNIX socket"
|
||||
|
||||
include CommonOptionMixin
|
||||
include Twenty::Path
|
||||
prepend Twenty::Command::MigrationMixin
|
||||
prepend Twenty::Command::SQLiteMixin
|
||||
prepend Twenty::Command::RescueMixin
|
||||
|
@ -30,12 +29,16 @@ class Twenty::Command::Up < Twenty::Command
|
|||
private
|
||||
|
||||
def run_command(options)
|
||||
File.binwrite(pidfile, Process.pid.to_s)
|
||||
File.binwrite(pid, Process.pid.to_s)
|
||||
thr = Twenty::Rack.server(options).start
|
||||
thr.join
|
||||
rescue Interrupt
|
||||
thr.kill
|
||||
ensure
|
||||
FileUtils.rm(pidfile)
|
||||
FileUtils.rm(pid)
|
||||
end
|
||||
|
||||
def pid
|
||||
Twenty.pid
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,14 +3,42 @@
|
|||
module Twenty
|
||||
require "fileutils"
|
||||
require "sequel"
|
||||
require_relative "server/path"
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the default path for the SQLite database
|
||||
def self.default_database
|
||||
@default_database ||= File.join(Path.datadir, "database.sqlite")
|
||||
end
|
||||
extend Module.new {
|
||||
extend FileUtils
|
||||
require "tmpdir"
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the path for the default SQLite database
|
||||
def default_database
|
||||
@default_database ||= File.join(datadir, "database.sqlite")
|
||||
end
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the directory where twenty stores data
|
||||
def datadir
|
||||
File.join(Dir.home, ".local", "share", "twenty")
|
||||
end
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the directory where twenty stores temporary data
|
||||
def tmpdir
|
||||
File.join(Dir.tmpdir, "twenty")
|
||||
end
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the path to a PID file
|
||||
def pid
|
||||
File.join(tmpdir, "server.pid")
|
||||
end
|
||||
|
||||
mkdir_p(datadir)
|
||||
mkdir_p(tmpdir)
|
||||
}
|
||||
|
||||
##
|
||||
# Establishes a database connection
|
||||
|
@ -34,7 +62,6 @@ module Twenty
|
|||
@connection
|
||||
end
|
||||
|
||||
FileUtils.touch(default_database)
|
||||
require_relative "server/graphql"
|
||||
require_relative "server/rack"
|
||||
end
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty::Path
|
||||
require "tmpdir"
|
||||
extend self
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the directory where twenty stores persistent data.
|
||||
def datadir
|
||||
File.join(Dir.home, ".local", "share", "twenty")
|
||||
end
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the directory where twenty stores temporary data.
|
||||
def tmpdir
|
||||
File.join(Dir.tmpdir, "twenty")
|
||||
end
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
# Returns the file where twenty can write the PID of
|
||||
# a web server running in the background.
|
||||
def pidfile
|
||||
File.join(tmpdir, "server.pid")
|
||||
end
|
||||
|
||||
FileUtils.mkdir_p(datadir)
|
||||
FileUtils.mkdir_p(tmpdir)
|
||||
end
|
Loading…
Reference in a new issue