17

I have the following below code of systemd.

[Unit]
Description=start RCC logger server process
Requires=rcc-drbd.service rcc_check_locked_scr.service s96rcc.service
After=rcc-drbd.service rcc_check_locked_scr.service s96rcc.service

[Service]
ExecStart= exec /var/RCC/RCClogger.sh
Restart=no

[Install]
WantedBy=multi-user.target

where i try to run it, i get the below error.

Mar 23 04:45:52 localhost.localdomain systemd[1]: 
[/etc/systemd/system/rcc_logger.service:7] Executable path is not absolute, 
ignoring: exec /v...ogger.sh
Mar 23 04:45:52 localhost.localdomain systemd[1]: rcc_logger.service lacks 
both ExecStart= and ExecStop= setting. Refusing.

I know it is because of no absolute path of exec command, but since exec is not available as binary i cannot use absolute path for it. How to make this ExecStart run?

1
  • 4
    remove exec, it isn't required (script should contain hashbang to invoke shell)
    – sebasth
    Aug 7, 2017 at 13:58

2 Answers 2

18

You can't use exec in a systemd service unit configuration.
exec is a shell built-in and cannot be called directly from the filesystem (it doesn't reside on the filesystem) -- type exec and whereis exec will show you that.
Use the shell they're written in.

For example, if it's a bash script, you can run the script like this:

bash /var/RCC/RCClogger.sh

Now, bash is an executable and does have an absolute path: /bin/bash. Your ExecStart will look like the following:

ExecStart=/bin/bash /var/RCC/RCClogger.sh

Another way is to simply add a shebang to the beginning of the script:

#!/bin/bash
... script code ...

This tells the operating system to run the file with the specified interpreter, /bin/bash in this case.

After that simply make your script executable:

chmod +x /var/RCC/RCClogger.sh

And use it directly as the ExecStart:

ExecStart=/var/RCC/RCClogger.sh
2
  • @KamilMaciorowski you're right about my choice of wording, fixed.
    – Fanatique
    Sep 14, 2018 at 12:31
  • This is a fantastic answer. Its instructional as well as accurate. Solved my issue. Thank you @Fanatique May 10, 2020 at 12:01
-1

The "EXecStart=" needs an absolute path to start the service. Get the full path to your .sh file and append it to ExecStart statement.

Again "manpage" will give you detailed info.

0

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.