LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-10-2019, 12:07 PM   #1
nacheitor
LQ Newbie
 
Registered: Sep 2018
Posts: 11

Rep: Reputation: Disabled
Systemd shutdown service problem


Hi, I have created a file /lib/systemd/system/my-service.service like this:

Code:
[Unit]
Description=My Service
After=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=true
ExecStop=ping www.google.com

[Install]
WantedBy=network-online.target
The service start and stops correctly but, I obtain the next output:

Code:
PING www.google.com (172.217.17.4) 56(84) bytes of data.
64 bytes from mad07s09-in-f4.1e100.net (172.217.17.4): icmp_seq=1 ttl=53 time=11                                                                                                             .0 ms
64 bytes from mad07s09-in-f4.1e100.net (172.217.17.4): icmp_seq=2 ttl=53 time=10                                                                                                             .0 ms
64 bytes from mad07s09-in-f4.1e100.net (172.217.17.4): icmp_seq=3 ttl=53 time=69                                                                                                             .9 ms
ping: sendmsg: The network is inaccessible
ping: sendmsg: The network is inaccessible
ping: sendmsg: The network is inaccessible
ping: sendmsg: The network is inaccessible
ping: sendmsg: The network is inaccessible
In the begining of execution of the service the network is up but in the middle of the exetion the networg goes down.

How could I stop the rest of the services until my-service ends?

Thanks in advance.
 
Old 01-11-2019, 07:52 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
my-service will never end. The ping program just goes on until it’s interrupted. You can limit the number of echo packets with the -c (count) option. There are also two timeout options, -w and -W.

Last edited by berndbausch; 01-11-2019 at 07:55 AM.
 
Old 01-11-2019, 12:40 PM   #3
nacheitor
LQ Newbie
 
Registered: Sep 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
Hi, berndbausch. I know that the ping program just goes on until it’s interrupted. I used the ping program to know if I have Internet access available for the time necessary to update my distribution packages, I used it only for testing purposes. And I have verified that I only receive 3 pings before losing the connection.

Thanks for your help.

Last edited by nacheitor; 01-11-2019 at 12:42 PM.
 
Old 01-11-2019, 06:11 PM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Do I understand you right: You want to perform an action when the system shuts down, but you need internet access to accomplish it?

If so, I have no experience with it, but googling for systemd shutdown sequence yields a few promising results, such as https://superuser.com/questions/1016...016848#1016848.

Last edited by berndbausch; 01-11-2019 at 06:18 PM. Reason: Total rewrite
 
Old 01-12-2019, 02:44 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by nacheitor View Post
I have created a file /lib/systemd/system/...
there's your first error there.
you should've created that file in /etc/systemd/system instead.
read the docs.

i also find your service file a little convoluted:
Code:
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=true
ExecStop=ping www.google.com
all this to keep the machine online during shutdown?
not sure what would be better, but this doesn't seem the right way.
why not simply create a service that runs upgrades on shutdown, before the network shuts down?
have you tried searching "systemd run updates during shutdown" or some such?

the problem you are seeing is that something else is shutting down important parts of the system/networking while your ping is running. could be DNS, could be sth else.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Used to shutdown/reboot from CLI but since systemd replaced init "shutdown" cmnd broke? Beagleburt Debian 10 09-24-2019 07:49 PM
How to write slow, blocking systemd shutdown service? charlweed Linux - General 9 03-22-2019 03:22 PM
Can't access full journalctl from script via systemd service even though user is in systemd-journal group iwtbf Linux - Newbie 0 02-19-2016 02:44 PM
[SOLVED] shutdown works, but /lib/systemd/system/shutdown.target does not. kaz2100 Debian 3 08-06-2014 03:28 AM
Boot Delay 30min: systemd-analyze blame systemd-tmpfiles-setup.service BGHolmes Fedora 0 07-27-2011 09:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration