aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
527 stars 100 forks source link

I'm unable to start the tutorial as a systemd service at boot. #211

Closed Folaht closed 4 years ago

Folaht commented 4 years ago

Setup: RPi4 - Manjaro ARM

The error I get:

mai 25 12:27:25 Klav TestBot[225]: Error: Io(Custom { kind: Other, error: "failed to lookup address information: Temporary failure in name resolution" })
mai 25 12:27:25 Klav systemd[1]: testbot.service: Control process exited, code=exited, status=1/FAILURE
mai 25 12:27:25 Klav systemd[1]: testbot.service: Failed with result 'exit-code'.
mai 25 12:27:25 Klav systemd[1]: Failed to start Test bot..

My code:

main.rs

// main.rs

extern crate irc;

use irc::client::prelude::*;
use futures::prelude::*;

#[tokio::main]
async fn main() -> Result<(), failure::Error> {
    let config = Config {
      nickname: Some("Testbot".to_owned()),
      server: Some("irc.privchat.net".to_owned()),
      port: Some(6697),
      channels: vec!["#testbots".to_owned()],
      username: Some("testbot".to_owned()),
      realname: Some("Testbot".to_owned()),          
      use_tls: Some(true),
      alt_nicks: vec!["Testbot_".to_owned()],
      .. Default::default()
    };

    let mut client = Client::from_config(config).await?;
    client.identify()?;

    let mut stream = client.stream()?;

    while let Some(message) = stream.next().await.transpose()? {
        print!("{}", message)
    }

    Ok(())
}

And my systemd service.

testbot.service

[Unit]
Description=Test bot
After=network-online.target

[Service]
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin/:/bin" "TZ=CEST"
Type=simple
ExecStart=/usr/bin/testbot
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
User=folaht
SyslogIdentifier=testbot

[Install]
WantedBy=multi-user.target
Folaht commented 4 years ago

Looks like I'm using old code, closing this issue.

[update] Reopening because the new code is causing a very similar error, which I edited above.

aatxe commented 4 years ago

As I understand it, the error you're encountering occurs when name resolution fails. I don't know for certain, but my impression is that you ultimately end up trying to connect before your machine has established an internet connection. You'll want to change the program to re-attempt connection in a loop, most likely.

Folaht commented 4 years ago

Solved by adding:

Wants=network-online.target

Folaht commented 4 years ago

I'm going to link myself to this before I keep reopening this issue:

https://forum.manjaro.org/t/systemd-issue-wont-start-program-on-boot-but-does-start-manually-status-101/144401/7