Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute multiple commands with && in systemd service ExecStart on RedHat 7.9

Tags:

redhat

systemd

I have this systemd service on Red Hat Enterprise Linux Server 7.9 (Maipo)

[Unit]
Description = EUM Server Service
PartOf=eum.service
# Start this unit after the app.service start
After=eum.service
After=eum-db.service

[Service]
Type=forking
User=root
WorkingDirectory=/prod/appdynamics/EUMServer/eum-processor/
ExecStart=/usr/bin/sleep 45 && /bin/bash bin/eum.sh start
RemainAfterExit=true
ExecStop=/bin/bash bin/eum.sh stop

[Install]
WantedBy=multi-user.target

that fails because it tries to pick everything after /usr/bin/sleep as parameters to that command. I just want to execute the /usr/bin/sleep 45 and on success execute bin/eum.sh start. How can I make it work?

● eum-server.service - EUM Server Service
   Loaded: loaded (/etc/systemd/system/eum-server.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2021-07-02 00:00:53 CEST; 9min ago
  Process: 13860 ExecStart=/usr/bin/sleep 45 && /bin/bash bin/eum.sh start (code=exited, status=1/FAILURE)

Jul 02 00:00:53 lmlift06mnp001 systemd[1]: Starting EUM Server Service...
Jul 02 00:00:53 lmlift06mnp001 sleep[13860]: /usr/bin/sleep: invalid time interval ‘&&’
Jul 02 00:00:53 lmlift06mnp001 sleep[13860]: /usr/bin/sleep: invalid time interval ‘/bin/bash’
Jul 02 00:00:53 lmlift06mnp001 sleep[13860]: /usr/bin/sleep: invalid time interval ‘bin/eum.sh’
Jul 02 00:00:53 lmlift06mnp001 sleep[13860]: /usr/bin/sleep: invalid time interval ‘start’
Jul 02 00:00:53 lmlift06mnp001 sleep[13860]: Try '/usr/bin/sleep --help' for more information.
Jul 02 00:00:53 lmlift06mnp001 systemd[1]: eum-server.service: control process exited, code=exited status=1
Jul 02 00:00:53 lmlift06mnp001 systemd[1]: Failed to start EUM Server Service.
Jul 02 00:00:53 lmlift06mnp001 systemd[1]: Unit eum-server.service entered failed state.
Jul 02 00:00:53 lmlift06mnp001 systemd[1]: eum-server.service failed.
like image 254
Stefano Lazzaro Avatar asked Dec 29 '25 06:12

Stefano Lazzaro


1 Answers

The command line is not given to a shell, so && is not valid. You would need, for example,

ExecStart=/bin/bash -c 'sleep 45 && /bin/bash bin/eum.sh start'

or you could separate the commands into

ExecStartPre=/usr/bin/sleep 45
ExecStart=/bin/bash bin/eum.sh start
like image 159
meuh Avatar answered Dec 30 '25 23:12

meuh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!