GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 31696d...d014e0 )
by Stuart
05:40
created

UsingHost::startInScreen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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/Host
38
 * @author    Stuart Herbert <[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\Host;
45
46
use DataSift\Storyplayer\OsLib;
47
use DataSift\Stone\ObjectLib\BaseObject;
48
49
use Storyplayer\SPv2\Modules\Exceptions;
50
use Storyplayer\SPv2\Modules\Filesystem;
51
use Storyplayer\SPv2\Modules\Screen;
52
use Storyplayer\SPv2\Modules\Shell;
53
54
/**
55
 * do things with vagrant
56
 *
57
 * @category  Libraries
58
 * @package   Storyplayer/Modules/Host
59
 * @author    Stuart Herbert <[email protected]>
60
 * @copyright 2011-present Mediasift Ltd www.datasift.com
61
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
62
 * @link      http://datasift.github.io/storyplayer
63
 */
64
class UsingHost extends HostAwareModule
65
{
66
    /**
67
     * @deprecated since v2.4.0
68
     */
69
    public function runCommand($command)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
70
    {
71
        return Shell::onHost($this->args[0])->runCommand($command);
72
    }
73
74
    /**
75
     * @deprecated since v2.4.0
76
     */
77
    public function runCommandAsUser($command, $user)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
78
    {
79
        return Shell::onHost($this->args[0])->runCommandAsUser($command, $user);
80
    }
81
82
    /**
83
     * @deprecated since v2.4.0
84
     */
85
    public function runCommandAndIgnoreErrors($command)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
86
    {
87
        return Shell::onHost($this->args[0])->runCommandAndIgnoreErrors($command);
88
    }
89
90
    /**
91
     * @deprecated since v2.4.0
92
     */
93
    public function runCommandAsUserAndIgnoreErrors($command, $user)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
94
    {
95
        return Shell::onHost($this->args[0])->runCommandAsUserAndIgnoreErrors($command, $user);
96
    }
97
98
    /**
99
     * @deprecated since v2.4.0
100
     */
101
    public function startInScreen($sessionName, $commandLine)
102
    {
103
        return Screen::onHost($this->args[0])->startScreen($sessionName, $commandLine);
104
    }
105
106
    /**
107
     * @deprecated since v2.4.0
108
     */
109
    public function stopInScreen($sessionName)
110
    {
111
        return Screen::onHost($this->args[0])->stopScreen($sessionName);
112
    }
113
114
    /**
115
     * @deprecated since v2.4.0
116
     */
117
    public function stopAllScreens()
118
    {
119
        return Screen::onHost($this->args[0])->stopAllScreens();
120
    }
121
122
    public function stopProcess($pid, $grace = 5)
123
    {
124
        // what are we doing?
125
        $log = usingLog()->startAction("stop process '{$pid}' on host '{$this->args[0]}'");
126
127
        // is the process running at all?
128
        if (!fromHost($this->args[0])->getPidIsRunning($pid)) {
129
            $log->endAction("process is not running");
130
            return;
131
        }
132
133
        // yes it is, so stop it
134
        // send a TERM signal to the screen session
135
        $log->addStep("send SIGTERM to process '{$pid}'", function() use ($pid) {
136 View Code Duplication
            if ($this->getIsLocalhost()) {
137
                posix_kill($pid, SIGTERM);
138
            }
139
            else {
140
                usingHost($this->args[0])->runCommand("kill {$pid}");
0 ignored issues
show
Deprecated Code introduced by
The method Storyplayer\SPv2\Modules...UsingHost::runCommand() has been deprecated with message: since v2.4.0

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.

Loading history...
141
            }
142
        });
143
144
        // has this worked?
145
        $isStopped = $log->addStep("wait for process to terminate", function() use($pid, $grace, $log) {
146
            for($i = 0; $i < $grace; $i++) {
147
                if (!fromHost($this->args[0])->getPidIsRunning($pid)) {
148
                    return true;
149
                }
150
151
                // process still exists
152
                sleep(1);
153
            }
154
155
            return false;
156
        });
157
158
        // did the process stop?
159
        if ($isStopped) {
160
            $log->endAction();
161
            return;
162
        }
163
164
        $log->addStep("send SIGKILL to process '{$pid}'", function() use($pid) {
165 View Code Duplication
            if ($this->getIsLocalhost()) {
166
                posix_kill($pid, SIGKILL);
167
            }
168
            else {
169
                usingHost($this->args[0])->runCommand("kill -9 {$pid}");
0 ignored issues
show
Deprecated Code introduced by
The method Storyplayer\SPv2\Modules...UsingHost::runCommand() has been deprecated with message: since v2.4.0

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.

Loading history...
170
            }
171
            sleep(1);
172
        });
173
174
        // success?
175
        if (fromHost($this->args[0])->getProcessIsRunning($pid)) {
176
            $log->endAction("process is still running :(");
177
            throw Exceptions::newActionFailedException(__METHOD__);
178
        }
179
180
        // all done
181
        $log->endAction("process has finished");
182
    }
183
184
    /**
185
     * @deprecated since v2.4.0
186
     */
187
    public function uploadFile($sourceFilename, $destFilename)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
188
    {
189
        return Filesystem::onHost($this->args[0])->uploadFile($sourceFilename, $destFilename);
190
    }
191
}
192