Making systemctl to shutdown process gracefully Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionMake systemd reload only single openvpn process and not the whole groupmysql service restarted during user being connected lead to failing serviceautomatic reconnect of wifi via systemd on raspbianMinecraft server startup/shutdown with systemdsystemd and OpenVPN woes after an Ubuntu upgradeWhy is systemd stopping service immediately after it is started?Systemd irregular timing issueInstruct to execute an unit after completing another unit successfullysystemd: finish the execution of custom shell script before starting nginxStopping systemd unit together with another. Starting works

How come Sam didn't become Lord of Horn Hill?

Overriding an object in memory with placement new

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

What does the word "veer" mean here?

Why did the rest of the Eastern Bloc not invade Yugoslavia?

How would the world control an invulnerable immortal mass murderer?

Is there a program I can run on the C64 to speed up booting of a game?

Can I cast Passwall to drop an enemy into a 20-foot pit?

How can I make names more distinctive without making them longer?

At the end of Thor: Ragnarok why don't the Asgardians turn and head for the Bifrost as per their original plan?

How to answer "Have you ever been terminated?"

Storing hydrofluoric acid before the invention of plastics

How to react to hostile behavior from a senior developer?

Why didn't this character "real die" when they blew their stack out in Altered Carbon?

Single word antonym of "flightless"

porting install scripts : can rpm replace apt?

Can an alien society believe that their star system is the universe?

51k Euros annually for a family of 4 in Berlin: Is it enough?

Is the Standard Deduction better than Itemized when both are the same amount?

Identify plant with long narrow paired leaves and reddish stems

Dating a Former Employee

Why do we bend a book to keep it straight?

How to find out what spells would be useless to a blind NPC spellcaster?

Is there a (better) way to access $wpdb results?



Making systemctl to shutdown process gracefully



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionMake systemd reload only single openvpn process and not the whole groupmysql service restarted during user being connected lead to failing serviceautomatic reconnect of wifi via systemd on raspbianMinecraft server startup/shutdown with systemdsystemd and OpenVPN woes after an Ubuntu upgradeWhy is systemd stopping service immediately after it is started?Systemd irregular timing issueInstruct to execute an unit after completing another unit successfullysystemd: finish the execution of custom shell script before starting nginxStopping systemd unit together with another. Starting works



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








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














bumped to the homepage by Community 9 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






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














bumped to the homepage by Community 9 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






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





bumped to the homepage by Community 9 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 9 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






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.

  • If the service only "listens", then runs another script that writes your file using wait, then you could theoretically systemctl stop your service while allowing the write operation to finish, which I think is your goal.





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.

    • If the service only "listens", then runs another script that writes your file using wait, then you could theoretically systemctl stop your service while allowing the write operation to finish, which I think is your goal.





    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.

      • If the service only "listens", then runs another script that writes your file using wait, then you could theoretically systemctl stop your service while allowing the write operation to finish, which I think is your goal.





      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.

        • If the service only "listens", then runs another script that writes your file using wait, then you could theoretically systemctl stop your service while allowing the write operation to finish, which I think is your goal.





        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.

        • If the service only "listens", then runs another script that writes your file using wait, then you could theoretically systemctl stop your service while allowing the write operation to finish, which I think is your goal.






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 16 at 14:13

























        answered Mar 16 at 9:37









        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







            -services, systemd

            Popular posts from this blog

            Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

            What is this called? Old film camera viewer?What makes a good film camera?What to do with an old film camera?What should one look for when buying a used film camera?What is the value and age of this pre-1967 Ricoh 35 mm camera?DSLR recommendation, question about old Canon 35mm film Camera & lensesCan anyone identify the silver rangefinder-style camera in this advertisement?What kind of a Polaroid 600-camera is this?Will an old film camera still work even when not used in a very long time?What is this camera / Can I develop the film?How to fit an action camera into antique (bellows) housing?What to check when buying used and old film bodies?

            Why is this plane circling around the Lucknow airport every day?Why do aircraft on Flight Radar 24 jump around randomly sometimes?What airport has this walkway over a taxiway?How does Chicago O'Hare's tower sequence aircraft at peak capacity?Which airport is featured in this Delta commercial?After a crash, for how long is the airport closed?Can a passenger plane stand still in the air, or hover at a fixed location above a ground?What are those trucks towing around, and why?What is this airport outside of Cairo, Egypt?Which US airport has the lowest circling MDH?What is this airport video?