Linux

How To Redirect Output Of Systemd Service To A File (Ubuntu).


Lets start from the service file which is located at the following directory: /etc/systemd/system/ (You can use the "cd" command - cd /etc/systemd/system/).

The second step is to edit our service file, for that open the file for editing using "vim" editor. Use the following command sudo vim your_service.service.

Add the following lines under the [Service] at your service file.

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=[our service identifier] -> Just as it is(No brackets, no quotes)

In order to close the vim editor press ":" then write wq.

Now we have to create config file for the rsyslog so it would know to process our service's logs.

Access /etc/rsyslog.d/ directoy and create there a new config file name it at the same name you named you service: our_service.conf

Then place the following content at the file:

if $programname == '[our service identifier]' then /var/log/our_service.log & stop

Now give syslog the ability to write into our file:

chown syslog:adm /var/log/our_service.log 

And the final step is to restart the rsyslog service:

sudo systemctl restart rsyslog

14 thoughts on “How To Redirect Output Of Systemd Service To A File (Ubuntu).

  1. It is really a nice and helpful piece of information. I’m glad that you shared this helpful info with us. Please keep us informed like this. Thank you for sharing.

  2. Hello There. I found your blog using msn. This is an extremely
    well written article. I will make sure to bookmark it and
    return to read more of your useful information. Thanks for the post.
    I will definitely comeback.

    Keep up the good work!

  3. Hi! I just want to give you a huge thumbs up for your excellent info you’ve got right here on this post. I will be returning to your site for more soon.

  4. Heya! I realize this is somewhat off-topic but I needed to ask.
    Does building a well-established blog like yours require a large
    amount of work? I’m completely new to operating a blog but I do write in my journal everyday.

    I’d like to start a blog so I will be able to share my own experience and views online.
    Please let me know if you have any suggestions or tips for brand new aspiring blog owners.

    Appreciate it!

  5. I am in fact pleased to read this website posts which includes tons of valuable information, thanks for providing such information.

  6. Hi there, all is going fine here and ofcourse every one is sharing facts,
    that’s really excellent, keep up writing.

  7. Excellent web site you’ve got here.. It’s difficult to find high-quality writing like yours these days. I really appreciate individuals like you! Take care!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top