forked from brianlmoon/GearmanManager
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to install as daemonized service for RHEL (Redhat, CentO…
…S) or Deb (Debian, Ubuntu) distros, including init scripts Note: incorporating new config changes from upstream/master
- Loading branch information
1 parent
52ec290
commit 4c39c6d
Showing
3 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/sh | ||
|
||
# Gearman worker manager | ||
|
||
### BEGIN INIT INFO | ||
# Provides: gearman-manager | ||
# Required-Start: $network $remote_fs $syslog | ||
# Required-Stop: $network $remote_fs $syslog | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Start daemon at boot time | ||
# Description: Enable gearman manager daemon | ||
### END INIT INFO | ||
|
||
DAEMON=/usr/local/bin/gearman-manager | ||
PIDFILE=/var/run/gearman-manager.pid | ||
LOGFILE=/var/log/gearman-manager.log | ||
CONFIGDIR=/etc/gearman-manager | ||
GEARMANUSER="gearman" | ||
PARAMS="-a -c ${CONFIGDIR}/config.ini -w ${CONFIGDIR}/workers" | ||
|
||
test -x ${DAEMON} || exit 0 | ||
|
||
. /lib/lsb/init-functions | ||
|
||
start() | ||
{ | ||
log_daemon_msg "Starting Gearman Manager" | ||
# TODO: instead of start-stop-daemon's --chuid, implement GearmanManager having a -u | ||
if start-stop-daemon \ | ||
--start \ | ||
--startas $DAEMON \ | ||
--pidfile $PIDFILE \ | ||
-- -P $PIDFILE \ | ||
-l $LOGFILE \ | ||
-d \ | ||
$PARAMS | ||
then | ||
log_end_msg 0 | ||
else | ||
log_end_msg 1 | ||
log_warning_msg "Please take a look at the syslog" | ||
exit 1 | ||
fi | ||
} | ||
|
||
stop() | ||
{ | ||
log_daemon_msg "Stopping Gearman Manager" | ||
if start-stop-daemon \ | ||
--stop \ | ||
--oknodo \ | ||
--retry 20 \ | ||
--pidfile $PIDFILE | ||
then | ||
log_end_msg 0 | ||
else | ||
log_end_msg 1 | ||
exit 1 | ||
fi | ||
} | ||
|
||
case "$1" in | ||
|
||
start) | ||
start | ||
;; | ||
|
||
stop) | ||
stop | ||
;; | ||
|
||
restart|force-reload) | ||
stop | ||
start | ||
;; | ||
|
||
status) | ||
status_of_proc -p $PIDFILE $DAEMON "Gearman Manager" | ||
;; | ||
|
||
*) | ||
echo "Usage: $0 {start|stop|restart|force-reload|status|help}" | ||
;; | ||
|
||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/sh | ||
|
||
# we're going to be mucking about, so we need to be root/sudo'd | ||
if [ "$(id -u)" != "0" ]; then | ||
echo "This script must be run as root" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# where are we now? | ||
WORKING_DIR=$(dirname $(readlink -f $0)) | ||
|
||
# determine if & which (supported) distro we're running | ||
if [ -f /etc/redhat-release ]; then | ||
DISTRO="rhel" | ||
elif [-f /etc/debian_version ]; then | ||
DISTRO="deb" | ||
else | ||
echo "Only Redhat Enterprise (RHEL) or Debian systems currently supported" | ||
exit 1 | ||
fi | ||
|
||
# create and populate installation folder | ||
mkdir -p /usr/local/share/gearman-manager | ||
cp -r ${WORKING_DIR}/../* /usr/local/share/gearman-manager/ | ||
|
||
# create config folders | ||
mkdir -p /etc/gearman-manager/workers | ||
touch /etc/gearman-manager/config.ini | ||
|
||
# symlink proper library wrapper into bin | ||
echo "Which PHP library to use, pecl/gearman or PEAR::Net_Gearman?" | ||
select PHPLIB in "pecl" "pear"; do | ||
ln -s /usr/local/share/gearman-manager/${PHPLIB}-manager.php /usr/local/bin/gearman-manager | ||
done | ||
|
||
# install init script | ||
cp ${WORKING_DIR}/${DISTRO}.sh /etc/init.d/gearman-manager | ||
chmod +x /etc/init.d/gearman-manager | ||
|
||
echo "Install ok! Worker scripts can be installed in /etc/gearman-manager/workers" | ||
echo "Run /etc/init.d/gearman-manager to start and stop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
|
||
# Gearman worker manager | ||
|
||
### BEGIN INIT INFO | ||
# Provides: gearman-manager | ||
# Required-Start: $network $remote_fs $syslog | ||
# Required-Stop: $network $remote_fs $syslog | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Start daemon at boot time | ||
# Description: Enable gearman manager daemon | ||
### END INIT INFO | ||
|
||
# Source function library. | ||
. /etc/rc.d/init.d/functions | ||
|
||
DAEMON=/usr/local/bin/gearman-manager | ||
PIDFILE=/var/run/gearman-manager.pid | ||
LOGFILE=/var/log/gearman-manager.log | ||
CONFIGDIR=/etc/gearman-manager | ||
GEARMANUSER="gearmand" | ||
PARAMS="-a -c ${CONFIGDIR}/config.ini -w ${CONFIGDIR}/workers" | ||
|
||
RETVAL=0 | ||
|
||
start() { | ||
echo -n $"Starting gearman-manager: " | ||
# TODO: implement GearmanManager having a -u to change user for child procs | ||
daemon --pidfile=$PIDFILE $DAEMON \ | ||
-P $PIDFILE \ | ||
-l $LOGFILE \ | ||
-d \ | ||
$PARAMS | ||
RETVAL=$? | ||
echo | ||
return $RETVAL | ||
} | ||
|
||
stop() { | ||
echo -n $"Stopping gearman-manager: " | ||
killproc -p $PIDFILE $DAEMON | ||
RETVAL=$? | ||
echo | ||
} | ||
|
||
# See how we were called. | ||
case "$1" in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
status) | ||
status -p $PIDFILE $DAEMON | ||
RETVAL=$? | ||
;; | ||
restart|reload) | ||
stop | ||
start | ||
;; | ||
condrestart|try-restart) | ||
if status -p $PIDFILE $DAEMON >&/dev/null; then | ||
stop | ||
start | ||
fi | ||
;; | ||
*) | ||
echo $"Usage: $prog {start|stop|restart|reload|condrestart|status|help}" | ||
RETVAL=3 | ||
esac | ||
|
||
exit $RETVAL |