Input command into background service

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








up vote
2
down vote

favorite












I have a custom service running in the background for a custom gmod game service.
I wrote my own gmod.service file so now I can start it with service gmod start. You can see it below.
Is it possible to input a command into that service from a terminal or a bash script so I can change the map for example?
Thanks in advance



[Unit] 
Description=Gmod server
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh
[Install]
WantedBy=multi-user.target






share|improve this question






















  • Does the script accept commands if you run it directly from the terminal?
    – muru
    May 17 at 11:58










  • @muru Yeah it does
    – Kevin Snijder
    May 18 at 6:47










  • Then I'd suggest that you run the script in tmux or screen, and then attach or detach to the tmux/screen session as needed.
    – muru
    May 18 at 6:51










  • That might work! I'll try it later. Thanks a bunch :)
    – Kevin Snijder
    May 18 at 7:09














up vote
2
down vote

favorite












I have a custom service running in the background for a custom gmod game service.
I wrote my own gmod.service file so now I can start it with service gmod start. You can see it below.
Is it possible to input a command into that service from a terminal or a bash script so I can change the map for example?
Thanks in advance



[Unit] 
Description=Gmod server
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh
[Install]
WantedBy=multi-user.target






share|improve this question






















  • Does the script accept commands if you run it directly from the terminal?
    – muru
    May 17 at 11:58










  • @muru Yeah it does
    – Kevin Snijder
    May 18 at 6:47










  • Then I'd suggest that you run the script in tmux or screen, and then attach or detach to the tmux/screen session as needed.
    – muru
    May 18 at 6:51










  • That might work! I'll try it later. Thanks a bunch :)
    – Kevin Snijder
    May 18 at 7:09












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have a custom service running in the background for a custom gmod game service.
I wrote my own gmod.service file so now I can start it with service gmod start. You can see it below.
Is it possible to input a command into that service from a terminal or a bash script so I can change the map for example?
Thanks in advance



[Unit] 
Description=Gmod server
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh
[Install]
WantedBy=multi-user.target






share|improve this question














I have a custom service running in the background for a custom gmod game service.
I wrote my own gmod.service file so now I can start it with service gmod start. You can see it below.
Is it possible to input a command into that service from a terminal or a bash script so I can change the map for example?
Thanks in advance



[Unit] 
Description=Gmod server
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh
[Install]
WantedBy=multi-user.target








share|improve this question













share|improve this question




share|improve this question








edited May 27 at 11:32









Sebastian Stark

4,643838




4,643838










asked May 14 at 20:09









Kevin Snijder

112




112











  • Does the script accept commands if you run it directly from the terminal?
    – muru
    May 17 at 11:58










  • @muru Yeah it does
    – Kevin Snijder
    May 18 at 6:47










  • Then I'd suggest that you run the script in tmux or screen, and then attach or detach to the tmux/screen session as needed.
    – muru
    May 18 at 6:51










  • That might work! I'll try it later. Thanks a bunch :)
    – Kevin Snijder
    May 18 at 7:09
















  • Does the script accept commands if you run it directly from the terminal?
    – muru
    May 17 at 11:58










  • @muru Yeah it does
    – Kevin Snijder
    May 18 at 6:47










  • Then I'd suggest that you run the script in tmux or screen, and then attach or detach to the tmux/screen session as needed.
    – muru
    May 18 at 6:51










  • That might work! I'll try it later. Thanks a bunch :)
    – Kevin Snijder
    May 18 at 7:09















Does the script accept commands if you run it directly from the terminal?
– muru
May 17 at 11:58




Does the script accept commands if you run it directly from the terminal?
– muru
May 17 at 11:58












@muru Yeah it does
– Kevin Snijder
May 18 at 6:47




@muru Yeah it does
– Kevin Snijder
May 18 at 6:47












Then I'd suggest that you run the script in tmux or screen, and then attach or detach to the tmux/screen session as needed.
– muru
May 18 at 6:51




Then I'd suggest that you run the script in tmux or screen, and then attach or detach to the tmux/screen session as needed.
– muru
May 18 at 6:51












That might work! I'll try it later. Thanks a bunch :)
– Kevin Snijder
May 18 at 7:09




That might work! I'll try it later. Thanks a bunch :)
– Kevin Snijder
May 18 at 7:09










1 Answer
1






active

oldest

votes

















up vote
3
down vote













Use systemd unit template files



This is a good example for when systemd unit templates can be used. It is possible to have a systemd service to be called with an argument and use that argument in the service definition to e. g. hand it to the program that is run. Here is an example for your case:



Install your unit as



/etc/systemd/system/gmod@.service


Change the file to look like this:



[Unit] 
Description=Gmod server (map: %I)
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh %i
[Install]
WantedBy=multi-user.target
DefaultInstance=myDefaultMap


(You might need to run systemctl daemon-reload at this point to make systemd read the changed file). After this you will be able to start gmod with an argument like this:



systemctl start gmod@myMapName.service


Systemd will use the template file and replace I% with the argument, and %i with the shell quoted argument, then start it as a service instance named gmod@myMapName.service. You can verify this by running



systemctl status gmod@myMapName


You can also have it automatically starting a default instance at boot time like this:



systemctl enable gmod@


This way you could even start multiple instances of gmod, if the program allows that. For further reading on the topic check the systemd.unit(5) manual page.






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036259%2finput-command-into-background-service%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    Use systemd unit template files



    This is a good example for when systemd unit templates can be used. It is possible to have a systemd service to be called with an argument and use that argument in the service definition to e. g. hand it to the program that is run. Here is an example for your case:



    Install your unit as



    /etc/systemd/system/gmod@.service


    Change the file to look like this:



    [Unit] 
    Description=Gmod server (map: %I)
    After=network.target
    [Service]
    Type=simple
    ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh %i
    [Install]
    WantedBy=multi-user.target
    DefaultInstance=myDefaultMap


    (You might need to run systemctl daemon-reload at this point to make systemd read the changed file). After this you will be able to start gmod with an argument like this:



    systemctl start gmod@myMapName.service


    Systemd will use the template file and replace I% with the argument, and %i with the shell quoted argument, then start it as a service instance named gmod@myMapName.service. You can verify this by running



    systemctl status gmod@myMapName


    You can also have it automatically starting a default instance at boot time like this:



    systemctl enable gmod@


    This way you could even start multiple instances of gmod, if the program allows that. For further reading on the topic check the systemd.unit(5) manual page.






    share|improve this answer


























      up vote
      3
      down vote













      Use systemd unit template files



      This is a good example for when systemd unit templates can be used. It is possible to have a systemd service to be called with an argument and use that argument in the service definition to e. g. hand it to the program that is run. Here is an example for your case:



      Install your unit as



      /etc/systemd/system/gmod@.service


      Change the file to look like this:



      [Unit] 
      Description=Gmod server (map: %I)
      After=network.target
      [Service]
      Type=simple
      ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh %i
      [Install]
      WantedBy=multi-user.target
      DefaultInstance=myDefaultMap


      (You might need to run systemctl daemon-reload at this point to make systemd read the changed file). After this you will be able to start gmod with an argument like this:



      systemctl start gmod@myMapName.service


      Systemd will use the template file and replace I% with the argument, and %i with the shell quoted argument, then start it as a service instance named gmod@myMapName.service. You can verify this by running



      systemctl status gmod@myMapName


      You can also have it automatically starting a default instance at boot time like this:



      systemctl enable gmod@


      This way you could even start multiple instances of gmod, if the program allows that. For further reading on the topic check the systemd.unit(5) manual page.






      share|improve this answer
























        up vote
        3
        down vote










        up vote
        3
        down vote









        Use systemd unit template files



        This is a good example for when systemd unit templates can be used. It is possible to have a systemd service to be called with an argument and use that argument in the service definition to e. g. hand it to the program that is run. Here is an example for your case:



        Install your unit as



        /etc/systemd/system/gmod@.service


        Change the file to look like this:



        [Unit] 
        Description=Gmod server (map: %I)
        After=network.target
        [Service]
        Type=simple
        ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh %i
        [Install]
        WantedBy=multi-user.target
        DefaultInstance=myDefaultMap


        (You might need to run systemctl daemon-reload at this point to make systemd read the changed file). After this you will be able to start gmod with an argument like this:



        systemctl start gmod@myMapName.service


        Systemd will use the template file and replace I% with the argument, and %i with the shell quoted argument, then start it as a service instance named gmod@myMapName.service. You can verify this by running



        systemctl status gmod@myMapName


        You can also have it automatically starting a default instance at boot time like this:



        systemctl enable gmod@


        This way you could even start multiple instances of gmod, if the program allows that. For further reading on the topic check the systemd.unit(5) manual page.






        share|improve this answer














        Use systemd unit template files



        This is a good example for when systemd unit templates can be used. It is possible to have a systemd service to be called with an argument and use that argument in the service definition to e. g. hand it to the program that is run. Here is an example for your case:



        Install your unit as



        /etc/systemd/system/gmod@.service


        Change the file to look like this:



        [Unit] 
        Description=Gmod server (map: %I)
        After=network.target
        [Service]
        Type=simple
        ExecStart=/bin/bash /home/server/Documents/Servers/Gmod/run_gmod.sh %i
        [Install]
        WantedBy=multi-user.target
        DefaultInstance=myDefaultMap


        (You might need to run systemctl daemon-reload at this point to make systemd read the changed file). After this you will be able to start gmod with an argument like this:



        systemctl start gmod@myMapName.service


        Systemd will use the template file and replace I% with the argument, and %i with the shell quoted argument, then start it as a service instance named gmod@myMapName.service. You can verify this by running



        systemctl status gmod@myMapName


        You can also have it automatically starting a default instance at boot time like this:



        systemctl enable gmod@


        This way you could even start multiple instances of gmod, if the program allows that. For further reading on the topic check the systemd.unit(5) manual page.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 27 at 20:06

























        answered May 27 at 11:25









        Sebastian Stark

        4,643838




        4,643838






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036259%2finput-command-into-background-service%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Unable to execute new pre-installation script (/var/lib/dpkg/tmp.ci/preinst)

            Running the scala interactive shell from the command line

            Do not install recommended packages of dependencies