1

It's on Debian 11. The file PwOn.service:

[Unit]

Description=Send a message with a telegram bot 
After=network.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/JubiBotStartup.sh

[Install]

WantedBy=multi-user.target

With the bash script JubiBotStartup.sh being

#!/bin/bash

TOKEN="randomToken"
ID="11111111"
DT=$(date +'+%d-%m-%Y')
HR=$(date +'+%H:%M:%S')
MSG="System powered on $DT , $HR"
URL="https://api.telegram.org/bot$TOKEN/sendMessage"
curl -s -X POST $URL -d chat_id=$ID -d text="$MSG"

I've enabled the service, and so it appears like that when I put the command systemctl status. When I start the service with 'systemctl start PwOn.service' it works correctly.

However, it does not work when the system powers on or restarts, and checking its status shows the following:

PwOn.service - Send a message with a telegram bot 
     Loaded: loaded (/etc/systemd/system/PwOn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2023-03-07 04:22:37 CET; 21min ago
    Process: 474 ExecStart=/usr/bin/JubiBotStartup.sh (code=exited, status=6)
   Main PID: 474 (code=exited, status=6)
        CPU: 129ms

Mar 07 04:22:36 debian systemd[1]: Started Send a message with a telegram bot 
Mar 07 04:22:37 debian systemd[1]: PwON.service: Main process exited, code=exited, status=6/NOTCONFIGURED
Mar 07 04:22:37 debian systemd[1]: PwOn.service: Failed with result 'exit-code'
~
1
  • I'd read this - it may provide some useful insight into your issue Commented Mar 7, 2023 at 4:42

1 Answer 1

1

If you want to ensure a unit runs after the network is online, you need to list network-online.target in both Wants= and After=:

[Unit]
Description=Send a message with a telegram bot 
After=network-online.target
Wants=network-online.target

Currently, your unit is running during network bring-up, and curl fails because it can’t resolve the target host (which is what its exit code 6 indicates).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .