2014-11-20 13:21:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
2020-05-28 13:28:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
2014-11-20 13:21:19 +00:00
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; version 2
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
package com.sheepit.client.os;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
2014-11-30 23:42:57 +00:00
|
|
|
import java.io.File;
|
2014-11-20 13:21:19 +00:00
|
|
|
import java.io.IOException;
|
2020-05-28 23:05:52 +10:00
|
|
|
import java.io.InputStream;
|
2014-11-20 13:21:19 +00:00
|
|
|
import java.io.InputStreamReader;
|
2015-01-25 19:07:32 +00:00
|
|
|
import java.util.List;
|
2015-01-16 17:51:50 +01:00
|
|
|
import java.util.Map;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
import com.sheepit.client.Log;
|
|
|
|
|
|
|
|
|
|
public class Mac extends OS {
|
|
|
|
|
private final String NICE_BINARY_PATH = "nice";
|
2020-05-28 23:05:52 +10:00
|
|
|
private final String ID_COMMAND_INVOCATION = "id -u";
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
public Mac() {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 00:23:57 +00:00
|
|
|
@Override public String name() {
|
2014-11-20 13:21:19 +00:00
|
|
|
return "mac";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public String getRenderBinaryPath() {
|
2014-11-30 23:42:57 +00:00
|
|
|
return "Blender" + File.separator + "blender.app" + File.separator + "Contents" + File.separator + "MacOS" + File.separator + "blender";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
2015-01-25 19:07:32 +00:00
|
|
|
List<String> actual_command = command;
|
2020-05-28 23:05:52 +10:00
|
|
|
if (checkNiceAvailability()) {
|
2015-01-25 19:07:32 +00:00
|
|
|
// launch the process in lowest priority
|
2017-01-05 09:58:27 +01:00
|
|
|
if (env != null) {
|
|
|
|
|
actual_command.add(0, env.get("PRIORITY"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
actual_command.add(0, "19");
|
|
|
|
|
}
|
2015-01-25 19:07:32 +00:00
|
|
|
actual_command.add(0, "-n");
|
|
|
|
|
actual_command.add(0, NICE_BINARY_PATH);
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2015-01-18 16:50:28 +01:00
|
|
|
Log.getInstance(null).error("No low priority binary, will not launch renderer in normal priority");
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
ProcessBuilder builder = new ProcessBuilder(actual_command);
|
|
|
|
|
builder.redirectErrorStream(true);
|
2015-01-16 17:51:50 +01:00
|
|
|
if (env != null) {
|
|
|
|
|
builder.environment().putAll(env);
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
return builder.start();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 00:23:57 +00:00
|
|
|
@Override public boolean isSupported() {
|
|
|
|
|
String[] ver = operatingSystem.getVersionInfo().getVersion().split("\\.");
|
|
|
|
|
int majorVer = Integer.parseInt(ver[0]), minorVer = Integer.parseInt(ver[1]);
|
|
|
|
|
return (majorVer == 10 && minorVer >= 13) || majorVer >= 11;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public String getCUDALib() {
|
2014-11-20 13:21:19 +00:00
|
|
|
return "/usr/local/cuda/lib/libcuda.dylib";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:05:52 +10:00
|
|
|
@Override public boolean getSupportHighPriority() {
|
|
|
|
|
try {
|
|
|
|
|
ProcessBuilder builder = new ProcessBuilder();
|
|
|
|
|
builder.command("bash", "-c", ID_COMMAND_INVOCATION);
|
|
|
|
|
builder.redirectErrorStream(true);
|
|
|
|
|
|
|
|
|
|
Process process = builder.start();
|
|
|
|
|
InputStream is = process.getInputStream();
|
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
|
|
|
|
|
|
|
|
String userLevel = null;
|
|
|
|
|
if ((userLevel = reader.readLine()) != null) {
|
|
|
|
|
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
|
|
|
|
|
// to support changing the priority the nice tool must be accessible from the current user
|
|
|
|
|
return (userLevel.equals("0")) & checkNiceAvailability();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
|
|
|
|
System.err.println(String.format("ERROR Mac::getSupportHighPriority Unable to execute id command. IOException %s", e.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override public boolean checkNiceAvailability() {
|
2014-11-20 13:21:19 +00:00
|
|
|
ProcessBuilder builder = new ProcessBuilder();
|
|
|
|
|
builder.command(NICE_BINARY_PATH);
|
|
|
|
|
builder.redirectErrorStream(true);
|
2020-05-28 23:05:52 +10:00
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
Process process = null;
|
2020-05-28 23:05:52 +10:00
|
|
|
boolean hasNiceBinary = false;
|
2014-11-20 13:21:19 +00:00
|
|
|
try {
|
|
|
|
|
process = builder.start();
|
2020-05-28 23:05:52 +10:00
|
|
|
hasNiceBinary = true;
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
2015-01-18 16:50:28 +01:00
|
|
|
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (process != null) {
|
|
|
|
|
process.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-28 23:05:52 +10:00
|
|
|
return hasNiceBinary;
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2020-07-28 00:49:36 +10:00
|
|
|
|
|
|
|
|
@Override public void shutdownComputer(int delayInMinutes) {
|
|
|
|
|
try {
|
2021-09-10 11:49:22 +02:00
|
|
|
// Shutdown the computer waiting delayInMinutes minutes to allow all SheepIt threads to close and exit the app
|
2020-07-28 00:49:36 +10:00
|
|
|
ProcessBuilder builder = new ProcessBuilder("shutdown", "-h", String.valueOf(delayInMinutes));
|
|
|
|
|
Process process = builder.inheritIO().start();
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
|
|
|
|
System.err.println(String.format("Mac::shutdownComputer Unable to execute the 'shutdown -h 1' command. Exception %s", e.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|