LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   What is the proper way to start services on boot? (https://www.linuxquestions.org/questions/slackware-14/what-is-the-proper-way-to-start-services-on-boot-4175546465/)

Altiris 06-25-2015 11:01 PM

What is the proper way to start services on boot?
 
Been looking around, majority of these answers are around 2004-2008 and even so, they are rather confusing. Do I put a command in rc.M or rc.local ? At the moment I just put a command like this in rc.local "/etc/rc.d/rc.vsftpd &" without "" and that seems to work...but is this correct? Will Slackware properly shutdown the process when shutting down?

drgibbon 06-25-2015 11:15 PM

*deleted* proper answers below ;)

Hangaber 06-25-2015 11:38 PM

As you've probably already figured out, rc.M will attempt to execute rc.local so you can use either.
I also put mine in to rc.local, as that seems to be exactly what it was meant for.

For shutdown, if your app does not respond to the sighup/kill signal before shutdown, you can put your 'stop the app' command in to "rc.local_shutdown".
(You may have to create rc.local_shutdown and make it executable.)
The rc.K script will attempt to execute rc.local_shutdown if it exists & is executable.

kikinovak 06-26-2015 12:01 AM

Quote:

Originally Posted by Altiris (Post 5383152)
Been looking around, majority of these answers are around 2004-2008 and even so, they are rather confusing. Do I put a command in rc.M or rc.local ? At the moment I just put a command like this in rc.local "/etc/rc.d/rc.vsftpd &" without "" and that seems to work...but is this correct? Will Slackware properly shutdown the process when shutting down?

Uncomment the following line in /etc/inetd.conf:

Code:

# Very Secure File Transfer Protocol (FTP) server.
#ftp    stream  tcp    nowait  root    /usr/sbin/tcpd  vsftpd

Activate /etc/rc.d/rc.inetd on boot:

Code:

chmod +x /etc/rc.d/rc.inetd
Start it:
Code:

/etc/rc.d/rc.inetd start
Cheers,

Niki

PS: there's no rc.vsftpd.

bassmadrigal 06-26-2015 07:05 AM

I realize your specific situation was answered by kikinovak, but since you were confused, the below is to try an un-muddy the waters (hopefully I don't make it worse).

For anything that isn't already built into Slackware (like kikinovak showed you with vsftpd), the general consensus is to add any additional commands to your rc.local (if you add it to rc.M, it can cause issues with system upgrades or Slackware patches if there's changes made to rc.M). It is generally preferred that any new program installed on the system that needs to start at bootup (commonly called a daemon) should have it's own rc.program_name in /etc/rc.d that supports the start/stop/restart commands (most of these types of programs on SBo will have the needed rc.program_name file included). With these, it's preferred to call them in rc.local after checking to see if they're executable (this makes it follow the Slackware way of only needing to make the file executable to have it run, and if it isn't executable, you won't get an error because of it):

Code:

# Start program_name
if [ -x /etc/rc.d/rc.program_name ]; then
  /etc/rc.d/rc.program_name start
fi

If the program doesn't have an rc.program_name, you can either insert the command directly in rc.local, or you can create your own rc.program_name file. The below is a simple example, depending on the startup/shutdown procedure of your program, it can be more complicated (if the program just needs to be run to start, you might just be able to replace program_name with the name of the program and save the file -- if it is more complicated, it might take a bit more editing).

Code:

#!/bin/sh
# Start/stop/restart program_name

program_name_start() {
  echo "Starting program_name daemon: "
  /usr/bin/program_name
}

program_name_stop() {
  killall program_name 2> /dev/null
}

program_name_restart() {
  program_name_stop
  program_name_start
}

case "$1" in
'start')
  program_name_start
  ;;
'stop')
  program_name_stop
  ;;
'restart')
  program_name_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac

As for correctly shutting down the process, unless it is called somewhere else (like the rc.shutdown_local that Hangaber mentioned), Slackware will just send a SIGNAL code to close the program (I think it's actually two codes, with the second one being more severe to force it to close if the first one didn't do it -- but I can't remember which ones). If you want the program to actually shut down properly (if your program has that option), you can input the command in rc.shutdown_local just like rc.local file, but change it to the command to shut down the program (if you made your own rc.program_name, I would suggest putting the shutdown command in there, replacing the killall command under the stop), then, in the rc.shutdown_local, you could just add the if check to see if the rc.program_name is executable and then just add /etc/rc.d/rc.program_name stop, which will properly shut down the program rather than have Slackware manually killing it.

Didier Spaier 06-26-2015 08:07 AM

Here is a practical example of bassmadrigal's statement. It illustrates that you can display inconsistencies (like trying to start a service already running, or stop a non started service) and also the service' status.
Code:

#!/bin/sh
#
# Start/stop brltty
#
brltty_start() {
  if [ ! "`ps -C brltty --noheaders|wc -l`" = "0" ]; then
    echo "brltty is already started."
    brltty_status
    exit
  fi
  if [ -x /bin/brltty ]; then
    echo "Starting brltty daemon: /bin/brltty "
    /bin/brltty
  fi
}
brltty_stop() {
  NBPROC="`ps -C brltty --noheaders|wc -l`"
  if [  "$NBPROC" = "1" ]; then
    echo "Stopping brltty..."
    PID="`ps -C brltty --noheaders -o pid`"
    kill $PID
  elif [ "$NBPROC" = "0" ]; then   
    echo "brltty is not started."
  else
    echo "I can't stop brltty, several daemons are running:"
    brltty_status
  fi
}
brltty_status () {
  NBPROC="`ps -C brltty --noheaders|wc -l`"
  if [ "$NBPROC" = "0" ]; then
    echo "No active brltty daemon."
  elif [ "$NBPROC" = "1" ]; then
    echo "A brltty daemon is running, PID: `ps -C brltty --no-headers -o pid`"
  else
    ps -C brltty -o pid,args
fi
}
case "$1" in
'start')
  brltty_start
  ;;
'stop')
  brltty_stop
  ;;
'restart')
  brltty_stop
  sleep 3
  brltty_start
  ;;
'status')
  brltty_status
  ;;
*)
  echo "usage $0 restart|start|status|stop|"
esac


Altiris 06-28-2015 08:00 PM

Quote:

Originally Posted by kikinovak (Post 5383162)
Uncomment the following line in /etc/inetd.conf:

Code:

# Very Secure File Transfer Protocol (FTP) server.
#ftp    stream  tcp    nowait  root    /usr/sbin/tcpd  vsftpd

Activate /etc/rc.d/rc.inetd on boot:

Code:

chmod +x /etc/rc.d/rc.inetd
Start it:
Code:

/etc/rc.d/rc.inetd start
Cheers,

Niki

PS: there's no rc.vsftpd.

Oh I actually didn't know about that, I was just using rc.vsftpd as a place holder. Good to know though lol

Altiris 06-28-2015 08:02 PM

Quote:

Originally Posted by bassmadrigal (Post 5383258)
I realize your specific situation was answered by kikinovak, but since you were confused, the below is to try an un-muddy the waters (hopefully I don't make it worse).

For anything that isn't already built into Slackware (like kikinovak showed you with vsftpd), the general consensus is to add any additional commands to your rc.local (if you add it to rc.M, it can cause issues with system upgrades or Slackware patches if there's changes made to rc.M). It is generally preferred that any new program installed on the system that needs to start at bootup (commonly called a daemon) should have it's own rc.program_name in /etc/rc.d that supports the start/stop/restart commands (most of these types of programs on SBo will have the needed rc.program_name file included). With these, it's preferred to call them in rc.local after checking to see if they're executable (this makes it follow the Slackware way of only needing to make the file executable to have it run, and if it isn't executable, you won't get an error because of it):

Code:

# Start program_name
if [ -x /etc/rc.d/rc.program_name ]; then
  /etc/rc.d/rc.program_name start
fi

If the program doesn't have an rc.program_name, you can either insert the command directly in rc.local, or you can create your own rc.program_name file. The below is a simple example, depending on the startup/shutdown procedure of your program, it can be more complicated (if the program just needs to be run to start, you might just be able to replace program_name with the name of the program and save the file -- if it is more complicated, it might take a bit more editing).

Code:

#!/bin/sh
# Start/stop/restart program_name

program_name_start() {
  echo "Starting program_name daemon: "
  /usr/bin/program_name
}

program_name_stop() {
  killall program_name 2> /dev/null
}

program_name_restart() {
  program_name_stop
  program_name_start
}

case "$1" in
'start')
  program_name_start
  ;;
'stop')
  program_name_stop
  ;;
'restart')
  program_name_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac

As for correctly shutting down the process, unless it is called somewhere else (like the rc.shutdown_local that Hangaber mentioned), Slackware will just send a SIGNAL code to close the program (I think it's actually two codes, with the second one being more severe to force it to close if the first one didn't do it -- but I can't remember which ones). If you want the program to actually shut down properly (if your program has that option), you can input the command in rc.shutdown_local just like rc.local file, but change it to the command to shut down the program (if you made your own rc.program_name, I would suggest putting the shutdown command in there, replacing the killall command under the stop), then, in the rc.shutdown_local, you could just add the if check to see if the rc.program_name is executable and then just add /etc/rc.d/rc.program_name stop, which will properly shut down the program rather than have Slackware manually killing it.

This cleared things up a lot, thank you.

FeyFre 06-30-2015 07:42 AM

Slackware's init system is SysV compatible, isn't it?
So, I usually create one universal starter/stopper script in /etc/rc.d/ or /etc/rc.d/init.d (or whereever you like) and setup symlinks from /etc/rc.d/rc[0123456].d/ (or /etc/rc[0123456].d/ which are symlinks to former locations).
Such scheme allows Package.t?z to install service control scripts as files, not as patches to system scripts(in doinst.sh). And when package is being removed, service control scripts will be cleanly removed from system. No more edit conflicts, startup sequence control.

Didier Spaier 06-30-2015 07:52 AM

Quote:

Originally Posted by FeyFre (Post 5384992)
Slackware's init system is SysV compatible, isn't it?
So, I usually create one universal starter/stopper script in /etc/rc.d/ or /etc/rc.d/init.d (or whereever you like) and setup symlinks from /etc/rc.d/rc[0123456].d/ (or /etc/rc[0123456].d/ which are symlinks to former locations).
Such scheme allows Package.t?z to install service control scripts as files, not as patches to system scripts(in doinst.sh). And when package is being removed, service control scripts will be cleanly removed from system. No more edit conflicts, startup sequence control.

Each one is entitled to one's way.

But be careful: knowing how same folks react on this forum, maybe you just opened a can of worms or Pandora's box or <your preferred metaphor here> ;)

gnashley 06-30-2015 07:59 AM

I think "A Bob's box of canned-worms" is probably the proper phrase...

genss 06-30-2015 09:14 AM

Quote:

Originally Posted by FeyFre (Post 5384992)
Slackware's init system is SysV compatible, isn't it?

i think it is
i do remember seeing something ugly about it in the init scripts

Didier Spaier 06-30-2015 09:47 AM

Quote:

Originally Posted by genss (Post 5385029)
i think it is
i do remember seeing something ugly about it in the init scripts

Nothing ugly.

/etc/rc.d/init.d/README.functions says:
Code:

If you're reading this in /etc/init.d/, Slackware's real init directory is
/etc/rc.d/.  Maybe you already knew this, but it never hurts to say.  :-)

This script was taken from Fedora (and is presumably licensed under the GPL).
While I don't see Slackware init scripts making much use of it (but use it
if you wish), some third party init scripts (such as for commercial software
designed to run on Red Hat based systems) expect this script and use it in
their own init scripts, so it's a good idea to make it available here.

These functions are provided solely for commercial (or other) software that
expects to find "Red Hat-isms".  I wouldn't use them to write new init
scripts (personally), but if you've had experience with them in the past
and like them, by all means feel free.

It's planned to continue support for them.

Of course "this script" refers to /etc/rc.d/init.d/functions.

genss 06-30-2015 11:46 AM

Quote:

Originally Posted by Didier Spaier (Post 5385064)
Nothing ugly.

...

Of course "this script" refers to /etc/rc.d/init.d/functions.

looks better then i remember it
thx for looking instead of me :)


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