Skip to content

Commit 51a8066

Browse files
committed
Added ShellScript-task to run Linux shell scripts.
1 parent 0eaa890 commit 51a8066

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

tasks-dsl/src/main/scala/net/codejitsu/tasks/GenericTask.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class GenericTask(name: String, desc: String, hosts: Hosts, exec: Strin
1313
protected val procs: Processes = name on hosts ~> {
1414
case cmd => if (usingSudo) {
1515
Sudo ~ Exec(exec, params :_*)
16-
} else{
16+
} else {
1717
Exec(exec, params :_*)
1818
}
1919
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2015, codejitsu.
2+
3+
package net.codejitsu.tasks
4+
5+
import net.codejitsu.tasks.dsl._
6+
7+
/**
8+
* Run shell scripts.
9+
*/
10+
final case class ShellScript[S <: Stage](hosts: Hosts, script: String, params: List[String] = List.empty[String],
11+
usingSudo: Boolean = false, usingPar: Boolean = false,
12+
shell: String = "/bin/sh")(implicit user: User, stage: S, rights: S Allow StartService[S])
13+
extends GenericTask("script", "run shell script", hosts, s"$shell $script", params,
14+
usingSudo, usingPar, taskRepr = s"run shell script '$script'") with UsingSudo[ShellScript[S]] with UsingParallelExecution[ShellScript[S]] {
15+
16+
override def sudo: ShellScript[S] = copy[S](usingSudo = true)
17+
override def par: ShellScript[S] = copy[S](usingPar = true)
18+
}

tasks-dsl/src/main/scala/net/codejitsu/tasks/dsl/Allow.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ object Allow {
2828
implicit val devAllowStopService: Dev Allow StopService[Dev] = new Allow[Dev, StopService[Dev]]
2929
implicit val devAllowStartTomcat: Dev Allow StartTomcat[Dev] = new Allow[Dev, StartTomcat[Dev]]
3030
implicit val devAllowStopTomcat: Dev Allow StopTomcat[Dev] = new Allow[Dev, StopTomcat[Dev]]
31+
implicit val devAllowShellScripts: Dev Allow ShellScript[Dev] = new Allow[Dev, ShellScript[Dev]]
3132
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.codejitsu.tasks.dsl
2+
3+
import org.scalatest.{FlatSpec, Matchers}
4+
5+
class ShellScriptTest extends FlatSpec with Matchers {
6+
import net.codejitsu.tasks._
7+
import net.codejitsu.tasks.dsl.Tasks._
8+
9+
import scala.concurrent.duration._
10+
11+
implicit val timeout = 30 seconds
12+
13+
implicit val stage = new Dev
14+
15+
"shell script task" should "run shell scripts" in {
16+
val path = getClass.getResource("/program-param.sh").getPath
17+
18+
val task = ShellScript(Localhost, path, List("test", "1", "-z"))
19+
20+
val result = task.run()
21+
22+
result.res.isSuccess should be (true)
23+
result.out should be (List("start test program with param: test 1 -z"))
24+
result.err should be (empty)
25+
}
26+
}

0 commit comments

Comments
 (0)