Skip to content

Commit dac1013

Browse files
committed
Merge branch 'develop'
2 parents 6508ac5 + 996f4c2 commit dac1013

File tree

8 files changed

+231
-1
lines changed

8 files changed

+231
-1
lines changed

.distignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.DS_Store
2+
.git
3+
.gitignore
4+
.gitlab-ci.yml
5+
.editorconfig
6+
.travis.yml
7+
behat.yml
8+
circle.yml
9+
bin/
10+
features/
11+
utils/
12+
*.zip
13+
*.tar.gz
14+
*.swp
15+
*.txt
16+
*.log

.editorconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
16+
[{.jshintrc,*.json,*.yml,*.feature}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[{*.txt,wp-config-sample.php}]
21+
end_of_line = crlf
22+
23+
[composer.json]
24+
indent_style = space
25+
indent_size = 4

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
ee.local.yml
3+
node_modules/
4+
vendor/
5+
*.zip
6+
*.tar.gz
7+
*.swp
8+
*.txt
9+
*.log
10+
composer.lock
11+
.idea
12+
*.db

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
# service-command
1+
# EasyEngine/service-command
2+
3+
Manages global `ee-nginx-proxy` container.
4+
5+
## About `ee-nginx-proxy`
6+
`ee-nginx-proxy` is the main container which routes all incoming request to site-specific containers.
7+
8+
So let's say you have foo.com and bar.com on same ee server. When anyone requests either website, the request will first go to `ee-nginx-proxy` which will forward the request to appropriate nginx container of site (In this case foo.com or bar.com).
9+
10+
## Usage:
11+
12+
```
13+
ee service [start|stop|restart|reload] <service-name>
14+
15+
ee service start ee-nginx-proxy # starts ee-nginx-proxy container
16+
ee service restart ee-nginx-proxy # restarts ee-nginx-proxy container
17+
ee service stop ee-nginx-proxy # stops ee-nginx-proxy container
18+
ee service reload ee-nginx-proxy # reloads the configuration of ee-nginx-proxy container
19+
```
20+
21+
For more info run ee service --help

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "easyengine/service-command",
3+
"description": "Command to manager global containers/services in EasyEngine",
4+
"type": "ee-cli-package",
5+
"homepage": "https://github.com/easyengine/service-command",
6+
"license": "MIT",
7+
"authors": [],
8+
"minimum-stability": "dev",
9+
"prefer-stable": true,
10+
"autoload": {
11+
"psr-4": {
12+
"": "src/"
13+
},
14+
"files": [ "service-command.php" ]
15+
},
16+
"extra": {
17+
"branch-alias": {
18+
"dev-master": "1.x-dev"
19+
},
20+
"bundled": true,
21+
"commands": [
22+
"service start",
23+
"service stop",
24+
"service restart",
25+
"service reload"
26+
]
27+
}
28+
}

ee.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require:
2+
- service-command.php

service-command.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
if ( ! class_exists( 'EE' ) ) {
4+
return;
5+
}
6+
7+
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
8+
if ( file_exists( $autoload ) ) {
9+
require_once $autoload;
10+
}
11+
12+
EE::add_command( 'service', 'Service_Command' );

src/Service_Command.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
use EE\Utils;
4+
5+
/**
6+
* Manages global services of EasyEngine.
7+
*
8+
* ## EXAMPLES
9+
*
10+
* # Restarts global nginx proxy service
11+
* $ ee service restart nginx-proxy
12+
*
13+
* @package ee-cli
14+
*/
15+
class Service_Command extends EE_Command {
16+
17+
/**
18+
* @var array Array of services defined in global docker-compose.yml
19+
*/
20+
private $whitelisted_services = [
21+
'nginx-proxy',
22+
];
23+
24+
/**
25+
* Service_Command constructor.
26+
*
27+
* Changes directory to EE_CONF_ROOT since that's where all docker-compose commands will be executed
28+
*/
29+
public function __construct() {
30+
chdir( EE_CONF_ROOT );
31+
}
32+
33+
/**
34+
* Starts global services.
35+
*
36+
* ## OPTIONS
37+
*
38+
* <service-name>
39+
* : Name of service.
40+
*/
41+
public function start( $args, $assoc_args ) {
42+
$service = $this->filter_service( $args );
43+
44+
EE::exec( "docker-compose start $service", true, true );
45+
}
46+
47+
/**
48+
* Returns valid service name from arguments.
49+
*/
50+
private function filter_service( $args ) {
51+
$services = array_intersect( $this->whitelisted_services, $args );
52+
53+
if ( empty( $services ) ) {
54+
EE::error( "Unable to find global EasyEngine service $args[0]" );
55+
}
56+
57+
return $services[0];
58+
}
59+
60+
/**
61+
* Stops global services.
62+
*
63+
* ## OPTIONS
64+
*
65+
* <service-name>
66+
* : Name of service.
67+
*/
68+
public function stop( $args, $assoc_args ) {
69+
$service = $this->filter_service( $args );
70+
EE::exec( "docker-compose stop $service", true, true );
71+
}
72+
73+
/**
74+
* Restarts global services.
75+
*
76+
* ## OPTIONS
77+
*
78+
* <service-name>
79+
* : Name of service.
80+
*/
81+
public function restart( $args, $assoc_args ) {
82+
$service = $this->filter_service( $args );
83+
EE::exec( "docker-compose restart $service", true, true );
84+
}
85+
86+
/**
87+
* Reloads global service without restarting services.
88+
*
89+
* ## OPTIONS
90+
*
91+
* <service-name>
92+
* : Name of service.
93+
*/
94+
public function reload( $args, $assoc_args ) {
95+
$service = $this->filter_service( $args );
96+
$command = $this->service_reload_command( $service );
97+
EE::exec( "docker-compose exec $service $command", true, true );
98+
}
99+
100+
/**
101+
* Returns reload command of a service.
102+
* This is necessary since command to reload each service can be different.
103+
*
104+
* @param $service string name of service
105+
*
106+
* @return mixed
107+
*/
108+
private function service_reload_command( string $service ) {
109+
$command_map = [
110+
'nginx-proxy' => "sh -c 'nginx -t && service nginx reload'",
111+
];
112+
113+
return $command_map[ $service ];
114+
}
115+
}

0 commit comments

Comments
 (0)