Systemd issue. Won't start program on boot, but does start manually. status=101

I'm trying to create an IRC bot and run it on an RPi4 - Manjaro ARM.

My error:

$ sudo systemctl status testbot
[sudo] Mot de passe de folaht : 
● testbot.service - Test bot.
     Loaded: loaded (/usr/lib/systemd/system/testbot.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sun 2020-05-24 13:55:51 CEST; 1min 16s ago
    Process: 272 ExecStart=/usr/bin/testbot (code=exited, status=101)
   Main PID: 272 (code=exited, status=101)

mai 24 13:55:51 Klav systemd[1]: testbot.service: Scheduled restart job, restart counter is at 5.
mai 24 13:55:51 Klav systemd[1]: Stopped Test bot..
mai 24 13:55:51 Klav systemd[1]: testbot.service: Start request repeated too quickly.
mai 24 13:55:51 Klav systemd[1]: test.service: Failed with result 'exit-code'.
mai 24 13:55:51 Klav systemd[1]: Failed to start Test bot..

testbot.service

[Unit]
Description=Test bot
Wants=network-online.target
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

main.rs

// main.rs

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

#[tokio::main]
async fn main() -> Result<(), failure::Error> {

let cfg = Config {
      nickname: Some(format!("testbot")),
      server: Some(format!("irc.freenode.net")),
      port: Some(6697),
      channels: Some(vec![format!("#testbots1234")]),
      username: Some(format!("testbot")),
      realname: Some(format!("Test Bot")),          
      use_ssl: Some(true),
      alt_nicks: Some(vec![format!("Test_Bot_")]),
      .. 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(())
}

[edit]

I'm getting the feeling this is more an issue of the package I'm using.
I forgot how to use $ journalctl -u testbot.service.

mai 24 16:07:03 Klav testbot[271]: thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Custom { kind: Other, error: "failed to lookup address information: Temporary failure in name resolution" })', /home/folaht/.cargo/registry/src/github.com-1ecc6299db9ec823/irc-0.13.6/src/client/mod.rs:700:36
mai 24 16:07:03 Klav testbot[271]: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
mai 24 16:07:03 Klav testbot[271]: thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OneShotCanceled(Canceled)', src/main.rs:20:18

[edit #2]

A network configuration seems to be needed as well:

20-wired.network

[Match]
Name=eth0

[Network]
DHCP=yes

Better use network-online.target to wait until network is up, see https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

2 Likes

Also ensure that "simple" is the right type for your software.

1 Like

It should be.

I don't know the other types, but as far as I can tell an IRCbot is not a oneshot.

Here are the types and their descriptions:
https://www.freedesktop.org/software/systemd/man/systemd.service.html#Options

testbot.service

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

And I'm still getting the same issue from time to time, even with the suggested setup.

$ sudo systemctl is-enabled systemd-networkd-wait-online
enabled

Forum kindly sponsored by