0

I have two Java services where the second one depends on the first being fully started before it can start.

In order to check that the first service is fully started I need to grep for a specific message in the logs (and also ignore previous start messages).

Can I add this search somewhere in the systemd files?

  • Couldn't one just sleep for a specific period of time which lets the first service have plenty of time to start? – john doe Aug 2 '19 at 13:59
  • You could but I'd rather have a robust solution. – opticyclic Aug 2 '19 at 14:09
0

You could add a "pre start" action in the unit file for doing your grep / sleep. It's not pretty but something like that!

ExecStartPre=/bin/bash -c "i=1; while [ $i -ne 0 ]; do grep pattern file; i=$?; sleep 5; done"
|improve this answer|||||
  • And drop everything you grepped before, to avoid acting on previous starts: sed -n "${sometimestamp},$ p" | grep pattern logfile (and fill $sometimestamp after 'do', of course) – markgraf Aug 2 '19 at 14:45
  • yep, not bad, or with a tail on the last lines – sébastien dagnicourt Aug 4 '19 at 10:52

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.