LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   start-stop-daemon in Slackware? (http://www.linuxquestions.org/questions/slackware-14/start-stop-daemon-in-slackware-888116/)

qlands 06-24-2011 09:04 AM

start-stop-daemon in Slackware?
 
Hi,

I have an init scripts that uses start-stop-daemon but Slackware 13.37 does not have it.

How can I emulate it or install it?

Thanks,
Carlos

Skaperen 06-24-2011 09:21 AM

From what distribution is that script originally for? What does it need to actually do to start up whatever it is starting?

I don't know if there is such a thing independently made for Slackware. Ordinarily, if you need to do things that way, you need to do it all that way, and thus need to run another distribution instead (to avoid all the manual rewrites you'd have to do that effectively morph Slackware into something else). If you want to stick with Slackware, just rewrite the script to literally do on its own everything that needs to be done. This is how things used to be, anyway before all these new fangled toys made life more complicated, and systems harder to debug.

tronayne 06-24-2011 09:48 AM

Using the files you'll find in /etc/rc.d as a model rewrite your script(s) to look the same. Save the rewritten script in /etc/rc.d as "rc.whatever" (where "whatever" is the name of the daemon you're trying to control), make it executable (chmod 755 /etc/rc.d/rc.whatever and add the name to /etc/rc.local in this form (this is /etc/rc.d/rc.httpd, it should give you the idea of what to do using your own daemon name and path settings):
Code:

#!/bin/sh
#
# /etc/rc.d/rc.httpd
#
# Start/stop/restart/graceful[ly restart]/graceful[ly]-stop
# the Apache (httpd) web server.
#
# To make Apache start automatically at boot, make this
# file executable:  chmod 755 /etc/rc.d/rc.httpd
#
# For information on these options, "man apachectl".

case "$1" in
  'start')
    /usr/sbin/apachectl -k start
  ;;
  'stop')
    /usr/sbin/apachectl -k stop
    killall httpd
    rm -f /var/run/httpd/*.pid
  ;;
  'restart')
    /usr/sbin/apachectl -k restart
  ;;
  'graceful')
    /usr/sbin/apachectl -k graceful
  ;;
  'graceful-stop')
    /usr/sbin/apachectl -k graceful-stop
  ;;
  *)
    echo "Usage: $0 {start|stop|restart|graceful|graceful-stop}"
  ;;
esac

Remember, the above is an existing program, copy it to a new file and edit that. You may not need anything but a start, stop and restart section in your new file.

In /etc/rc.local:
Code:

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

also, add the name to /etc/rc.local_shutdown in this form
Code:

# Stop whatever
#
if [ -x /etc/rc.d/rc.whatever ]; then
        /etc/rc.d/rc.whatever stop
fi

That's probably the easiest.

Hope this helps some.

qlands 06-24-2011 10:28 AM

1 Attachment(s)
Hi,

This is the original script:

Code:

start() {
      log_daemon_msg "Starting ActiveMQ" "activemq"
      if start-stop-daemon -b --chuid activemq --make-pidfile --start --pidfile /var/run/activemq.pid --startas $ACTIVEMQ_HOME/bin/activemq-admin start ; then
          log_end_msg 0
      else
          echo "Failed"
          log_end_msg 1
      fi
}
stop() {
      log_daemon_msg "Stopping ActiveMQ" "activemq"
      if start-stop-daemon --stop --pidfile /var/run/activemq.pid ; then
          log_end_msg 0
      else
          log_end_msg 1
      fi
      # $ACTIVEMQ_HOME/bin/activemq-admin stop
}

I checked if activemq-admin have the option to indicate the pid file but it does not.

I uploaded the file so you can see the whole thing.

Many thanks in advance.

Diantre 06-24-2011 11:17 AM

The script is sourcing /lib/lsb/init-functions, I can only guess that the functions log_daemon_msg, start-stop-daemon and log_end_msg are defined there.

What I would do in your case is get /lib/lsb/init-functions from the distro this script come from, study what the functions do exactly, and then write my own Slackware script as tronayne suggests.

It seems that log_daemon_msg logs messages to the file activemq, log_end_msg is also related to logging. The function start-stop-daemon is the one that starts/stops the daemon, using parameters --start and --stop. But once again, I'm just guessing without actually seeing what /lib/lsb/init-functions does.

Woodsman 06-24-2011 03:21 PM

Quote:

How can I emulate it or install it?
Nothing fancy here, but something I wrote a long time ago. Works for me, but YMMV.

Code:

#!/bin/sh
# /usr/local/sbin/service

# A script to start/stop/restart system scripts without typing the full path.

RCD_PATH="/etc/rc.d"

SERVICE=$1
ACTION=$2
# Additional parameters that could be passed to the script
PARAM1=$3
PARAM2=$4
PARAM3=$5

if [ -z "$SERVICE" ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
  echo "Correct usage: $0 script-name [action] [parameter] [parameter] [parameter]"
  exit 0
fi
SERVICE="`echo $SERVICE | sed 's/^rc.//'`"
if [ -r "/etc/slackware-version" ]; then
 if [ ! -f "$RCD_PATH/rc.$SERVICE" ]; then
    echo "$RCD_PATH/rc.$SERVICE does not exist."
    exit 0
  else
    sh $RCD_PATH/rc.$SERVICE $ACTION $PARAM1 $PARAM2 $PARAM3
  fi
else
  echo "Unable to determine the operating system."
fi

Feel free to modify to your heart's content.

T3slider 06-24-2011 04:03 PM

Quote:

Originally Posted by qlands (Post 4394624)
Code:

if start-stop-daemon -b --chuid activemq --make-pidfile --start --pidfile /var/run/activemq.pid --startas $ACTIVEMQ_HOME/bin/activemq-admin start ; then

start-stop-daemon is a nice simple utility used (at least) on Debian. The only reason it is nice and should exist is because it has the ability to change the user ID (UID) before launching the program. Shell scripts cannot be granted setuid powers because of potential security risks (at least in Linux), and so if you want to launch a shell script as another user you need another binary program to switch the uid. If the account has its shell set to /bin/false or similar in /etc/passwd (which is a good idea for any account that shouldn't ever be logged into interactively), you cannot use `su` for this purpose (unless I am mistaken). Thus, start-stop-daemon was born and changes the UID before launching the program. If $ACTIVEMQ_HOME/bin/activemq-admin is a binary file then you might be able to get away with setting it setuid activemq, but if it is an interpreted script then you're stuck. I have some (limited) experience with the necessity of start-stop-daemon on a Debian box (yuck), but I don't know of any alternatives for Slackware off-hand (though I'm sure some must exist, especially since the program required to change UID and spawn another process is exceedingly easy to write). If I remember I may search for a Slackware alternative or see how easy it is to setup start-stop-daemon on Slackware later (though I am forgetful).

A script like Woodsman's will be fine -- IF the process is meant to run as root, or if the binary you are starting changes its own UID (like mysql, I think, though I don't have the start scripts handy). However, for something like this, which is designed to be run as a non-root non-interactive user and does not change its own UID upon running, start-stop-daemon or something like it is a very good idea.

[edit]daemonize should also work, FYI -- but there is no SlackBuild or package for either that I know of, so you'll have to roll your own.[/edit]


All times are GMT -5. The time now is 08:03 AM.