2

I have an application I'd like to compile once on boot and if it succeeds, run it. I have two services: compile-app and run-app. When I set it up using Requires it works but whenever I do systemctl restart run-app it also re-runs compile-app, which I don't want.

How can I restructure my services to not run compile-app when I manually restart run-app?

# compile-app.service

[Unit]
Description=compile app
After=network-online.target syslog.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=some command
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

and

# run-app.service

[Unit]
Description=run app
After=network-online.target syslog.target
Wants=network-online.target
Requires=compile-app.service

[Service]
Type=simple
ExecStart=some command

[Install]
WantedBy=multi-user.target

EOF

Is what I have now.

1

RemainAfterExit=true should already do the trick. Are you sure that compile-app.service really gets stopped/restarted when you stop/restart the other unit?

You should also add compile-app.service to the After of run-app.service. The way it is right now, there's no ordering relation between the two services, so they will be started in parallel. Remember that Wants/Requires/Conflicts doesn't imply any ordering and similarly, Before/After doesn't imply any dependency.

|improve this answer|||||
  • A good way to troubleshoot this is looking at systemctl status compile-app.service, if it's not in status started then it will be started again when run-app restarts. But I definitely agree that RemainAfterExit=true should get the correct behavior. – filbranden Mar 7 '19 at 9:12

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.