Labels

Android (1) bash (2) boost (2) C (34) C++ (2) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (2) Dreamweaver (2) Eclipse (3) fail2ban (4) git (5) GitHub (4) Hacking (3) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (31) javascript (3) Linux (167) Mac (19) Machine Learning (1) mySQL (48) Netbeans (4) Networking (1) Nexus (1) OpenVMS (6) Oracle (1) Pandas (3) php (16) Postgresql (8) Python (9) raid (1) RedHat (14) Samba (2) Slackware (47) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (3) Visual Basic (1) Visual Studio (1) Windows (2)

Tuesday, 3 August 2021

Starting Services at boot time in slackware

 A reminder...

Any networking services should be handles by rc.init2 and simply requires making the appropriate script in /etc/rc.d executable.

But if we add our own custom script, then we can add the following to rc.local

# Start MCR Monitor
if [ -x /etc/rc.d/rc.mcr_monitor ]; then
        echo "Starting MCR Monitor..."
        . /etc/rc.d/rc.mcr_monitor start
fi


similarly, we can create rc.local_shutdown with the same permissions as rc.local and add the following;

# Stop MCR Monitor
if [ -x /etc/rc.d/rc.mcr_monitor ]; then
        echo "Stopping MCR Monitor..."
        . /etc/rc.d/rc.mcr_monitor stop
fi


We could add the above to /etc/rc.M and /etc/rc.K but I prefer the former.

Example of a generic control script is as below;

#
# run control file for NAME
#
# User options:
#
# USER: set an alternative uid (default: www)
# GROUP: set an alternative group (default: www)
#
 
USER=root
GROUP=root
PRGNAM=mcr_monitor
BIN=/usr/bin/mcr_monitor
#CONF=/etc/prog.conf
#ARGS=-c $CONF -u $USER -g $GROUP
PID=/var/run/mcr_monitor/mcr_monitor.pid
 
magicd_start()
{
  if [ ! -r $CONF ]; then
    echo "No configuration file available. Aborting"
    exit 1
  fi
 
  if [ -s $PID ]; then
    echo "$PRGNAM is already running: $(cat $PID)"
    exit 1
  fi
 
  if [ -x $BIN ]; then
    echo "Starting $PRGNAM: $BIN $ARGS"
    $BIN
  fi
}
 
magicd_stop()
{
  if [ -s $PID ]; then 
    kill -QUIT $(cat $PID)
  fi
}
 
magicd_restart()
{
  magicd_stop
  sleep 3         # NOTE: adjust or remove if possible
  magicd_start
}
 
magicd_status()
{
  if [ -s $PID ]; then
    echo "$PRGNAM is running: $(cat $PID)"
  else
    echo "$PRGNAM does not seem to be running"
  fi
}
 
case $1 in
restart)
        magicd_restart
        ;;
start)
        magicd_start
        ;;
status)
        magicd_status
        ;;
stop)
        magicd_stop
        ;;
*)
        echo "Usage: $0 {restart|start|status|stop}"
        ;;
esac

No comments:

Post a Comment

Note: only a member of this blog may post a comment.