-1

Let me preface this my saying I am a Linux noob, so apologies for anything that should be painfully obvious but i'm not getting it.

I have a phone server running on Debian, this phone server is supposed to send out emails when services crash, but this isn't always reliable, sometimes the services crash and we are never notified. So I figured it would be more reliable to have the services trigger an alert in the OS itself to send a notification if they go down, instead of at the software level.

I have a total of three different files, one is a bash script, one is a text file with the email parameters, and the other is the service.

The bash script (called systemd-email.sh) has this in it:

#!/bin/bash sendmail -vt < mail.txt 

The file the script references above (mail.txt) has this in it (some info changed to generic):

To: [email protected] From: [email protected] Subject: A Service Has Failed A service has failed, please login to PBX and confirm all services are working and investigate failure. 

The service has this in it (root is there only for testing, will change to user created for this service if I can get it working):

[Unit] Description=Status email for PBX services to support [Service] Type=oneshot ExecStart=/bin/bash /usr/local/bin/systemd-email.sh User=root Group=systemd-journal 

If I run the bash script directly it works just fine. When I try to start the service it says that it failed because the control process exited with an error code. I am attempting to start the service using "sudo sytemctl start status-email.service".

If I run "sudo systemctl status status-email.service" I get the output shown in the attached screenshot.

Linux Service Start Attempt

Any help is appreciated. Thanks.

6
  • Use the full path to the mail.txt file. The script isn't running in the directory that contains the file. Commented Mar 22, 2021 at 21:48
  • How is this "one-shot" going to detect a problem? How is it being hooked up so that it gets executed on error? Commented Mar 22, 2021 at 21:52
  • 1
    Did you even read the error message? It says it can't find the mail.txt file. So it should be obvious that it's looking in the wrong directory. Commented Mar 22, 2021 at 21:53
  • The bash script is running in the same directory as the mail.txt so I didn't specify the full path, is the full path still required if its in the same directory? Commented Mar 22, 2021 at 21:54
  • Regarding the question about how its going to detect a problem, the idea is to use the onfailure parameter in the services that are running and have it run this service when the service fails. Commented Mar 22, 2021 at 21:56

1 Answer 1

0

in your systemd-email.sh file use pwd to find out what the directory is when you start your script and if it is not correct then enter cd (to your file path) ad then run the script again. Also check your permissions when you run this as a non root user.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.