1

I have a simple systemd service that runs for some time and then exits. It usually gets triggered by a systemd timer but sometimes I want to run it manually (well, from a script). The problem is - I need that script to output to terminal whatever my service outputs and do couple other things when the service exits.

I'd really like to be able to do systemctl start foo.service instead of moving my ExecStart= to a bash script and just running it for a couple of reasons:

  1. I want the behavior to be exactly the same. My experience tells me that things running from shell and from shell-from-systemd sometimes behave differently.
  2. I don't know how to limit resources used by script like with systemd unit's Limit*= directives.
  3. I need there to be only one instance of the service at most, which starting via systemctl ensures, but starting via script doesn't (unless I complicate it with pidfile handling).

Basically, what I want is:

tail --pid $MY_PID -f my.log

but done with journalctl.

Using:

journalctl -u my.service -o cat --no-pager -f

after starting the service works almost like I want it to, but it doesn't exit after my service exits.

If possible, I'd like not to use StandardOutput= and StandardError= to redirect my logs to a file and running tail command from above on it, because I'd like journalctl to store and manage my logs.

I know about StandardOutput=tty option and judging from documentation it should do what I want, but I'm not sure how it'll work when the service is being ran by the timer.

What options do I have?

Discussian
  • 11
  • 1

0 Answers0