Making systemctl to shutdown process gracefully












3















I made a small systemctl service to manqge HLTV server (it records demos from a game and stores them on disk):



[Unit]
Description=HLTV server
Requires=cs16.service
After=cs16.service

[Service]
Type=simple
User=cs16
Group=cs16
UMask=007

ExecStart=/home/cs16/server/hltv_start.sh

Restart=on-failure

# Configures the time to wait before service is stopped forcefully.
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target


It works great, but if I shutdown/restart system service, it kills the process, which corrupts demo that is currently being written.



To properly save the demo, I need to type "quit" or "stop" in htlv command tool.
Is there a way to make systemctl send one of those commands to the program before closing it?










share|improve this question













migrated from serverfault.com Jan 15 '16 at 0:08


This question came from our site for system and network administrators.



















  • Or alternatively, if a special signal can be sent, that can be configured to be used as the stop signal.

    – saiarcot895
    Jan 15 '16 at 13:32











  • I haven't tried it yet, but I think if I store the process in screen or tmux, I can later send stdin into it.

    – grisevg
    Jan 19 '16 at 10:20











  • I have the same question, did you find a solution to this question?

    – centic
    Jun 15 '18 at 20:25
















3















I made a small systemctl service to manqge HLTV server (it records demos from a game and stores them on disk):



[Unit]
Description=HLTV server
Requires=cs16.service
After=cs16.service

[Service]
Type=simple
User=cs16
Group=cs16
UMask=007

ExecStart=/home/cs16/server/hltv_start.sh

Restart=on-failure

# Configures the time to wait before service is stopped forcefully.
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target


It works great, but if I shutdown/restart system service, it kills the process, which corrupts demo that is currently being written.



To properly save the demo, I need to type "quit" or "stop" in htlv command tool.
Is there a way to make systemctl send one of those commands to the program before closing it?










share|improve this question













migrated from serverfault.com Jan 15 '16 at 0:08


This question came from our site for system and network administrators.



















  • Or alternatively, if a special signal can be sent, that can be configured to be used as the stop signal.

    – saiarcot895
    Jan 15 '16 at 13:32











  • I haven't tried it yet, but I think if I store the process in screen or tmux, I can later send stdin into it.

    – grisevg
    Jan 19 '16 at 10:20











  • I have the same question, did you find a solution to this question?

    – centic
    Jun 15 '18 at 20:25














3












3








3


1






I made a small systemctl service to manqge HLTV server (it records demos from a game and stores them on disk):



[Unit]
Description=HLTV server
Requires=cs16.service
After=cs16.service

[Service]
Type=simple
User=cs16
Group=cs16
UMask=007

ExecStart=/home/cs16/server/hltv_start.sh

Restart=on-failure

# Configures the time to wait before service is stopped forcefully.
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target


It works great, but if I shutdown/restart system service, it kills the process, which corrupts demo that is currently being written.



To properly save the demo, I need to type "quit" or "stop" in htlv command tool.
Is there a way to make systemctl send one of those commands to the program before closing it?










share|improve this question














I made a small systemctl service to manqge HLTV server (it records demos from a game and stores them on disk):



[Unit]
Description=HLTV server
Requires=cs16.service
After=cs16.service

[Service]
Type=simple
User=cs16
Group=cs16
UMask=007

ExecStart=/home/cs16/server/hltv_start.sh

Restart=on-failure

# Configures the time to wait before service is stopped forcefully.
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target


It works great, but if I shutdown/restart system service, it kills the process, which corrupts demo that is currently being written.



To properly save the demo, I need to type "quit" or "stop" in htlv command tool.
Is there a way to make systemctl send one of those commands to the program before closing it?







services systemd






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 14 '16 at 22:20









grisevggrisevg

1467




1467




migrated from serverfault.com Jan 15 '16 at 0:08


This question came from our site for system and network administrators.









migrated from serverfault.com Jan 15 '16 at 0:08


This question came from our site for system and network administrators.















  • Or alternatively, if a special signal can be sent, that can be configured to be used as the stop signal.

    – saiarcot895
    Jan 15 '16 at 13:32











  • I haven't tried it yet, but I think if I store the process in screen or tmux, I can later send stdin into it.

    – grisevg
    Jan 19 '16 at 10:20











  • I have the same question, did you find a solution to this question?

    – centic
    Jun 15 '18 at 20:25



















  • Or alternatively, if a special signal can be sent, that can be configured to be used as the stop signal.

    – saiarcot895
    Jan 15 '16 at 13:32











  • I haven't tried it yet, but I think if I store the process in screen or tmux, I can later send stdin into it.

    – grisevg
    Jan 19 '16 at 10:20











  • I have the same question, did you find a solution to this question?

    – centic
    Jun 15 '18 at 20:25

















Or alternatively, if a special signal can be sent, that can be configured to be used as the stop signal.

– saiarcot895
Jan 15 '16 at 13:32





Or alternatively, if a special signal can be sent, that can be configured to be used as the stop signal.

– saiarcot895
Jan 15 '16 at 13:32













I haven't tried it yet, but I think if I store the process in screen or tmux, I can later send stdin into it.

– grisevg
Jan 19 '16 at 10:20





I haven't tried it yet, but I think if I store the process in screen or tmux, I can later send stdin into it.

– grisevg
Jan 19 '16 at 10:20













I have the same question, did you find a solution to this question?

– centic
Jun 15 '18 at 20:25





I have the same question, did you find a solution to this question?

– centic
Jun 15 '18 at 20:25










1 Answer
1






active

oldest

votes


















0














It shouldn't be a service



Something that can't be terminated without causing catastrophic damage to its operation shouldn't be run as a "service", but as a per-job script or process.



What you're attempting would compare to waiting for the Internet to stop requesting from your website before allowing systemctl stop apache2 to complete itself.



For a local machine, if you need to shut down the machine, you won't be able to continue writing the file anyway. If you decided to do that, then you want systemctl to end the service without waiting.



Maybe, your service should run another script that waits to terminate.



The solution will be in your Product Roadmap, viz letting the developers tell the Product Manager what user experience isn't possible and what the user should experience instead.





I'm answering this with the following suggestions, not knowing the contents of your script hltv_start.sh because you didn't share it. So, it must not be central to your question. Accordingly, I can't be specific much beyond these brainstorms...





Consider:




  • Take a scripted approach to what Kdenlive does in GUI, similar to to the option of shutting down the machine once finished rendering. You could adapt a scropt to start writing your file, then automatically shut down your service via systemctl stop after you finish writing your file.

  • Make a script to write your file on a per-job basis using wait to let the write process finish before exiting.

  • Write a separate script using systemctl to end that process is a kind of power-move that should stop the process mid-file.

  • If you need a service involved, use it to "listen" or something, not to actually write—a service that calls a script that uses wait to end, if even necessary.






share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f255438%2fmaking-systemctl-to-shutdown-process-gracefully%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It shouldn't be a service



    Something that can't be terminated without causing catastrophic damage to its operation shouldn't be run as a "service", but as a per-job script or process.



    What you're attempting would compare to waiting for the Internet to stop requesting from your website before allowing systemctl stop apache2 to complete itself.



    For a local machine, if you need to shut down the machine, you won't be able to continue writing the file anyway. If you decided to do that, then you want systemctl to end the service without waiting.



    Maybe, your service should run another script that waits to terminate.



    The solution will be in your Product Roadmap, viz letting the developers tell the Product Manager what user experience isn't possible and what the user should experience instead.





    I'm answering this with the following suggestions, not knowing the contents of your script hltv_start.sh because you didn't share it. So, it must not be central to your question. Accordingly, I can't be specific much beyond these brainstorms...





    Consider:




    • Take a scripted approach to what Kdenlive does in GUI, similar to to the option of shutting down the machine once finished rendering. You could adapt a scropt to start writing your file, then automatically shut down your service via systemctl stop after you finish writing your file.

    • Make a script to write your file on a per-job basis using wait to let the write process finish before exiting.

    • Write a separate script using systemctl to end that process is a kind of power-move that should stop the process mid-file.

    • If you need a service involved, use it to "listen" or something, not to actually write—a service that calls a script that uses wait to end, if even necessary.






    share|improve this answer




























      0














      It shouldn't be a service



      Something that can't be terminated without causing catastrophic damage to its operation shouldn't be run as a "service", but as a per-job script or process.



      What you're attempting would compare to waiting for the Internet to stop requesting from your website before allowing systemctl stop apache2 to complete itself.



      For a local machine, if you need to shut down the machine, you won't be able to continue writing the file anyway. If you decided to do that, then you want systemctl to end the service without waiting.



      Maybe, your service should run another script that waits to terminate.



      The solution will be in your Product Roadmap, viz letting the developers tell the Product Manager what user experience isn't possible and what the user should experience instead.





      I'm answering this with the following suggestions, not knowing the contents of your script hltv_start.sh because you didn't share it. So, it must not be central to your question. Accordingly, I can't be specific much beyond these brainstorms...





      Consider:




      • Take a scripted approach to what Kdenlive does in GUI, similar to to the option of shutting down the machine once finished rendering. You could adapt a scropt to start writing your file, then automatically shut down your service via systemctl stop after you finish writing your file.

      • Make a script to write your file on a per-job basis using wait to let the write process finish before exiting.

      • Write a separate script using systemctl to end that process is a kind of power-move that should stop the process mid-file.

      • If you need a service involved, use it to "listen" or something, not to actually write—a service that calls a script that uses wait to end, if even necessary.






      share|improve this answer


























        0












        0








        0







        It shouldn't be a service



        Something that can't be terminated without causing catastrophic damage to its operation shouldn't be run as a "service", but as a per-job script or process.



        What you're attempting would compare to waiting for the Internet to stop requesting from your website before allowing systemctl stop apache2 to complete itself.



        For a local machine, if you need to shut down the machine, you won't be able to continue writing the file anyway. If you decided to do that, then you want systemctl to end the service without waiting.



        Maybe, your service should run another script that waits to terminate.



        The solution will be in your Product Roadmap, viz letting the developers tell the Product Manager what user experience isn't possible and what the user should experience instead.





        I'm answering this with the following suggestions, not knowing the contents of your script hltv_start.sh because you didn't share it. So, it must not be central to your question. Accordingly, I can't be specific much beyond these brainstorms...





        Consider:




        • Take a scripted approach to what Kdenlive does in GUI, similar to to the option of shutting down the machine once finished rendering. You could adapt a scropt to start writing your file, then automatically shut down your service via systemctl stop after you finish writing your file.

        • Make a script to write your file on a per-job basis using wait to let the write process finish before exiting.

        • Write a separate script using systemctl to end that process is a kind of power-move that should stop the process mid-file.

        • If you need a service involved, use it to "listen" or something, not to actually write—a service that calls a script that uses wait to end, if even necessary.






        share|improve this answer













        It shouldn't be a service



        Something that can't be terminated without causing catastrophic damage to its operation shouldn't be run as a "service", but as a per-job script or process.



        What you're attempting would compare to waiting for the Internet to stop requesting from your website before allowing systemctl stop apache2 to complete itself.



        For a local machine, if you need to shut down the machine, you won't be able to continue writing the file anyway. If you decided to do that, then you want systemctl to end the service without waiting.



        Maybe, your service should run another script that waits to terminate.



        The solution will be in your Product Roadmap, viz letting the developers tell the Product Manager what user experience isn't possible and what the user should experience instead.





        I'm answering this with the following suggestions, not knowing the contents of your script hltv_start.sh because you didn't share it. So, it must not be central to your question. Accordingly, I can't be specific much beyond these brainstorms...





        Consider:




        • Take a scripted approach to what Kdenlive does in GUI, similar to to the option of shutting down the machine once finished rendering. You could adapt a scropt to start writing your file, then automatically shut down your service via systemctl stop after you finish writing your file.

        • Make a script to write your file on a per-job basis using wait to let the write process finish before exiting.

        • Write a separate script using systemctl to end that process is a kind of power-move that should stop the process mid-file.

        • If you need a service involved, use it to "listen" or something, not to actually write—a service that calls a script that uses wait to end, if even necessary.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 19 mins ago









        Jesse SteeleJesse Steele

        12717




        12717






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f255438%2fmaking-systemctl-to-shutdown-process-gracefully%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Loup dans la culture

            How to solve the problem of ntp “Unable to contact time server” from KDE?

            Connection limited (no internet access)