LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 06-24-2011, 09:04 AM   #1
qlands
Member
 
Registered: Sep 2010
Posts: 53

Rep: Reputation: 0
Question 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
 
Old 06-24-2011, 09:21 AM   #2
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Rep: Reputation: 115Reputation: 115
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.
 
Old 06-24-2011, 09:48 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,033

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
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.

Last edited by tronayne; 06-24-2011 at 09:50 AM.
 
1 members found this post helpful.
Old 06-24-2011, 10:28 AM   #4
qlands
Member
 
Registered: Sep 2010
Posts: 53

Original Poster
Rep: Reputation: 0
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.
Attached Files
File Type: txt activemq.txt (1.3 KB, 6 views)
 
Old 06-24-2011, 11:17 AM   #5
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 390

Rep: Reputation: 150Reputation: 150
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.
 
Old 06-24-2011, 03:21 PM   #6
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.0/14.1
Posts: 3,482

Rep: Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533
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.
 
Old 06-24-2011, 04:03 PM   #7
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,249

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
Quote:
Originally Posted by qlands View Post
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]

Last edited by T3slider; 06-24-2011 at 07:16 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Ubuntu start-stop-daemon problem CollieJim Linux - Software 1 06-14-2011 08:44 AM
new daemon - start and stop questions zoran119 Slackware 3 11-18-2008 05:39 AM
Using debian start-stop-daemon on Centos powadha Linux - Software 1 11-02-2008 05:59 AM
start-stop-daemon for linux eliufoo Linux - Software 1 02-07-2008 02:12 AM
Logging with Start stop daemon bigsness Linux - General 0 01-19-2005 03:25 PM


All times are GMT -5. The time now is 05:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration