-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command to restart ssh connections #491
Comments
Are you referring to the connection you're making in Also, on an unrelated note, while looking at the file you linked to I noticed that you're trying to |
Oh yep this subscribeToGerritStream. How can I create a new connection and close the other one please? |
If the ssh connection is actually being disconnected by the server, a simple reconnect solution might be something like: function subscribeToGerritStream(host, port, username, keypath, listener) {
var conn = ssh2.Client();
logging.info('Connecting to gerrit..');
conn.connect({
// ...
});
conn.on('ready', function() {
// ...
}).on('close', function() {
console.log('Client disconnected');
subscribeToGerritStream(host, port, username, keypath, listener);
});
} If the ssh connection is not disconnected by the server and you need to either re- |
So will doing this work even when it retry's the ssh server might be down, but will keep retrying? |
Yes, the |
Is it also possible for me to issue an irc command like !grrrit-wm-restart, and it will restart ssh? If so how please. |
For that case you'd need to store your ssh connection object so that it's accessible from the irc message handler. Move the variable declaration to the irc message handler's parent scope. For example: var sshConn = null;
function subscribeToGerritStream(host, port, username, keypath, listener) {
sshConn = new ssh2.Client();
logging.info('Connecting to gerrit..');
sshConn.on('ready', function() {
// ...
}).on('error', function(err) {
console.log('Client error: ' + err);
}).on('close', function() {
console.log('Client disconnected');
// Reconnect
subscribeToGerritStream(host, port, username, keypath, listener);
}).connect({
// ...
});
}
// ...
ircClient.addListener('message', function (from, to, text) {
// ...
if (command === '!grrrit-wm-restart') {
if (sshConn) {
ircClient.say(to, "forcing reconnection to gerrit ...");
sshConn.end();
} else {
ircClient.say(to, "waiting for initial connection to gerrit ...");
}
}
}); |
Hi thankyou very much. But restarting it, causes this info: Connected to event stream! TypeError: listener is not a function |
Never mind about the error seems to happen then and again. |
I don't see how that's possible judging by the current code for src/relay.js and the suggested changes. It's passing the exact same values when reconnecting. |
Thankyou very much for helping. Your example worked :). |
@paladox That commit you just pushed is missing the automatic reconnect (calling the subscribe function again from the ssh connection's |
@mscdex thanks, yeh I had a change but that change wasn't supposed to be merged. fixed in https://gerrit.wikimedia.org/r/#/c/319780/3 |
@mscdex hi, I'm wondering do you know how I can create a whitelist based on a cloak (irc) please. Since we want to only allow certain commands to be run only if you have a cloak which should prevent any spammer from trying to steal another user identity. https://github.com/martynsmith/node-irc/ how I am currently doing the whitelist is at https://gerrit.wikimedia.org/r/#/c/319780/ but I want to change this so it checks the cloak. |
That's beyond the scope of this module and I haven't used a node.js irc module in years, so I can't really help you with that. Your best bet would be to ask on the issue tracker of the module you're using. |
@mscdex Hi with this https://gerrit.wikimedia.org/r/#/c/319908/3/src/relay.js it seems that when I do grrrit-wm: force-restart it quits and then rejoins but then I keep getting ssh disconnecting and then it reconnects. Could I have help to prevent it keep trying to do ssh when it is already connected please? it keeps doing info: Connecting to gerrit.. even though it is already connected and it does it multiple times when I do grrrit-wm: force-restart. |
I don't see anything wrong with the current code in the repo, other than a duplicate That log seems a bit suspect though because it should be showing at least disconnection messages if it was reconnecting. You may need to change |
Oh, after 10+ mins it causes the bot to disconnect from ssh and irc, and keeps replaying Client error: Error: Timed out while waiting for handshake |
it seems that ssh keeps reconnecting, only happends when I do grrrit-wm: restart. |
You could try using |
Oh thankyou. |
Nope that didn't work either, but I have found it keeps calling it seems that it keeps restarting it's connection when i run grrrit-wm: force-restart startRelay(); yep it keeps calling it in close }).on('close', function() { may be a bug? Or it's the variable
or it could be sshConn = null not working properly? |
@mscdex how could I fix the problem you said with JSON.parse() please? |
Oh I found the problem, it was setinterval. |
Ah yes, Regarding
|
@mscdex thanks but I am unsure how to do that. |
Hi is there a way I can restart a ssh connection after it is disconnected please.
I am trying to do https://gerrit.wikimedia.org/r/#/c/318976/
It allows us to use an irc command to restart the bot. I managed to create another ssh connection but it just duplicates things so i have two ssh connections. Then if we do the command again it will do it a third and so on. We use this for gerrit which gets stopped when it gets updated so we need to restart the ssh connection. But it would automate things doing it through irc.
Could I have help please?
The text was updated successfully, but these errors were encountered: