redirect systemd service logs to file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I was trying to run flume on Ubuntu 16.04 as systemd service and have following in /etc/systemd/system/flume-ng.service



[Unit]
Description=Apache Flume

[Service]
ExecStart=/usr/bin/nohup /opt/flume/current/bin/flume-ng agent -c /etc/flume-ng/conf -f /etc/flume-ng/conf/flume.conf --name a1 &
ExecStop=/opt/flume/current/bin/flume-ng agent stop

[Install]
WantedBy=multi-user.target


I tried adding following lines



StandardOutput=/var/log/flume-ng/log1.log
StandardError=/var/log/flume-ng/log2.log


which didn't work for me.
I did run systemctl daemon-reload and systemctl restart flume-ng



anyone know how this works ?










share|improve this question

























    up vote
    2
    down vote

    favorite












    I was trying to run flume on Ubuntu 16.04 as systemd service and have following in /etc/systemd/system/flume-ng.service



    [Unit]
    Description=Apache Flume

    [Service]
    ExecStart=/usr/bin/nohup /opt/flume/current/bin/flume-ng agent -c /etc/flume-ng/conf -f /etc/flume-ng/conf/flume.conf --name a1 &
    ExecStop=/opt/flume/current/bin/flume-ng agent stop

    [Install]
    WantedBy=multi-user.target


    I tried adding following lines



    StandardOutput=/var/log/flume-ng/log1.log
    StandardError=/var/log/flume-ng/log2.log


    which didn't work for me.
    I did run systemctl daemon-reload and systemctl restart flume-ng



    anyone know how this works ?










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I was trying to run flume on Ubuntu 16.04 as systemd service and have following in /etc/systemd/system/flume-ng.service



      [Unit]
      Description=Apache Flume

      [Service]
      ExecStart=/usr/bin/nohup /opt/flume/current/bin/flume-ng agent -c /etc/flume-ng/conf -f /etc/flume-ng/conf/flume.conf --name a1 &
      ExecStop=/opt/flume/current/bin/flume-ng agent stop

      [Install]
      WantedBy=multi-user.target


      I tried adding following lines



      StandardOutput=/var/log/flume-ng/log1.log
      StandardError=/var/log/flume-ng/log2.log


      which didn't work for me.
      I did run systemctl daemon-reload and systemctl restart flume-ng



      anyone know how this works ?










      share|improve this question













      I was trying to run flume on Ubuntu 16.04 as systemd service and have following in /etc/systemd/system/flume-ng.service



      [Unit]
      Description=Apache Flume

      [Service]
      ExecStart=/usr/bin/nohup /opt/flume/current/bin/flume-ng agent -c /etc/flume-ng/conf -f /etc/flume-ng/conf/flume.conf --name a1 &
      ExecStop=/opt/flume/current/bin/flume-ng agent stop

      [Install]
      WantedBy=multi-user.target


      I tried adding following lines



      StandardOutput=/var/log/flume-ng/log1.log
      StandardError=/var/log/flume-ng/log2.log


      which didn't work for me.
      I did run systemctl daemon-reload and systemctl restart flume-ng



      anyone know how this works ?







      linux ubuntu






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 '16 at 19:02









      user3579198

      14026




      14026




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote














          ExecStart=/usr/bin/nohup …




          This is wrong. Remove it. This service is not running in an interactive login session. There is no controlling terminal, or session leader, to send a hangup signal to it in the first place.




          ExecStart=… &




          This is wrong. Remove it. This is not shell script. & has no special shell-like meaning, and in any case would be the wrong way to start a service.




          StandardOutput=/var/log/flume-ng/log1.log
          StandardError=/var/log/flume-ng/log2.log



          These are wrong. Do not use these. systemd already sends the standard output and error of the service process(es) to its journal, without any such settings in the service unit. You can view it with


          journalctl -e -u flume-ng.service





          share|improve this answer
















          • 15




            What if I wanted to send logs to a different file - is it possible or not? if possible, what is the correct way of doing this?
            – AnthonyK
            Mar 31 '17 at 2:13

















          up vote
          0
          down vote













          Use:



          StandardOutput=file:/var/log/flume-ng/log1.log
          StandardError=file:/var/log/flume-ng/log2.log


          as documented here: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=



          Note that this way log files contents will be overwritten each time service restarts. StandardOutput/Error systemd directives do not support appending to files.



          If you want to maintain file log between service restarts and just append new logged lines to it, use instead:



          ExecStart=/usr/bin/sh -c 'exec /usr/bin/my_binary [arguments] >>/var/log/flume-ng/log1.log 2>>/var/log/flume-ng/log2.log'


          exec means that shell program will be substituted by my_binary program after setting up redirections without forking. So there will be no difference from running my_binary directly after ExecStart=.





          share




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f321709%2fredirect-systemd-service-logs-to-file%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            5
            down vote














            ExecStart=/usr/bin/nohup …




            This is wrong. Remove it. This service is not running in an interactive login session. There is no controlling terminal, or session leader, to send a hangup signal to it in the first place.




            ExecStart=… &




            This is wrong. Remove it. This is not shell script. & has no special shell-like meaning, and in any case would be the wrong way to start a service.




            StandardOutput=/var/log/flume-ng/log1.log
            StandardError=/var/log/flume-ng/log2.log



            These are wrong. Do not use these. systemd already sends the standard output and error of the service process(es) to its journal, without any such settings in the service unit. You can view it with


            journalctl -e -u flume-ng.service





            share|improve this answer
















            • 15




              What if I wanted to send logs to a different file - is it possible or not? if possible, what is the correct way of doing this?
              – AnthonyK
              Mar 31 '17 at 2:13














            up vote
            5
            down vote














            ExecStart=/usr/bin/nohup …




            This is wrong. Remove it. This service is not running in an interactive login session. There is no controlling terminal, or session leader, to send a hangup signal to it in the first place.




            ExecStart=… &




            This is wrong. Remove it. This is not shell script. & has no special shell-like meaning, and in any case would be the wrong way to start a service.




            StandardOutput=/var/log/flume-ng/log1.log
            StandardError=/var/log/flume-ng/log2.log



            These are wrong. Do not use these. systemd already sends the standard output and error of the service process(es) to its journal, without any such settings in the service unit. You can view it with


            journalctl -e -u flume-ng.service





            share|improve this answer
















            • 15




              What if I wanted to send logs to a different file - is it possible or not? if possible, what is the correct way of doing this?
              – AnthonyK
              Mar 31 '17 at 2:13












            up vote
            5
            down vote










            up vote
            5
            down vote










            ExecStart=/usr/bin/nohup …




            This is wrong. Remove it. This service is not running in an interactive login session. There is no controlling terminal, or session leader, to send a hangup signal to it in the first place.




            ExecStart=… &




            This is wrong. Remove it. This is not shell script. & has no special shell-like meaning, and in any case would be the wrong way to start a service.




            StandardOutput=/var/log/flume-ng/log1.log
            StandardError=/var/log/flume-ng/log2.log



            These are wrong. Do not use these. systemd already sends the standard output and error of the service process(es) to its journal, without any such settings in the service unit. You can view it with


            journalctl -e -u flume-ng.service





            share|improve this answer













            ExecStart=/usr/bin/nohup …




            This is wrong. Remove it. This service is not running in an interactive login session. There is no controlling terminal, or session leader, to send a hangup signal to it in the first place.




            ExecStart=… &




            This is wrong. Remove it. This is not shell script. & has no special shell-like meaning, and in any case would be the wrong way to start a service.




            StandardOutput=/var/log/flume-ng/log1.log
            StandardError=/var/log/flume-ng/log2.log



            These are wrong. Do not use these. systemd already sends the standard output and error of the service process(es) to its journal, without any such settings in the service unit. You can view it with


            journalctl -e -u flume-ng.service






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 7 '16 at 19:44









            JdeBP

            30.9k465141




            30.9k465141







            • 15




              What if I wanted to send logs to a different file - is it possible or not? if possible, what is the correct way of doing this?
              – AnthonyK
              Mar 31 '17 at 2:13












            • 15




              What if I wanted to send logs to a different file - is it possible or not? if possible, what is the correct way of doing this?
              – AnthonyK
              Mar 31 '17 at 2:13







            15




            15




            What if I wanted to send logs to a different file - is it possible or not? if possible, what is the correct way of doing this?
            – AnthonyK
            Mar 31 '17 at 2:13




            What if I wanted to send logs to a different file - is it possible or not? if possible, what is the correct way of doing this?
            – AnthonyK
            Mar 31 '17 at 2:13












            up vote
            0
            down vote













            Use:



            StandardOutput=file:/var/log/flume-ng/log1.log
            StandardError=file:/var/log/flume-ng/log2.log


            as documented here: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=



            Note that this way log files contents will be overwritten each time service restarts. StandardOutput/Error systemd directives do not support appending to files.



            If you want to maintain file log between service restarts and just append new logged lines to it, use instead:



            ExecStart=/usr/bin/sh -c 'exec /usr/bin/my_binary [arguments] >>/var/log/flume-ng/log1.log 2>>/var/log/flume-ng/log2.log'


            exec means that shell program will be substituted by my_binary program after setting up redirections without forking. So there will be no difference from running my_binary directly after ExecStart=.





            share
























              up vote
              0
              down vote













              Use:



              StandardOutput=file:/var/log/flume-ng/log1.log
              StandardError=file:/var/log/flume-ng/log2.log


              as documented here: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=



              Note that this way log files contents will be overwritten each time service restarts. StandardOutput/Error systemd directives do not support appending to files.



              If you want to maintain file log between service restarts and just append new logged lines to it, use instead:



              ExecStart=/usr/bin/sh -c 'exec /usr/bin/my_binary [arguments] >>/var/log/flume-ng/log1.log 2>>/var/log/flume-ng/log2.log'


              exec means that shell program will be substituted by my_binary program after setting up redirections without forking. So there will be no difference from running my_binary directly after ExecStart=.





              share






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Use:



                StandardOutput=file:/var/log/flume-ng/log1.log
                StandardError=file:/var/log/flume-ng/log2.log


                as documented here: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=



                Note that this way log files contents will be overwritten each time service restarts. StandardOutput/Error systemd directives do not support appending to files.



                If you want to maintain file log between service restarts and just append new logged lines to it, use instead:



                ExecStart=/usr/bin/sh -c 'exec /usr/bin/my_binary [arguments] >>/var/log/flume-ng/log1.log 2>>/var/log/flume-ng/log2.log'


                exec means that shell program will be substituted by my_binary program after setting up redirections without forking. So there will be no difference from running my_binary directly after ExecStart=.





                share












                Use:



                StandardOutput=file:/var/log/flume-ng/log1.log
                StandardError=file:/var/log/flume-ng/log2.log


                as documented here: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=



                Note that this way log files contents will be overwritten each time service restarts. StandardOutput/Error systemd directives do not support appending to files.



                If you want to maintain file log between service restarts and just append new logged lines to it, use instead:



                ExecStart=/usr/bin/sh -c 'exec /usr/bin/my_binary [arguments] >>/var/log/flume-ng/log1.log 2>>/var/log/flume-ng/log2.log'


                exec means that shell program will be substituted by my_binary program after setting up redirections without forking. So there will be no difference from running my_binary directly after ExecStart=.






                share











                share


                share










                answered 8 mins ago









                Piotr Jurkiewicz

                685512




                685512



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f321709%2fredirect-systemd-service-logs-to-file%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay