Systemd error : Executable path is not absolute

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?


Solution 1:

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