Why does systemd stop my service but not restart it?
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
I am having some problems understanding the ideas behind systemd. What I am trying to do is configure a service which should normally run, and that depends on mariadb to work properly. Here is the (anonymized) .service file that I came up with:
[Unit]
Description=My Service
Requires=mariadb.service
After=mariadb.service
[Service]
ExecStart=/usr/bin/python2.7 -u /home/serviceuser/service.py
WorkingDirectory=/home/serviceuser
User=serviceuser
[Install]
WantedBy=multi-user.target
It worked well enough, but I noticed that sometimes the service would spontaneously stop. After some debugging I figured out that this coincided with mariadb security updates being installed automatically by ubuntu. Testing this, I found out that stopping mariadb will stop my service first (which makes sense to me) but starting mariadb back up again will not start my service.
I would expect that the WantedBy means that multi-user.target would really like My Service to run. So systemd should try to ensure that it runs whenever there is nothing that would prevent that. Things that would prevent it would be that the service or one of its dependencies was explicitly stopped. As soon as that preventing condition goes away, systemd should start the service again.
What is the mistake in this reasoning that leads to the service NOT being started again? How can I achieve the behavior I want with systemd?
services systemd
add a comment |Â
up vote
0
down vote
favorite
I am having some problems understanding the ideas behind systemd. What I am trying to do is configure a service which should normally run, and that depends on mariadb to work properly. Here is the (anonymized) .service file that I came up with:
[Unit]
Description=My Service
Requires=mariadb.service
After=mariadb.service
[Service]
ExecStart=/usr/bin/python2.7 -u /home/serviceuser/service.py
WorkingDirectory=/home/serviceuser
User=serviceuser
[Install]
WantedBy=multi-user.target
It worked well enough, but I noticed that sometimes the service would spontaneously stop. After some debugging I figured out that this coincided with mariadb security updates being installed automatically by ubuntu. Testing this, I found out that stopping mariadb will stop my service first (which makes sense to me) but starting mariadb back up again will not start my service.
I would expect that the WantedBy means that multi-user.target would really like My Service to run. So systemd should try to ensure that it runs whenever there is nothing that would prevent that. Things that would prevent it would be that the service or one of its dependencies was explicitly stopped. As soon as that preventing condition goes away, systemd should start the service again.
What is the mistake in this reasoning that leads to the service NOT being started again? How can I achieve the behavior I want with systemd?
services systemd
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am having some problems understanding the ideas behind systemd. What I am trying to do is configure a service which should normally run, and that depends on mariadb to work properly. Here is the (anonymized) .service file that I came up with:
[Unit]
Description=My Service
Requires=mariadb.service
After=mariadb.service
[Service]
ExecStart=/usr/bin/python2.7 -u /home/serviceuser/service.py
WorkingDirectory=/home/serviceuser
User=serviceuser
[Install]
WantedBy=multi-user.target
It worked well enough, but I noticed that sometimes the service would spontaneously stop. After some debugging I figured out that this coincided with mariadb security updates being installed automatically by ubuntu. Testing this, I found out that stopping mariadb will stop my service first (which makes sense to me) but starting mariadb back up again will not start my service.
I would expect that the WantedBy means that multi-user.target would really like My Service to run. So systemd should try to ensure that it runs whenever there is nothing that would prevent that. Things that would prevent it would be that the service or one of its dependencies was explicitly stopped. As soon as that preventing condition goes away, systemd should start the service again.
What is the mistake in this reasoning that leads to the service NOT being started again? How can I achieve the behavior I want with systemd?
services systemd
I am having some problems understanding the ideas behind systemd. What I am trying to do is configure a service which should normally run, and that depends on mariadb to work properly. Here is the (anonymized) .service file that I came up with:
[Unit]
Description=My Service
Requires=mariadb.service
After=mariadb.service
[Service]
ExecStart=/usr/bin/python2.7 -u /home/serviceuser/service.py
WorkingDirectory=/home/serviceuser
User=serviceuser
[Install]
WantedBy=multi-user.target
It worked well enough, but I noticed that sometimes the service would spontaneously stop. After some debugging I figured out that this coincided with mariadb security updates being installed automatically by ubuntu. Testing this, I found out that stopping mariadb will stop my service first (which makes sense to me) but starting mariadb back up again will not start my service.
I would expect that the WantedBy means that multi-user.target would really like My Service to run. So systemd should try to ensure that it runs whenever there is nothing that would prevent that. Things that would prevent it would be that the service or one of its dependencies was explicitly stopped. As soon as that preventing condition goes away, systemd should start the service again.
What is the mistake in this reasoning that leads to the service NOT being started again? How can I achieve the behavior I want with systemd?
services systemd
services systemd
edited Feb 27 at 23:10
asked Feb 26 at 23:08
Medo42
1011
1011
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
mariadb is set as dependency of My Service so starting it will also launch mariadb if not running.
Consequently stopping mariadb also stop My Service.
But if you only restart mariadb My Service will not be started automatically.
You may like to enable My Service: systemctl enable My Service.service
That will configure it to be started after booting up. But if I'm right stopping it shall keep it stopped until reboot or manual restart.
Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions.
â Medo42
Feb 27 at 22:55
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
mariadb is set as dependency of My Service so starting it will also launch mariadb if not running.
Consequently stopping mariadb also stop My Service.
But if you only restart mariadb My Service will not be started automatically.
You may like to enable My Service: systemctl enable My Service.service
That will configure it to be started after booting up. But if I'm right stopping it shall keep it stopped until reboot or manual restart.
Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions.
â Medo42
Feb 27 at 22:55
add a comment |Â
up vote
0
down vote
mariadb is set as dependency of My Service so starting it will also launch mariadb if not running.
Consequently stopping mariadb also stop My Service.
But if you only restart mariadb My Service will not be started automatically.
You may like to enable My Service: systemctl enable My Service.service
That will configure it to be started after booting up. But if I'm right stopping it shall keep it stopped until reboot or manual restart.
Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions.
â Medo42
Feb 27 at 22:55
add a comment |Â
up vote
0
down vote
up vote
0
down vote
mariadb is set as dependency of My Service so starting it will also launch mariadb if not running.
Consequently stopping mariadb also stop My Service.
But if you only restart mariadb My Service will not be started automatically.
You may like to enable My Service: systemctl enable My Service.service
That will configure it to be started after booting up. But if I'm right stopping it shall keep it stopped until reboot or manual restart.
mariadb is set as dependency of My Service so starting it will also launch mariadb if not running.
Consequently stopping mariadb also stop My Service.
But if you only restart mariadb My Service will not be started automatically.
You may like to enable My Service: systemctl enable My Service.service
That will configure it to be started after booting up. But if I'm right stopping it shall keep it stopped until reboot or manual restart.
answered Feb 26 at 23:36
![](https://lh5.googleusercontent.com/-YEXSBBJmefY/AAAAAAAAAAI/AAAAAAAADYc/wzbzAuHDfv0/photo.jpg?sz=32)
![](https://lh5.googleusercontent.com/-YEXSBBJmefY/AAAAAAAAAAI/AAAAAAAADYc/wzbzAuHDfv0/photo.jpg?sz=32)
augustin vm
234
234
Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions.
â Medo42
Feb 27 at 22:55
add a comment |Â
Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions.
â Medo42
Feb 27 at 22:55
Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions.
â Medo42
Feb 27 at 22:55
Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions.
â Medo42
Feb 27 at 22:55
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%2f1010107%2fwhy-does-systemd-stop-my-service-but-not-restart-it%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