SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
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
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.
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
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]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.