LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-09-2019, 12:34 PM   #1
nacheitor
LQ Newbie
 
Registered: Sep 2018
Posts: 11

Rep: Reputation: Disabled
Init services order


I am trying to add a service at the end of the linux service execution stack.

I have created the following service (/etc/init.d/my-service):

Code:
#!/bin/bash
### BEGIN INIT INFO
# Provides: my-service
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Run My Service
### END INIT INFO

# Service code .....

But when executing the command:

Code:
update-rc.d my-service defaults
The service is created in S01my-service like the rest of debian services. And it does not run at the end.

I have also tried this:

Code:
# Required-Start: $network network-manager
# Required-Stop: $network network-manager
I just need that when my service runs, it has access to the internet.

What is the problem?

Thanks in advance.

Last edited by nacheitor; 01-09-2019 at 12:38 PM.
 
Old 01-09-2019, 12:44 PM   #2
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by nacheitor View Post
The service is created in S01my-service like the rest of debian services. And it does not run at the end.

What is the problem?
Is this a Debian release that uses systemd?
If so, the starting order is determined BY it, not by the Sxx links and you need to create a systemd service for it.
The "required-start" etc clauses are for the old init system and will result into Sxx links that are numerical DIFFERENT, in the order they should be started.
I do not use systemd myself, so cannot tell you how to do it, but your reference to S01 "like the rest of debian services" makes me suspect you ARE using systemd and then the numbers aren't used anymore for the order of starting them (in fact, systemd often starts multiple services at the same time).
 
Old 01-10-2019, 06:44 AM   #3
nacheitor
LQ Newbie
 
Registered: Sep 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks ehartman, 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=/etc/init.d/my-service start
RemainAfterExit=true
ExecStop=/etc/init.d/my-service stop

[Install]
WantedBy=network-online.target
The service start and stops correctly but, inside the shell script I call (ping www.google.com) for cheching network, and 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.

Last edited by nacheitor; 01-10-2019 at 06:47 AM.
 
  


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
Logi Sales Manager on Ncurses (invoice, invoicing, orders, order, sale order, sales order...)? Xeratul Linux - Software 0 03-25-2017 02:45 PM
[SOLVED] order of init services mahmoodn Linux - Server 7 05-06-2011 12:50 AM
What is the exact diff between init 1,init S and init s challavijay Linux - Newbie 1 08-05-2010 06:51 AM

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

All times are GMT -5. The time now is 06:01 AM.

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