Fails to create a systemctl service

I’m trying to create a very simple service to launch a script:
[Unit]
Description="Mute on idle"

[Service]
Type=simple
Restar=always
RestartSec=0.5
User=jhonatan
ExecStart=/home/jhonatan/Documentos/mute-call

[Install]
WantedBy=multi-user.target 

systemctl daemon-reload
systemctl start mute-on-idle
systemctl status mute-on-idle
but when I check the status I get a strange output.

● mute-on-idle.service - "Mute on idle"
     Loaded: loaded (/etc/systemd/system/mute-on-idle.service; disabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Tue 2021-02-16 15:46:53 CET; 30s ago
    Process: 165134 ExecStart=/home/jhonatan/Documentos/mute-call (code=exited, status=203/EXEC)
   Main PID: 165134 (code=exited, status=203/EXEC)

feb 16 15:46:53 corporacion-latitudee5540 systemd[1]: Started "Mute on idle".
feb 16 15:46:53 corporacion-latitudee5540 systemd[165134]: mute-on-idle.service: Failed to locate executable /home/jhonatan/Documentos>
feb 16 15:46:53 corporacion-latitudee5540 systemd[165134]: mute-on-idle.service: Failed at step EXEC spawning /home/jhonatan/Documento>
feb 16 15:46:53 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Main process exited, code=exited, status=203/EXEC
feb 16 15:46:53 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Failed with result 'exit-code'.

what am I doing wrong?

I have absolutely no idea if this is the reason or not, but you seem to have a spelling mistake here:

It says Restar=always while I’m pretty sure it should be Restart=always.

(Note the t at the end is Restar there.)

Hope this helps.

You’re right, I’m ashamed, but the result still hasn’t changed.

Hi ashamed! I thought you were @JohnCa. Didn’t know, sorry.

Like I said, I don’t know if it’s the cause of it. And since it isn’t, well, sorry to tell you I don’t know either.

well at least I am not alone in waiting for help XD

Sadly, I’m about to retire for the day. (My day is winding down over here.)
So it seems you will be.

It is cut of but it basically means the file is not there, it is not a program or it can’t be executed.

is the script executable?

ls -l /home/jhonatan/Documentos/mute-call

ls -l /home/jhonatan/Documents/mute-call
ls: '/ home/jhonatan/Documents/mute-call' cannot be accessed: File or directory does not exist

what I have inside the script is this:
#!/bin/bash
watch -n0,5 /home/jhonatan/Documentos/mute-on-idle-jcc2 command &
I don’t know if I have to rename the script or change something inside

Well, it is not there. You need to use the correct path and name. There is no file that is called /home/jhonatan/Documents/mute-call

Okay, I had a slightly crooked route.
the correct path is:
ls -l /home/jhonatan/Documentos/call-mute
-rwxr-xr-x 1 jhonatan jhonatan 77 feb 16 15:29 /home/jhonatan/Documentos/call-mute

and the output of satus is:
● mute-on-idle.service - Mute idle
Loaded: loaded (/etc/systemd/system/mute-on-idle.service; disabled; vendor preset: disabled)
Active: failed (Result: start-limit-hit) since Tue 2021-02-16 16:48:23 CET; 7min ago
Process: 314880 ExecStart=/home/jhonatan/Documentos/call-mute (code=exited, status=0/SUCCESS)
Main PID: 314880 (code=exited, status=0/SUCCESS)

feb 16 16:48:23 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Scheduled restart job, restart counter is at 5.
feb 16 16:48:23 corporacion-latitudee5540 systemd[1]: Stopped Mute idle.
feb 16 16:48:23 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Start request repeated too quickly.
feb 16 16:48:23 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Failed with result 'start-limit-hit'.
feb 16 16:48:23 corporacion-latitudee5540 systemd[1]: Failed to start Mute idle.

It does not show the error because it failed to often (because of the restart).

However, you can’t put a process in the background. It will get killed and the service will fail.

I have removed the background execution and get this:
● mute-on-idle.service - Mute idle
Loaded: loaded (/etc/systemd/system/mute-on-idle.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2021-02-16 17:02:18 CET; 4s ago
Process: 316040 ExecStart=/home/jhonatan/Documentos/call-mute (code=exited, status=1/FAILURE)
Main PID: 316040 (code=exited, status=1/FAILURE)

feb 16 17:02:18 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Scheduled restart job, restart counter is at 5.
feb 16 17:02:18 corporacion-latitudee5540 systemd[1]: Stopped Mute idle.
feb 16 17:02:18 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Start request repeated too quickly.
feb 16 17:02:18 corporacion-latitudee5540 systemd[1]: mute-on-idle.service: Failed with result 'exit-code'.
feb 16 17:02:18 corporacion-latitudee5540 systemd[1]: Failed to start Mute idle.
~

It failed. Unfortunately you did still used the restart option. You need to check the journal to see why it failed.

why not use a systemd timer and call only /home/jhonatan/Documentos/mute-on-idle-jcc2 command ???
ps: test before alone script mute-on-idle-jcc2 - mute-on-idle-jcc2 command ? parameter is “command” ???

Every half second isn’t very practicable for a timer.

But I think OP need to rethink the approach. It looks like watch can’t be used in a systemd service. It requires a terminal. (A workaround might be using screen or temux)

Okay, I’m going to tell you the whole story.

there is a persistent “shhhhhh” in my headphones, I already checked with:
watch pacmd list-sinks
and pulseaudio works fine.
Here is the link to my publication in the sound section:

So I created my own script to automate the silence, I have no programming idea, I never wrote a script or something like that, after two days of research, trial and error I have this:

I’m going to call the main engine script:
#!/bin/bash
state=$(pacmd list-sinks | grep RUNNING | grep -o RUNNING)

if [[ $state == *"RUNNING"* ]];then
  pactl set-sink-mute 0 0
else
  pactl set-sink-mute 0 1
fi

I call the second script the power button:
#!/bin/bash
watch -n0,5 /home/jhonatan/Documentos/mute-on-idle-jcc2

and finally the service:
[Unit]
Description=Mute on idle

[Service]
Type=simple
User=jhonatan
ExecStart=/home/jhonatan/Documentos/call-mute

[Install]
WantedBy=multi-user.target

I would like the service to update the engine command every 0.5 seconds or 1 second if it has errors, but I don’t know how to do it.

It seemed like a reasonable time as I was using it, 1 second seemed slow, I already tried it.

So basically, you want a script that starts a script every half a second.

Could be done in one script, but doesn’t matter. Do not use watch , use a infinite loop. It can be a while or even a for loop. At a sleep command to pause for a specific time.


for example

#!/bin/bash

while [ true ]
do
    /home/jhonatan/Documentos/mute-on-idle-jcc2
    sleep 0.5
done

Of course you could put the content of /home/jhonatan/Documentos/mute-on-idle-jcc2 into the while loop. Then start it with the systemd service.

I quite like the result, I just want to solve a problem.
How do I hide the window of the terminal started by the script?
if we close it manually the process is dead.
So is there a way to hide the window and keep the process alive?

Did you used the loop?

You can’t really hide it, but with the loop the systemd service should work.

Yes, I used it, and it goes very well, your script gave a better direction to my construction.
well, I think we could close the issue, service is working and the scripts work as expected.
I am going to mark the answer that made the service work as a solution.
Thank you very much for your time to:
@xabbu @papajoke @Mirdarthos