1

I have created the service sendir.service and put it in /etc/systemd/system

This is what the service looks like:

[Unit]
Description=sendir

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/usr/local/bin/sendir

[Install]
WantedBy=multi-user.target     

And this is the script for the service /usr/local/bin/sendir:

#!/bin/bash

irsend SEND_ONCE ph_remote KEY_POWER

When I try to enable the service via sudo systemctl enable sendir.service --now I'm getting this error message

Synchronizing state of sendir.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable sendir
update-rc.d: error: sendir Default-Start contains no runlevels, aborting.

Does anybody know what I'm doing wrong?

1

The system is trying to keep the systemd System and Service Manager insync with the legacy SYSV (UNIX System V and BSD System and Service Manager).

systemd is controlled using systemctl, while SYSV is controlled using the service command.

I believe that this AskUbuntu answer is the fix for your problem. The only thing different about your situation is that your custom script runs at service stop instead of service start.

Try adding the following to your /usr/bin/local/sendir script:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          sendir
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Execute sendir at service termination ...
### END INIT INFO
  • The file already points at the service file: ExecStop=/usr/local/bin/sendir. It should be executed at every shutdown as you can see here. – jake Oct 9 '18 at 1:00
  • @jake Ah, I didn't catch that ... you're saying that /usr/local/bin/sendir is the Bash script he shows. Perhaps then the sendir file just needs to include the BEGIN INIT INFO. I'll edit the question to show the name of the Bash script. – HeatfanJohn Oct 9 '18 at 14:39
  • Maybe he could put his one-liner directly into the service file. Like ExecStop=/bin/bash irsend SEND_ONCE ph_remote KEY_POWER. What do you think? – jake Oct 9 '18 at 14:54
  • I have now tried both methods. I have added the BEGIN INIT INFO to the script and also put the command like @jake mentioned directly in the service. Bot I got the exact same error message again, when I try to enable the service. Can it be that somethings is wrong with the service file itself? – apfelcast Oct 9 '18 at 18:38
  • @apfelcast What version of Raspbian are you using? I'm on Stretch version 9 and the enable worked for me. I need try again this time removing the INIT INFO to see if I can recreate your error. – HeatfanJohn Oct 9 '18 at 18:52
0

I now got the service running by changing the service it self and adding Before=shutdown.target to it.

The sendir.service now looks like this:

[Unit]
Description= sending
Before=shutdown.target

[Service]
ExecStart=/bin/true
ExecStop=/usr/local/bin/sendir
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target 

I could enable the service without any problems now and it also sends the ir signal like is should.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.