Input command into background service

Clash 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
command-line services systemd
add a comment |Â
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
command-line services systemd
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 intmuxorscreen, 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
add a comment |Â
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
command-line services systemd
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
command-line services systemd
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 intmuxorscreen, 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
add a comment |Â
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 intmuxorscreen, 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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited May 27 at 20:06
answered May 27 at 11:25
Sebastian Stark
4,643838
4,643838
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
tmuxorscreen, 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