I'm trying to create a config file for my unit but when I start the daemon after enabling and shutdown the computer it doesnt works. The script only executes the ExecStart line after network.target on boot. Edit: Code:
[Unit]
Description="Service that executes Discord Bot at Boot and Shutdown."
After=network.target
Before=poweroff.target
[Service]
ExecStart=/usr/bin/mi_script_bash.sh start
ExecStop=/usr/bin/mi_script_bash.sh stop
Type=oneshot
RemainAfterExit=true
[Install]
WantedBy= default.target poweroff.target
The ExecStart and ExecStop Calls are for the bash script mi_script_bash.sh (simple string comparison for calling to a NodeJs script):
#!/bin/bash
[ "$1" == "start" ] && node /home/ser356/Escritorio/discordjs/app.js start
[ "$1" == "stop" ] && node /home/ser356/Escritorio/discordjs/app.js stop
And then the node script:
const {Client,Intents} = require("discord.js");
require('dotenv').config();
var hora=new Date();
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
var argumentos=process.argv[2];
console.log(argumentos)
//client.login("OTUwNTQyNDQ5MzYzODA4MzA2.YiabpA.bulmNmwGgz9s8kOPyvjngR_rSbo");
client.on('ready', () => {
var canal = client.channels.cache.get("950644612517724171")
if(argumentos==='start'){
canal.send("Mi dueño me ha arrancado "+hora);
}
else if(argumentos==='stop'){
canal.send("Mi dueño me requiere "+hora);
}
else{
canal.send("nada")
}
});
client.login('token')