You are not logged in.

#1 2017-11-30 20:02:24

amaro
Member
From: 5.11.1-1-ck-ivybridge, xfce
Registered: 2014-05-09
Posts: 363

[SOLVED] service: Failed to execute command: Exec format error

Hey guys!

After reading several threads and trying several things I still cannot get a custom service to start at boot. I need help.

Here is the story.

I want to delay some services at boot in order to decrease the boot time. So I made this (my first!) script

#!/bin/bash

#This script will run 3 sec after boot

 systemctl start dnsmasq.service &&
 systemctl start squid.service &&
 systemctl start squid-rotate.service

I tried putting the script in /usr/bin and in /usr/local/bin. It runs (manually) fine from either.

After that I created a service

[Unit]
Description=bootscript

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/bootscript

I tried adding

Environment=DISPLAY=:0

as well as changing the type to

Type=simple

After that I created a timer

[Unit]
Description=Runs bootscript at boot

[Timer]
# Time to wait after booting before activation
OnBootSec=3sec
Unit=bootscript.service

[Install]
WantedBy=multi-user.target

Then

systemctl enable bootscript.timer

And after a reboot I have no internet connection. I have to manually run the script in order to start the services.

Script is executable

chmod +x /usr/bin/bootscript

Here is the output

ctl status bootscript.service
● bootscript.service - bootscript
   Loaded: loaded (/etc/systemd/system/bootscript.service; static; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2017-11-30 21:33:22 EET; 3s ago
  Process: 1120 ExecStart=/usr/bin/bootscript (code=exited, status=203/EXEC)
 Main PID: 1120 (code=exited, status=203/EXEC)

Nov 30 21:33:22 ahp systemd[1]: Started bootscript.
Nov 30 21:33:22 ahp systemd[1120]: bootscript.service: Failed to execute command: Exec format error
Nov 30 21:33:22 ahp systemd[1120]: bootscript.service: Failed at step EXEC spawning /usr/bin/bootscript: Exec format error
Nov 30 21:33:22 ahp systemd[1]: bootscript.service: Main process exited, code=exited, status=203/EXEC
Nov 30 21:33:22 ahp systemd[1]: bootscript.service: Failed with result 'exit-code'.
ctl status bootscript.timer
● bootscript.timer - Runs bootscript at boot
   Loaded: loaded (/etc/systemd/system/bootscript.timer; enabled; vendor preset: disabled)
   Active: active (elapsed) since Thu 2017-11-30 21:27:11 EET; 27min ago
  Trigger: n/a

Nov 30 21:27:11 ahp systemd[1]: Started Runs bootscript at boot.

How to proceed to make it work?
Thank you in advance!

Last edited by amaro (2017-12-03 12:10:28)

Offline

#2 2017-11-30 20:06:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] service: Failed to execute command: Exec format error

amaro wrote:

I want to delay some services at boot in order to decrease the boot time.

Just stop here.  This is completely the wrong approach.  Delaying them will not decrease boot time.  It may artificially decrease the numbers reported by `systemd-analze` but that does not mean you are getting to a useable system any faster.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-11-30 20:22:08

amaro
Member
From: 5.11.1-1-ck-ivybridge, xfce
Registered: 2014-05-09
Posts: 363

Re: [SOLVED] service: Failed to execute command: Exec format error

You sank my enthusiasm smile. I wanted it to work.
Anyway, 'systemd-analyze' showed improvement of 6 sec. But I am not to argue with you. I believe you are right. After all my knowledge is limited.

Now I have

systemctl list-unit-files --state enabled
UNIT FILE        STATE  
autovt@.service  enabled
dhcpcd.service   enabled
getty@.service   enabled
remote-fs.target enabled
bootscript.timer enabled

'squid' takes about 6 sec to start.

Last edited by amaro (2017-11-30 20:33:10)

Offline

#4 2017-11-30 21:23:30

koffeinfriedhof
Member
Registered: 2017-11-30
Posts: 89

Re: [SOLVED] service: Failed to execute command: Exec format error

Hi!

You should use the Require and WantedBy to change the order on startup. See systemd-unit for details.

As a general recommendation: Always use absolute paths in units, e.g. /usr/bin/systemctl instead of systemctl.

Offline

#5 2017-11-30 22:05:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] service: Failed to execute command: Exec format error

amaro wrote:

Anyway, 'systemd-analyze' showed improvement of 6 sec...
'squid' takes about 6 sec to start.

Well there you have it.  With squid starting at boot, systemd-analyze doesn't report booting as "complete" until squid has started - but you will get to your login or desktop just as fast either way.  Delaying squid will only delay squid, it will not speed up anything else.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2017-11-30 22:35:50

loqs
Member
Registered: 2014-03-06
Posts: 17,192

Re: [SOLVED] service: Failed to execute command: Exec format error

@Trilby squid.service is of type forking with WantedBy=multi-user.target so if amaro was using a display manager then
would the display manager only start after multi-user.target is complete which would would require squid.service to finish start up?

Offline

#7 2017-11-30 23:26:28

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] service: Failed to execute command: Exec format error

Perhaps, but that then would be the problem to be fixed, and starting important services intentionally after a delay is not a solution for that problem.  Change the target they are wanted by, or change the dependency chain for the display manager, or - my favorite - ditch the DM as their primary purposes seem to be to slow down the boot process and break frequently.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2017-12-01 10:22:02

amaro
Member
From: 5.11.1-1-ck-ivybridge, xfce
Registered: 2014-05-09
Posts: 363

Re: [SOLVED] service: Failed to execute command: Exec format error

Trilby wrote:

Delaying squid will only delay squid, it will not speed up anything else.

Absolutely right. But i did not know it.

Here is what I did in the meantime.

Changed 'Type' to 'forking' as loqs whispered to Trilby

loqs wrote:

@Trilby squid.service is of type forking with WantedBy=multi-user.target

After that I made two services - one for 'dnsmasq' and one for 'squid'. Hooked them together in that order with a new 'target' file and started the 'target' file with the 'timer'. Found the solution here https://jason.the-graham.com/2013/03/06 … md-timers/

It seems to work cause after rebooting I have access to internet. The only thing I don't get is why the status of both services shows as 'inactive'

ctl status squid
● squid.service - Web Proxy Cache Server
   Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
   Active: inactive (dead)


ctl status dnsmasq
● dnsmasq.service - A lightweight DHCP and caching DNS server
   Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:dnsmasq(8)

Offline

#9 2017-12-03 12:09:54

amaro
Member
From: 5.11.1-1-ck-ivybridge, xfce
Registered: 2014-05-09
Posts: 363

Re: [SOLVED] service: Failed to execute command: Exec format error

I finally did it. Created 'target' file that 'Requires' 'dhcpcd', 'dnmasq', 'squid' and 'iptables'. Created 'crontab' for squid-rotate. Started the 'target' with 'timer'. Everything works fine. Overall gain - 3 sec.
Thank you Trilby and loqs! Your comments were very helpful!

Offline

Board footer

Powered by FluxBB