|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2011-present Mediasift Ltd |
|
5
|
|
|
* All rights reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
8
|
|
|
* modification, are permitted provided that the following conditions |
|
9
|
|
|
* are met: |
|
10
|
|
|
* |
|
11
|
|
|
* * Redistributions of source code must retain the above copyright |
|
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
|
13
|
|
|
* |
|
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
|
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
|
16
|
|
|
* the documentation and/or other materials provided with the |
|
17
|
|
|
* distribution. |
|
18
|
|
|
* |
|
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
|
20
|
|
|
* contributors may be used to endorse or promote products derived |
|
21
|
|
|
* from this software without specific prior written permission. |
|
22
|
|
|
* |
|
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
|
35
|
|
|
* |
|
36
|
|
|
* @category Libraries |
|
37
|
|
|
* @package Storyplayer/Modules/Supervisor |
|
38
|
|
|
* @author Shweta Saikumar <[email protected]> |
|
39
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
|
40
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
41
|
|
|
* @link http://datasift.github.io/storyplayer |
|
42
|
|
|
*/ |
|
43
|
|
|
|
|
44
|
|
|
namespace Storyplayer\SPv2\Modules\Supervisor; |
|
45
|
|
|
|
|
46
|
|
|
use DataSift\Storyplayer\HostLib; |
|
47
|
|
|
use DataSift\Storyplayer\OsLib; |
|
48
|
|
|
use DataSift\Storyplayer\PlayerLib\StoryTeller; |
|
49
|
|
|
|
|
50
|
|
|
use DataSift\Stone\ObjectLib\BaseObject; |
|
51
|
|
|
|
|
52
|
|
|
use Storyplayer\SPv2\Modules\Exceptions; |
|
53
|
|
|
use Storyplayer\SPv2\Modules\Host; |
|
54
|
|
|
use Storyplayer\SPv2\Modules\Host\HostAwareModule; |
|
55
|
|
|
use Storyplayer\SPv2\Modules\Log; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* start and stop programs under supervisor |
|
59
|
|
|
* |
|
60
|
|
|
* @category Libraries |
|
61
|
|
|
* @package Storyplayer/Modules/Supervisor |
|
62
|
|
|
* @author Shweta Saikumar <[email protected]> |
|
63
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
|
64
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
65
|
|
|
* @link http://datasift.github.io/storyplayer |
|
66
|
|
|
*/ |
|
67
|
|
|
class UsingSupervisor extends HostAwareModule |
|
68
|
|
|
{ |
|
69
|
|
View Code Duplication |
public function startProgram($programName) |
|
70
|
|
|
{ |
|
71
|
|
|
// what are we doing? |
|
72
|
|
|
$log = Log::usingLog()->startAction("start program '{$programName}' on host '{$this->args[0]}'"); |
|
73
|
|
|
|
|
74
|
|
|
// get the host details |
|
75
|
|
|
$hostDetails = $this->getHostDetails(); |
|
76
|
|
|
|
|
77
|
|
|
// start the program |
|
78
|
|
|
$result = Host::onHost($hostDetails->hostId)->runCommand("sudo supervisorctl start '{$programName}'"); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
// did the command succeed? |
|
81
|
|
|
if ($result->didCommandFail()) { |
|
82
|
|
|
throw Exceptions::newActionFailedException(__METHOD__, "failed to start process '{$programName} (via supervisord)'"); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// all done |
|
86
|
|
|
$log->endAction(); |
|
87
|
|
|
return true; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
View Code Duplication |
public function stopProgram($programName) |
|
91
|
|
|
{ |
|
92
|
|
|
// what are we doing? |
|
93
|
|
|
$log = Log::usingLog()->startAction("stop program '{$programName}' on host '{$this->args[0]}'"); |
|
94
|
|
|
|
|
95
|
|
|
// get the host details |
|
96
|
|
|
$hostDetails = $this->getHostDetails(); |
|
97
|
|
|
|
|
98
|
|
|
// stop the program |
|
99
|
|
|
$result = Host::onHost($hostDetails->hostId)->runCommand("sudo supervisorctl stop '{$programName}'"); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
// did the command succeed? |
|
102
|
|
|
if ($result->didCommandFail()) { |
|
103
|
|
|
throw Exceptions::newActionFailedException(__METHOD__, "failed to start process '{$programName} (via supervisord)'"); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// all done |
|
107
|
|
|
$log->endAction(); |
|
108
|
|
|
return true; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.