Update
This commit is contained in:
parent
2c7b5bd865
commit
8e848fc104
9 changed files with 133 additions and 12 deletions
|
|
@ -57,7 +57,7 @@ impl<'a> Symbol for GitCheckout<'a> {
|
|||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
if let Err(e) = metadata(self.target) {
|
||||
return if e.kind() == io::ErrorKind::NotFound {
|
||||
try!(self.command_runner.run_with_args("git", &["clone", "-b", self.branch, self.source, self.target]));
|
||||
try!(self.command_runner.run_with_args("git", &["clone", "--depth", "1", "-b", self.branch, self.source, self.target]));
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Box::new(e))
|
||||
|
|
|
|||
52
src/symbols/mariadb/database.rs
Normal file
52
src/symbols/mariadb/database.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use std::borrow::Cow;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use symbols::Symbol;
|
||||
|
||||
pub struct MariaDBDatabase<'a> {
|
||||
db_name: Cow<'a, str>,
|
||||
seed_file: &'a str,
|
||||
command_runner: &'a CommandRunner
|
||||
}
|
||||
|
||||
impl<'a> MariaDBDatabase<'a> {
|
||||
pub fn new(db_name: Cow<'a, str>, command_runner: &'a CommandRunner) -> MariaDBDatabase<'a> {
|
||||
MariaDBDatabase {
|
||||
db_name: db_name,
|
||||
seed_file: "/root/seedfile.sql",
|
||||
command_runner: command_runner
|
||||
}
|
||||
}
|
||||
|
||||
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {
|
||||
let output = try!(self.command_runner.run_with_args("mariadb", &["--skip-column-names", "-B", "-e", sql]));
|
||||
if output.status.code() != Some(0) {
|
||||
return Err(try!(String::from_utf8(output.stderr)).into());
|
||||
}
|
||||
Ok(try!(String::from_utf8(output.stdout)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for MariaDBDatabase<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "MariaDB Database {}", self.db_name)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for MariaDBDatabase<'a> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
Ok(try!(self.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))).trim_right() == self.db_name)
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
try!(self.run_sql(&format!("CREATE DATABASE {}", self.db_name)));
|
||||
try!(self.command_runner.run_with_args("sh", &["-c", &format!("mariadb '{}' < {}", self.db_name, self.seed_file)]));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
}
|
||||
5
src/symbols/mariadb/mod.rs
Normal file
5
src/symbols/mariadb/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod database;
|
||||
mod user;
|
||||
|
||||
pub use self::database::MariaDBDatabase;
|
||||
pub use self::user::MariaDBUser;
|
||||
49
src/symbols/mariadb/user.rs
Normal file
49
src/symbols/mariadb/user.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use std::borrow::Cow;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use symbols::Symbol;
|
||||
|
||||
pub struct MariaDBUser<'a> {
|
||||
user_name: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
}
|
||||
|
||||
impl<'a> MariaDBUser<'a> {
|
||||
pub fn new(user_name: Cow<'a, str>, command_runner: &'a CommandRunner) -> MariaDBUser<'a> {
|
||||
MariaDBUser {
|
||||
user_name: user_name,
|
||||
command_runner: command_runner
|
||||
}
|
||||
}
|
||||
|
||||
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {
|
||||
let output = try!(self.command_runner.run_with_args("mariadb", &["--skip-column-names", "-e", sql]));
|
||||
if output.status.code() != Some(0) {
|
||||
return Err(try!(String::from_utf8(output.stderr)).into());
|
||||
}
|
||||
Ok(try!(String::from_utf8(output.stdout)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for MariaDBUser<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "MariaDB User {}", self.user_name)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for MariaDBUser<'a> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
Ok(try!(self.run_sql(&format!("SELECT User FROM mysql.user WHERE User = '{}' AND plugin = 'unix_socket'", self.user_name))).trim_right() == self.user_name)
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
try!(self.run_sql(&format!("GRANT ALL ON {0}.* TO {0} IDENTIFIED VIA unix_socket", self.user_name)));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ pub mod file;
|
|||
pub mod git;
|
||||
pub mod hook;
|
||||
pub mod list;
|
||||
pub mod mariadb;
|
||||
pub mod nginx;
|
||||
pub mod not_a_symlink;
|
||||
pub mod npm;
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
pub mod reload;
|
||||
pub mod server;
|
||||
|
|
|
|||
|
|
@ -100,6 +100,18 @@ location @proxy {{
|
|||
NginxServer::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_php(domain: &'a str, socket_path: &'a str, static_path: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
let content = NginxServer::server_config(domain, &format!("
|
||||
root {};
|
||||
index index.html index.php;
|
||||
location ~ [^/]\\.php(/|$) {{
|
||||
fastcgi_pass unix:{};
|
||||
include \"snippets/fastcgi-php.conf\";
|
||||
}}
|
||||
", static_path, socket_path));
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_static(domain: &'a str, static_path: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
let content = NginxServer::server_config(domain, &format!("
|
||||
root {};
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
pub mod user_session;
|
||||
pub mod node_js_user_service;
|
||||
pub mod reload;
|
||||
pub mod user_session;
|
||||
|
|
|
|||
|
|
@ -4,31 +4,33 @@ use std::fmt;
|
|||
use command_runner::CommandRunner;
|
||||
use symbols::Symbol;
|
||||
|
||||
pub struct NginxReload<'a> {
|
||||
command_runner: &'a CommandRunner,
|
||||
pub struct ReloadService<'a> {
|
||||
service: &'a str,
|
||||
command_runner: &'a CommandRunner
|
||||
}
|
||||
|
||||
impl<'a> NginxReload<'a> {
|
||||
pub fn new(command_runner: &'a CommandRunner) -> Self {
|
||||
NginxReload {
|
||||
impl<'a> ReloadService<'a> {
|
||||
pub fn new(service: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
ReloadService {
|
||||
service: service,
|
||||
command_runner: command_runner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for NginxReload<'a> {
|
||||
impl<'a> Symbol for ReloadService<'a> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
try!(self.command_runner.run_with_args("systemctl", &["reload-or-restart", "nginx"]));
|
||||
try!(self.command_runner.run_with_args("systemctl", &["reload-or-restart", self.service]));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for NginxReload<'a> {
|
||||
impl<'a> fmt::Display for ReloadService<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error>{
|
||||
write!(f, "Reload nginx server")
|
||||
write!(f, "Reload service {}", self.service)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue