3

I have created this Unit file in /lib/systemd/system/menu-core-prices-update.service:

[Unit]
Description = core-price-update daemon
After network.target = auditd.service

[Service]
Type = forking
ExecStart = /usr/local/bin/start-menu-core-prices-update.sh
ExecStop =  /usr/local/bin/stop-menu-core-prices-update.sh
ExecReload = /usr/local/bin/reload-stop-menu-core-prices-update.sh

[Install]
WantedBy = multi-user.target

From the command line I can run:

$ /usr/local/bin/start-menu-core-prices-update.sh

and the program starts properly. But if I start the daemon:

$ sudo systemctl start menu-core-prices-update.service

I get this error:

Jul 24 21:10:20 localhost systemd[13655]: menu-core-prices-update.service: Failed at step EXEC spawning /usr/local/bin/start-menu-core-prices-update.sh: Exec format error
-- Subject: Process /usr/local/bin/start-menu-core-prices-update.sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- The process /usr/local/bin/start-menu-core-prices-update.sh could not be executed and failed.
-- 
-- The error number returned by this process is 8.
Jul 24 21:10:20 localhost systemd[1]: menu-core-prices-update.service: Control process exited, code=exited status=203
Jul 24 21:10:20 localhost systemd[1]: Failed to start core-price-update daemon.
-- Subject: Unit menu-core-prices-update.service has failed

The permissions:

-rwxr-xr-x 1 root root 87 Jul 24 20:27 /usr/local/bin/start-menu-core-prices-update.sh
3
  • 1
    Recommended: use /etc/systemd/system instead of /lib/systemd/system for local unit files. See man systemd.unit
    – cherdt
    Jul 24, 2018 at 22:14
  • Does you script have a proper shebang line? Does the daemon have a PID file that systemd can use to keep track of the main process?
    – muru
    Jul 25, 2018 at 1:28
  • My suggestion removed after network.target and type from your systemd config and run it again.Beware some command line can run not well on systemd. I tried to notify-send in shell script and run on systemd. It did not pop up any notification. Run it from terminal was ok.
    – supriady
    Jul 26, 2018 at 14:27

1 Answer 1

4

Issue #1

I found this thread titled: [Solved] Add custom script to systemd which has the same error as your output shows above, mainly this bit:

Failed at step EXEC spawning /usr/local/bin/start-menu-core-prices-update.sh: Exec format error

This error generally means that your script has one or more of these issues:

  • Is not executable
  • Is missing the shebang (#!/bin/bash)

To address these make sure that your script is executable:

$ chmod a+x /usr/local/bin/start-menu-core-prices-update.sh

And be sure to add a shebang, #!/bin/bash to the top.

Issue #2

It looks like you have a typo on this line:

After network.target = auditd.service

This should likely be this:

After=network.target auditd.service

Issue #3

It's unclear to me why you're using the Type = forking. When you use this type you're ExecStart= is required to use a method that calls fork(). You're also suppose to be using the PIDFile= option.

I would expect your Java application would work fine with either simple or oneshot. See this U&L Q&A titled: Forking in a systemd script for more on this.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .