Skip to content

Commit 01f1781

Browse files
committed
Adding sudo to service call
1 parent 3a45e5d commit 01f1781

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

.bldr.yml.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ bldr:
3333
calls:
3434
-
3535
type: notify
36-
message: "Sleeping for 2 Second"
36+
message: "Sleeping for 1 Second"
3737
-
3838
type: sleep
39-
seconds: 2
39+
seconds: 1
4040
-
4141
type: notify
42-
message: "Done sleeping for 2 Second"
42+
message: "Done sleeping for 1 Second"
4343
-
4444
type: notify
4545
message: "Stopping and Starting redis service"

src/Extension/Miscellaneous/Call/ServiceCall.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function configure()
3838
)
3939
->addOption('service', true, 'Service to manage')
4040
->addOption('method', true, 'Method to run on the service manager. <restart>', 'restart')
41+
->addOption('sudo', true, 'Run as sudo?', false)
4142
->addOption('dry_run', true, 'If set, will not run command', false);
4243
}
4344

@@ -51,21 +52,32 @@ public function run()
5152
->addOption('arguments', true);
5253

5354
$arguments = [];
54-
$manager = $this->getOption('manager');
55+
$sudo = $this->getOption('sudo');
56+
$manager = $this->getOption('manager');
5557
switch ($manager) {
5658
case 'service':
57-
$executable = 'sudo';
58-
$arguments[] = $manager;
59+
$executable = $manager;
60+
if ($sudo) {
61+
$executable = 'sudo';
62+
$arguments[] = $manager;
63+
}
5964
$arguments[] = $this->getOption('service');
6065
$arguments[] = $this->getOption('method');
6166
break;
6267
case 'init.d':
63-
$executable = 'sudo';
64-
$arguments[] = '/etc/init.d/'.$this->getOption('service');
68+
$executable = '/etc/init.d/'.$this->getOption('service');
69+
if ($sudo) {
70+
$executable = 'sudo';
71+
$arguments[] = $manager;
72+
}
6573
$arguments[] = $this->getOption('method');
6674
break;
6775
case 'launchctl':
68-
$executable = $manager;
76+
$executable = $manager;
77+
if ($sudo) {
78+
$executable = 'sudo';
79+
$arguments[] = $manager;
80+
}
6981
$arguments[] = $this->getOption('method');
7082
$arguments[] = $this->getOption('service');
7183
break;

0 commit comments

Comments
 (0)