summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager/tasks/Reboot.java
blob: c7b8d2628bf458d8a3919a8b12eceda0737ae231 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.openslx.taskmanager.tasks;

import org.openslx.taskmanager.api.SystemCommandTask;

public class Reboot extends SystemCommandTask
{
	private final Output status = new Output();

	@Override
	protected String[] initCommandLine()
	{
		this.timeoutSeconds = 5;
		return new String[] {
				"/usr/bin/sudo",
				"-n",
				"-u", "root",
				"/sbin/reboot"
		};
	}

	@Override
	protected boolean processEnded( int exitCode )
	{
		return exitCode == 0;
	}

	@Override
	protected void processStdOut( String line )
	{
		status.addMessage( line );
	}

	@Override
	protected void processStdErr( String line )
	{
		status.addMessage( line );
	}

	@Override
	protected boolean initTask()
	{
		this.setStatusObject( status );
		return true;
	}

	/**
	 * Output - contains additional status data of this task
	 */
	class Output
	{
		private String messages = null;

		private void addMessage( String str )
		{
			if ( messages == null ) {
				messages = str;
			} else {
				messages += "\n" + str;
			}
		}
	}

}