31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { Message } from 'eris';
|
|
import { Client, Command } from '../class';
|
|
|
|
export default class SystemD_Stop extends Command {
|
|
constructor(client: Client) {
|
|
super(client);
|
|
this.name = 'stop';
|
|
this.description = 'Stops a SystemD user service.';
|
|
this.usage = `${this.client.config.prefix}systemd stop <service name>`;
|
|
this.enabled = false;
|
|
}
|
|
|
|
public async run(message: Message, args: string[]) {
|
|
try {
|
|
if (!args[0]) return this.client.commands.get('help').run(message, ['systemd', this.name]);
|
|
const account = await this.client.db.Account.findOne({ userID: message.author.id });
|
|
if (!account) return this.error(message.channel, 'You do not have a Cloud Services account.');
|
|
try {
|
|
await this.client.util.exec(`runuser ${account.username} -c 'DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/\${UID}/bus" systemctl --user stop ${args[0]}'`);
|
|
message.delete();
|
|
return this.success(message.channel, 'Service stopped.');
|
|
} catch (err) {
|
|
if (err.toString().includes('not found')) return this.error(message.channel, 'Service not found.');
|
|
return this.error(message.channel, err.toString());
|
|
}
|
|
} catch (err) {
|
|
return this.client.util.handleError(err, message, this);
|
|
}
|
|
}
|
|
}
|