use of aQute.jpm.lib.Service in project bnd by bndtools.
the class Main method _trace.
/**
* Trace a service.
*
* @param options
* @throws Exception
*/
@Description("Trace a service")
public void _trace(traceOptions options) throws Exception {
List<String> args = options._arguments();
String s = args.remove(0);
boolean on = args.isEmpty() || !"off".equalsIgnoreCase(args.remove(0));
Service service = jpm.getService(s);
if (service == null)
error("Non existent service %s", s);
else {
try {
if (!service.isRunning())
error("First start the service to trace it");
else {
String result = service.trace(on);
if (result != null)
error("Failed to trace: %s", result);
}
} catch (Exception e) {
exception(e, "Could not trace service %s due to %s", s, e);
}
}
}
use of aQute.jpm.lib.Service in project bnd by bndtools.
the class Main method _start.
/**
* Start a service.
*
* @param options
* @throws Exception
*/
@Description("Start a service")
public void _start(startOptions options) throws Exception {
if (!jpm.hasAccess()) {
error("No write acces, might require administrator or root privileges (sudo in *nix)");
return;
}
for (String s : options._arguments()) {
Service service = jpm.getService(s);
if (service == null)
error("Non existent service %s", s);
else {
if (!service.isRunning()) {
try {
ServiceData d = service.getServiceData();
logger.debug("starting {} as user {}, lock={}, log={}", d.name, d.user, d.lock, d.log);
if (options.clean())
service.clear();
String result = service.start();
if (result != null)
error("Failed to start: %s", result);
} catch (Exception e) {
exception(e, "Could not start service %s due to %s", s, e);
}
} else
warning("Service %s already running", s);
}
}
}
use of aQute.jpm.lib.Service in project bnd by bndtools.
the class Main method _remove.
@Description("Remove a command or a service from the system")
public void _remove(UninstallOptions opts) throws Exception {
if (!jpm.hasAccess()) {
error("No write acces, might require administrator or root privileges (sudo in *nix)");
return;
}
ArrayList<String> toDelete = new ArrayList<String>();
ArrayList<String> names = new ArrayList<String>();
List<CommandData> commands = jpm.getCommands();
for (CommandData command : commands) {
names.add(command.name);
}
List<ServiceData> services = jpm.getServices();
for (ServiceData service : services) {
names.add(service.name);
}
for (String pattern : opts._arguments()) {
Glob glob = new Glob(pattern);
for (String name : names) {
if (glob.matcher(name).matches()) {
toDelete.add(name);
}
}
}
int ccount = 0, scount = 0;
for (String name : toDelete) {
Service s = null;
if (jpm.getCommand(name) != null) {
// Try command first
logger.debug("Corresponding command found, removing");
jpm.deleteCommand(name);
ccount++;
} else if ((s = jpm.getService(name)) != null) {
// No command
// matching, try
// service
logger.debug("Corresponding service found, removing");
s.remove();
scount++;
} else {
// No match amongst commands & services
error("No matching command or service found for: %s", name);
}
}
out.format("%d command(s) removed and %d service(s) removed%n", ccount, scount);
}
Aggregations