LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-16-2017, 05:46 PM   #1
King Arthur
LQ Newbie
 
Registered: Oct 2010
Posts: 23

Rep: Reputation: 1
Question restarting service with systenctl (systemd) produces way too much output


I'm running a small server on a BananaPi (ARMV7-A) with Ubuntu 16.04.02 LTS). To automate SSL certfifcate updates with Let's Encrypt certificates I created a script that's started regularly by a cron job. This script is needed because I have to change router configuration for the automatic certificate update to succeed (and I have to change it back afterwards).

I also restart Apache if a certificate renewal takes place. The output (stdout+stderr) of all important commands in this script is written to a temporary file and sent to me by mail.

If I start this script as root from the command line everything works as expected (restarting apache produces no output in the mail I receive). If the same script is started by cron (etc/crontab, user root) the line

systemctl restart apache2 >>${tmp_log_file} 2>&1

produces way too many lines of output on stderr (which is redirect into the specified file) and which I believe come from systemd:

Calling manager for RestartUnit on apache2.service, replace
Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 object=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=RestartUnit cookie=1 reply_cookie=0 error=n/a
Got message type=method_return sender=n/a destination=n/a object=n/a interface=n/a member=n/a cookie=1 reply_cookie=1 error=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 object=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=GetUnit cookie=2 reply_cookie=0 error=n/a
Got message type=method_return sender=n/a destination=n/a object=n/a interface=n/a member=n/a cookie=3 reply_cookie=2 error=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 object=/org/freedesktop/systemd1/unit/apache2_2eservice interface=org.freedesktop.DBus.Properties member=Get cookie=3 reply_cookie=0 error=n/a
[...]
Got message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd1/job/110031 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=15 reply_cookie=0 error=n/a
Got message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=JobRemoved cookie=16 reply_cookie=0 error=n/a
Got result done/Resource temporarily unavailable for job apache2.service


While trying to narrow this down I already tried
  • Determine the environment variables seen when the script is started by cron and creating the same environment when starting the script manually
  • start the script manually whith </dev/zero >/dev/null as I expected this to remove a controlling terminal ("tty" says "not a tty")
  • verify that the script is started as root in both cases
Whatever I tried, when started from the command line the output looks clean and when started by cron I get these strange messages.

This leads me to ask two questions
  1. What further differences (apart from environment and controlling terminal) can a script see between being called from the command line and by cron? I'd really like to understand this an not just somehow get it to work (the I would use grep to remove the offending lines).
  2. Does the last line of output which ends with "Resource temporarily unavailable for job apache2.service" actually show an error? At least apache seems to be restarted as requested.
 
Old 04-21-2017, 03:17 AM   #2
floppy_stuttgart
Senior Member
 
Registered: Nov 2010
Location: EU mainland
Distribution: Debian like
Posts: 1,155
Blog Entries: 5

Rep: Reputation: 107Reputation: 107
redefine the log format/output? I had a look at GOOGLE "systemctl log setup"
Use a conf file? https://www.loggly.com/ultimate-guid...-with-systemd/
(If I understood correctly your question)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Systemd incorrectly keeps killing a service and restarting it rylan76 Linux - Server 3 02-22-2016 12:34 AM
Can't access full journalctl from script via systemd service even though user is in systemd-journal group iwtbf Linux - Newbie 0 02-19-2016 02:44 PM
[SOLVED] Restarting a Network in Systemd Brandon9000 Linux - General 15 10-24-2012 01:24 PM
Boot Delay 30min: systemd-analyze blame systemd-tmpfiles-setup.service BGHolmes Fedora 0 07-27-2011 09:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration