3

Is there a way to start a service using systemd and direct it's logging to /dev/null WITHOUT including the proper lines in the unit file.

For example, A file that has the StandardOutput and StandardErorr directives set to null will send logs to /dev/null.

[Unit]
Description=MyService
[Service]

ExecStart=/usr/bin/start_myservice.sh 
Restart=always
StandardOutput=null
StandardError=inherit

[X-Fleet]
Global=true

This service can be started with

systemctl start MyService.service

My question is whether there is a way to start a service that does NOT have the StandardOutput and StandardError directives set, and force it's log to go to /dev/null. Maybe with a command like

systemctl start OtherService.service --disable-logging
Brian Sizemore
  • 132
  • 1
  • 6

1 Answers1

8

You can override anything in a unit with drop-ins, files that systemd automatically reads from an include directory if it exists.

For instance, if you create a directory /etc/systemd/system/myservice.service.d and then a file within that directory, directives in that file will override whatever is in the system shipped unit.

For example, /etc/systemd/system/myservice.service.d/logging.conf:

[Service]
StandardOutput=null

(But note that if you create the directory and leave it empty, the service will be masked and unable to start!)

The use of a drop-in will also be shown whenever you request the service status. For example:

# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/libvirtd.service.d
           └─zfs.conf
   Active: active (running) since Mon 2016-04-04 21:40:09 EDT; 3 days ago

Remember to systemctl daemon-reload after creating or editing a drop-in.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972