I have a setup where the email sending service is queued to redis driver on my laravel application.
But I need to run the following code on my local host php artisan queue:work --daemon where the queue will be executed.
How can I run the daemon once I pushed my code into the server? I am currently using AWS Elastic Beanstalk
Thanks!!
Thanks #davidlee for posting comment of this question... :)
Finally I found a solution for running queue in elasticbeanstalk amazon. I'm using supervisord. I put the file on my laravel root as supervise.sh. Content of supervise.sh is like this :
#!/bin/bash
#
#
# Author: Günter Grodotzki (gunter#grodotzki.co.za)
# Version: 2015-04-25
#
# install supervisord
#
# See:
# - https://github.com/Supervisor/initscripts
# - http://supervisord.org/
if [ "${SUPERVISE}" == "enable" ]; then
export HOME="/root"
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin"
easy_install supervisor
cat <<'EOB' > /etc/init.d/supervisord
#!/bin/bash
#
# supervisord Startup script for the Supervisor process control system
#
# Author: Mike McGrath <mmcgrath#redhat.com> (based off yumupdatesd)
# Jason Koppe <jkoppe#indeed.com> adjusted to read sysconfig,
# use supervisord tools to start/stop, conditionally wait
# for child processes to shutdown, and startup later
# Erwan Queffelec <erwan.queffelec#gmail.com>
# make script LSB-compliant
#
# chkconfig: 345 83 04
# description: Supervisor is a client/server system that allows \
# its users to monitor and control a number of processes on \
# UNIX-like operating systems.
# processname: supervisord
# config: /etc/supervisord.conf
# config: /etc/sysconfig/supervisord
# pidfile: /var/run/supervisord.pid
#
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $all
# Required-Stop: $all
# Short-Description: start and stop Supervisor process control system
# Description: Supervisor is a client/server system that allows
# its users to monitor and control a number of processes on
# UNIX-like operating systems.
### END INIT INFO
# Source function library
. /etc/rc.d/init.d/functions
# Source system settings
if [ -f /etc/sysconfig/supervisord ]; then
. /etc/sysconfig/supervisord
fi
# Path to the supervisorctl script, server binary,
# and short-form for messages.
supervisorctl=${SUPERVISORCTL-/usr/bin/supervisorctl}
supervisord=${SUPERVISORD-/usr/bin/supervisord}
prog=supervisord
pidfile=${PIDFILE-/var/run/supervisord.pid}
lockfile=${LOCKFILE-/var/lock/subsys/supervisord}
STOP_TIMEOUT=${STOP_TIMEOUT-60}
OPTIONS="${OPTIONS--c /etc/supervisord.conf}"
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} $supervisord $OPTIONS
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
touch ${lockfile}
$supervisorctl $OPTIONS status
fi
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
LSB=1 killproc -p $pidfile $supervisord -HUP
RETVAL=$?
echo
if [ $RETVAL -eq 7 ]; then
failure $"$prog reload"
else
$supervisorctl $OPTIONS status
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $supervisord
RETVAL=$?
[ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status
;;
restart)
restart
;;
condrestart|try-restart)
if status -p ${pidfile} $supervisord >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}"
RETVAL=2
esac
exit $RETVAL
EOB
chmod +x /etc/init.d/supervisord
cat <<'EOB' > /etc/sysconfig/supervisord
# Configuration file for the supervisord service
#
# Author: Jason Koppe <jkoppe#indeed.com>
# orginal work
# Erwan Queffelec <erwan.queffelec#gmail.com>
# adjusted to new LSB-compliant init script
# make sure elasticbeanstalk PARAMS are being passed through to supervisord
. /opt/elasticbeanstalk/support/envvars
# WARNING: change these wisely! for instance, adding -d, --nodaemon
# here will lead to a very undesirable (blocking) behavior
#OPTIONS="-c /etc/supervisord.conf"
PIDFILE=/var/run/supervisord/supervisord.pid
#LOCKFILE=/var/lock/subsys/supervisord.pid
# Path to the supervisord binary
SUPERVISORD=/usr/local/bin/supervisord
# Path to the supervisorctl binary
SUPERVISORCTL=/usr/local/bin/supervisorctl
# How long should we wait before forcefully killing the supervisord process ?
#STOP_TIMEOUT=60
# Remove this if you manage number of open files in some other fashion
#ulimit -n 96000
EOB
mkdir -p /var/run/supervisord/
chown webapp: /var/run/supervisord/
cat <<'EOB' > /etc/supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock
chmod=0777
[supervisord]
logfile=/var/app/support/logs/supervisord.log
logfile_maxbytes=0
logfile_backups=0
loglevel=warn
pidfile=/var/run/supervisord/supervisord.pid
nodaemon=false
nocleanup=true
user=webapp
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[program:laravel_queue]
command=php artisan queue:listen
directory=/var/www/html
stdout_logfile=/var/www/html/storage/logs/laravel-queue.log
logfile_maxbytes=0
logfile_backups=0
redirect_stderr=true
autostart=true
autorestart=true
startretries=86400
EOB
# this is now a little tricky, not officially documented, so might break but it is the cleanest solution
# first before the "flip" is done (e.g. switch between ondeck vs current) lets stop supervisord
echo -e '#!/usr/bin/env bash\nservice supervisord stop' > /opt/elasticbeanstalk/hooks/appdeploy/enact/00_stop_supervisord.sh
chmod +x /opt/elasticbeanstalk/hooks/appdeploy/enact/00_stop_supervisord.sh
# then right after the webserver is reloaded, we can start supervisord again
echo -e '#!/usr/bin/env bash\nservice supervisord start' > /opt/elasticbeanstalk/hooks/appdeploy/enact/99_z_start_supervisord.sh
chmod +x /opt/elasticbeanstalk/hooks/appdeploy/enact/99_z_start_supervisord.sh
fi
Honestly... I don't really understand the meaning of above code ahaha... I just copied it from someone's blog... :D
And then we need to a new supervise.config inside .ebextensions folder like this:
packages:
yum:
python27-setuptools: []
files:
"/usr/bin/supervise.sh" :
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
#
# Author: Günter Grodotzki (gunter#grodotzki.co.za)
# Version: 2015-04-25
#
# install supervisord
#
# See:
# - https://github.com/Supervisor/initscripts
# - http://supervisord.org/
if [ "${SUPERVISE}" == "enable" ]; then
export HOME="/root"
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin"
easy_install supervisor
cat <<'EOB' > /etc/init.d/supervisord
#!/bin/bash
#
# supervisord Startup script for the Supervisor process control system
#
# Author: Mike McGrath <mmcgrath#redhat.com> (based off yumupdatesd)
# Jason Koppe <jkoppe#indeed.com> adjusted to read sysconfig,
# use supervisord tools to start/stop, conditionally wait
# for child processes to shutdown, and startup later
# Erwan Queffelec <erwan.queffelec#gmail.com>
# make script LSB-compliant
#
# chkconfig: 345 83 04
# description: Supervisor is a client/server system that allows \
# its users to monitor and control a number of processes on \
# UNIX-like operating systems.
# processname: supervisord
# config: /etc/supervisord.conf
# config: /etc/sysconfig/supervisord
# pidfile: /var/run/supervisord.pid
#
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $all
# Required-Stop: $all
# Short-Description: start and stop Supervisor process control system
# Description: Supervisor is a client/server system that allows
# its users to monitor and control a number of processes on
# UNIX-like operating systems.
### END INIT INFO
# Source function library
. /etc/rc.d/init.d/functions
# Source system settings
if [ -f /etc/sysconfig/supervisord ]; then
. /etc/sysconfig/supervisord
fi
# Path to the supervisorctl script, server binary,
# and short-form for messages.
supervisorctl=${SUPERVISORCTL-/usr/bin/supervisorctl}
supervisord=${SUPERVISORD-/usr/bin/supervisord}
prog=supervisord
pidfile=${PIDFILE-/var/run/supervisord.pid}
lockfile=${LOCKFILE-/var/lock/subsys/supervisord}
STOP_TIMEOUT=${STOP_TIMEOUT-60}
OPTIONS="${OPTIONS--c /etc/supervisord.conf}"
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} $supervisord $OPTIONS
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
touch ${lockfile}
$supervisorctl $OPTIONS status
fi
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
LSB=1 killproc -p $pidfile $supervisord -HUP
RETVAL=$?
echo
if [ $RETVAL -eq 7 ]; then
failure $"$prog reload"
else
$supervisorctl $OPTIONS status
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $supervisord
RETVAL=$?
[ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status
;;
restart)
restart
;;
condrestart|try-restart)
if status -p ${pidfile} $supervisord >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}"
RETVAL=2
esac
exit $RETVAL
EOB
chmod +x /etc/init.d/supervisord
cat <<'EOB' > /etc/sysconfig/supervisord
# Configuration file for the supervisord service
#
# Author: Jason Koppe <jkoppe#indeed.com>
# orginal work
# Erwan Queffelec <erwan.queffelec#gmail.com>
# adjusted to new LSB-compliant init script
# make sure elasticbeanstalk PARAMS are being passed through to supervisord
. /opt/elasticbeanstalk/support/envvars
# WARNING: change these wisely! for instance, adding -d, --nodaemon
# here will lead to a very undesirable (blocking) behavior
#OPTIONS="-c /etc/supervisord.conf"
PIDFILE=/var/run/supervisord/supervisord.pid
#LOCKFILE=/var/lock/subsys/supervisord.pid
# Path to the supervisord binary
SUPERVISORD=/usr/local/bin/supervisord
# Path to the supervisorctl binary
SUPERVISORCTL=/usr/local/bin/supervisorctl
# How long should we wait before forcefully killing the supervisord process ?
#STOP_TIMEOUT=60
# Remove this if you manage number of open files in some other fashion
#ulimit -n 96000
EOB
mkdir -p /var/run/supervisord/
chown webapp: /var/run/supervisord/
cat <<'EOB' > /etc/supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock
chmod=0777
[supervisord]
logfile=/var/app/support/logs/supervisord.log
logfile_maxbytes=0
logfile_backups=0
loglevel=warn
pidfile=/var/run/supervisord/supervisord.pid
nodaemon=false
nocleanup=true
user=webapp
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[program:laravel_queue_general]
command=php /var/www/html/artisan queue:listen --timeout=600
directory=/var/www/html
stdout_logfile=/var/www/html/storage/logs/laravel-queue.log
logfile_maxbytes=0
logfile_backups=0
redirect_stderr=true
autostart=true
autorestart=true
startretries=86400
process_name=%(program_name)s_%(process_num)02d
numprocs=2
[program:laravel_queue_data]
command=php /var/www/html/artisan queue:listen --timeout=600 --queue=https://sqs.ap-southeast-1.amazonaws.com/333973004348/data-processing-queue
directory=/var/www/html
stdout_logfile=/var/www/html/storage/logs/laravel-queue.log
logfile_maxbytes=0
logfile_backups=0
redirect_stderr=true
autostart=true
autorestart=true
startretries=86400
process_name=%(program_name)s_%(process_num)02d
numprocs=30
[program:laravel_queue_notif]
command=php /var/www/html/artisan queue:listen --timeout=600 --queue=https://sqs.ap-southeast-1.amazonaws.com/333973004348/notifications-queue
directory=/var/www/html
stdout_logfile=/var/www/html/storage/logs/laravel-queue.log
logfile_maxbytes=0
logfile_backups=0
redirect_stderr=true
autostart=true
autorestart=true
startretries=86400
process_name=%(program_name)s_%(process_num)02d
numprocs=2
EOB
# this is now a little tricky, not officially documented, so might break but it is the cleanest solution
# first before the "flip" is done (e.g. switch between ondeck vs current) lets stop supervisord
echo -e '#!/usr/bin/env bash\nservice supervisord stop' > /opt/elasticbeanstalk/hooks/appdeploy/enact/00_stop_supervisord.sh
chmod +x /opt/elasticbeanstalk/hooks/appdeploy/enact/00_stop_supervisord.sh
# then right after the webserver is reloaded, we can start supervisord again
echo -e '#!/usr/bin/env bash\nservice supervisord start' > /opt/elasticbeanstalk/hooks/appdeploy/enact/99_z_start_supervisord.sh
chmod +x /opt/elasticbeanstalk/hooks/appdeploy/enact/99_z_start_supervisord.sh
fi
Sometime's the queue failed to start. So we need to run it manually by login to ec2 instance of amazon using putty or mobaextrem (this is my favorite ssh terminal). And then after login, we just need to execute this command :
sudo -i
cd /usr/bin
./supervise.sh
/opt/elasticbeanstalk/hooks/appdeploy/enact/99_z_start_supervisord.sh
./99_z_start_supervisord.sh
yaaapsss... that's all... :)
Note :
for checking whether the queue is running or not, we can use these :
ps ax|grep supervise
ps aux|grep sord
Related
So i am trying to use monit to monitor my delayed_job processes. And to do that, i have written this
/home/deploy/sites/app.project.com.my/shared/delayed_job.monitrc
check process delayed_job_0
with pidfile /home/deploy/sites/app.project.com.my/shared/pids/delayed_job.0.pid
start program = "/home/deploy/sites/app.project.com.my/shared/delayed_job.sh start staging 0"
as uid deploy and gid deploy
stop program = "/bin/su - deploy -c '/home/deploy/sites/app.project.com.my/current/bin/delayed_job stop staging 0'"
group delayed_job
I have also written this script
/home/deploy/sites/app.project.com.my/shared/delayed_job.sh
#!/bin/bash
APP_NAME=app.project.com.my
APP_DIR=/home/deploy/sites
RAILS_ROOT=$APP_DIR/$APP_NAME/current
LOG_FILE=$APP_DIR/$APP_NAME/shared/delayed_job_monit.log
exec 2>&1
if [ "$3" ]; then
RUNNER="$3"
else
RUNNER=0
fi
echo "Runner: $RUNNER"
ENVIRONMENT=$2
echo "Env: $ENVIRONMENT"
PID_FILE=$RAILS_ROOT/tmp/pids/delayed_job.$RUNNER.pid
echo "Pid: $PID_FILE"
cd $RAILS_ROOT
echo "Received $1"
function stop {
cd $RAILS_ROOT
RAILS_ENV=$ENVIRONMENT /usr/bin/env bin/delayed_job stop -i $RUNNER
}
function start {
if [ -f $PID_FILE ]; then
echo "Pid Found. Deleting PID FILE: $PID_FILE"
rm -f $PID_FILE
fi
CMD=" /usr/bin/env RAILS_ENV=$ENVIRONMENT bin/delayed_job start -i $RUNNER"
cd $RAILS_ROOT
exec $CMD
}
case $1 in
start)
stop
start
;;
stop)
stop
;;
*)
echo "WTF"
;;
esac
Now when in this folder /home/deploy/sites/app.project.com.my/shared/, if i run the delayed_job.sh script like this ./delayed_job start staging 0. it works properly and the delayed_job is restarted.
But when i run the monit script sudo monit start delayed_job_0, i get an error /usr/lib/ruby/2.3.0/rubygems/core_ext/kern
Currently not sure how to get rid of this error.
Does somebody how to change the max-job size of beanstalkd ?
I have the problem that I get the message JOB_TOO_BIG and at Adding Job to beanstalkd, it says that the default size is 65k.
Does somebody know how to change that ?
EDIT:
my beanstalkd init-script in the folder /etc/init.d looks like the following (I added the -z option to increase the job size):
#!/bin/sh
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs#debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# the Debian operating system, in /usr/share/common-licenses/GPL; if
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
### BEGIN INIT INFO
# Provides: beanstalkd
# Required-Start: $remote_fs $network $local_fs
# Required-Stop: $remote_fs $network $local_fs
# Should-Start: $named
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: in-memory workqueue service
# Description: beanstalk is a simple, fast, queueing server. Its
# interface is generic, but was originally designed
# for reducing the latency of page views in high-volume
# web applications by running time-consuming tasks
# asynchronously.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/beanstalkd # Introduce the server's location here
NAME=beanstalkd # Introduce the short server's name here
DESC="in-memory queueing server" # Introduce a short description here
LOGDIR=/var/log/beanstalkd # Log directory to use
BEANSTALKD_LISTEN_ADDR=0.0.0.0
BEANSTALKD_LISTEN_PORT=11300
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
# Default options, these can be overriden by the information
# at /etc/default/$NAME
DAEMON_OPTS="-l $BEANSTALKD_LISTEN_ADDR -p $BEANSTALKD_LISTEN_PORT -z 550000000000" # Additional options given to the server
#DIETIME=10 # Time to wait for the server to die, in seconds
# If this value is set too low you might not
# let some servers to die gracefully and
# 'restart' will not work
STARTTIME=1 # Time to wait for the server to start, in seconds
# If this value is set each time the server is
# started (on start or restart) the script will
# stall to try to determine if it is running
# If it is not set and the server takes time
# to setup a pid file the log message might
# be a false positive (says it did not start
# when it actually did)
#LOGFILE=$LOGDIR/$NAME.log # Server logfile
DAEMONUSER=root #beanstalkd # Users to run the daemons as. If this value
# is set start-stop-daemon will chuid the server
# Include defaults if available
if [ -f /etc/default/$NAME ] ; then
. /etc/default/$NAME
fi
# Check that the user exists (if we set a user)
# Does the user exist?
if [ -n "$DAEMONUSER" ] ; then
if getent passwd | grep -q "^$DAEMONUSER:"; then
# Obtain the uid and gid
DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
else
log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
exit 0
fi
fi
set -e
running_pid() {
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
# Is this the expected server
[ "$cmd" != "$name" ] && return 1
return 0
}
running() {
# Check if the process is running looking at /proc
# (works for all users)
# No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
pid=`cat $PIDFILE`
running_pid $pid $DAEMON || return 1
return 0
}
start_server() {
# Start the process using the wrapper
if [ "x$START" != "xyes" -a "x$START" != "xtrue" ]; then
echo ""
echo "beanstalkd not configured to start, please edit /etc/default/beanstalkd to enable"
exit 0
fi
if [ -z "$DAEMONUSER" ] ; then
start_daemon -p $PIDFILE $DAEMON $DAEMON_OPTS
errcode=$?
else
# if we are using a daemonuser then change the user id
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--chuid $DAEMONUSER --make-pidfile --oknodo \
--background --exec $DAEMON -- $DAEMON_OPTS
errcode=$?
fi
return $errcode
}
stop_server() {
# Stop the process using the wrapper
if [ -z "$DAEMONUSER" ] ; then
killproc -p $PIDFILE $DAEMON
errcode=$?
else
# if we are using a daemonuser then look for process that match
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--user $DAEMONUSER \
--exec $DAEMON
errcode=$?
fi
rm -f $PIDFILE
return $errcode
}
reload_server() {
[ ! -f "$PIDFILE" ] && return 1
pid=pidofproc $PIDFILE # This is the daemon's pid
# Send a SIGHUP
kill -1 $pid
return $?
}
force_stop() {
# Force the process to die killing it manually
[ ! -e "$PIDFILE" ] && return
if running ; then
kill -15 $pid
# Is it really dead?
sleep "$DIETIME"s
if running ; then
kill -9 $pid
sleep "$DIETIME"s
if running ; then
echo "Cannot kill $NAME (pid=$pid)!"
exit 0
fi
fi
fi
rm -f $PIDFILE
}
case "$1" in
start)
log_daemon_msg "Starting $DESC " "$NAME"
# Check if it's running first
if running ; then
log_progress_msg "apparently already running"
log_end_msg 0
exit 0
fi
if start_server ; then
# NOTE: Some servers might die some time after they start,
# this code will detect this issue if STARTTIME is set
# to a reasonable value
[ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
if running ; then
# It's ok, the server started and is running
log_end_msg 0
else
# It is not running after we did start
log_end_msg 1
fi
else
# Either we could not start it
log_end_msg 1
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
if running ; then
# Only stop the server if we see it running
errcode=0
stop_server || errcode=$?
log_end_msg $errcode
else
# If it's not running don't do anything
log_progress_msg "apparently not running"
log_end_msg 0
exit 0
fi
;;
force-stop)
# First try to stop gracefully the program
$0 stop
if running; then
# If it's still running try to kill it more forcefully
log_daemon_msg "Stopping (force) $DESC" "$NAME"
errcode=0
force_stop || errcode=$?
log_end_msg $errcode
fi
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
errcode=0
stop_server || errcode=$?
# Wait some sensible amount, some server need this
[ -n "$DIETIME" ] && sleep $DIETIME
start_server || errcode=$?
[ -n "$STARTTIME" ] && sleep $STARTTIME
running || errcode=$?
log_end_msg $errcode
;;
status)
log_daemon_msg "Checking status of $DESC" "$NAME"
if running ; then
log_progress_msg "running"
log_end_msg 0
else
log_progress_msg "apparently not running ... "
log_end_msg 1
exit 0
fi
;;
reload)
log_warning_msg "Reloading $NAME daemon: not implemented (use restart)."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
And my beanstalkd.conf file which is in the folder /etc/default looks like the following:
## Defaults for the beanstalkd init script, /etc/init.d/beanstalkd on
## Debian systems. Append "-b /var/lib/beanstalkd" for persistent
## storage.
BEANSTALKD_LISTEN_ADDR=0.0.0.0
BEANSTALKD_LISTEN_PORT=11300
# create the journal path before use !!!
BEANSTALKD_JOURNAL_PATH="/var/lib/beanstalkd"
DAEMON_OPTS="-l $BEANSTALKD_LISTEN_ADDR -p $BEANSTALKD_LISTEN_PORT -z 550000000000 -b $BEANSTALKD_JOURNAL_PATH -V"
## Uncomment to enable startup during boot.
START=yes
best regards,
The answer by slickorange in the following link might help you:
JOB_TOO_BIG Pheanstalk - what can be done?
The size of beanstalkd job can be increased by adding the following line (or uncomment the existing BEANSTALKD_EXTRA line and edit it):
BEANSTALKD_EXTRA="-z 524280"
The size is specified in bytes, default size being 65535 bytes.
Restart beanstalkd after making the change:
sudo service beanstalkd restart
On Debian 8.7 x64 editing the settings in /etc/default/beanstalkd works. A bug probably.
I have systemctl in Debian 8 and my config looks slightly different from what is suggested here in other answers to increase the limit. This is what I did:
Edit the beanstalkd file in:
nano /etc/sysconfig/beanstalkd
Then increase the limit for MAX_JOB_SIZE from default 65535 to 524280
MAX_JOB_SIZE=-z 524280
Restart beanstalkd and check the status:
service beanstalkd restart
systemctl status beanstalkd
There are settings for the daemon
-b DIR wal directory
-f MS fsync at most once every MS milliseconds (use -f0 for "always fsync")
-F never fsync (default)
-l ADDR listen on address (default is 0.0.0.0)
-p PORT listen on port (default is 11300)
-u USER become user and group
-z BYTES set the maximum job size in bytes (default is 65535)
-s BYTES set the size of each wal file (default is 10485760)
(will be rounded up to a multiple of 512 bytes)
-c compact the binlog (default)
-n do not compact the binlog
-v show version information
-V increase verbosity
-h show this help
So based on your Linux, you should find out where this is kept and change it. Usually it's under beanstalkd.conf
I use God to watch over my Ruby APIs and services. I have created Init scripts to start up these services when the server boots. Doing this has led me to a couple of questions.
Firstly I have to have the scripts running as root? I found that as it loads with init.d scripts that the processes will then be managed by root - requiring Sudo for any changes.
Secondly, I have created RVM wrappers for some of the main processes (such as thin) which work brilliantly. But have found that some of the gems I use such as the Mongo gem will not get loaded from the context of the bundler (I assume that this is due to how the script is loaded and that it is loaded as root?) So I am forced to do a Gem install Mongo (and bson)
Is there a way to get init.d loaded scripts to load in the context of the bundler?
I might be doing this completely wrong as I am still fairly new to Ruby deployment and Linux configurations.
Here is an example of my god script:
require 'yaml'
config_path = '/opt/broker/current/config/api_config.yml'
config = YAML.load_file config_path
God.watch do |w|
w.name = 'Broker_API'
pid_file = config[:pid_file_path]
w.pid_file = pid_file
w.behavior :clean_pid_file
w.dir = config[:deployed_current_path]
w.env = config[:deployed_current_path]
port = config[:api_port]
server_logs = config[:api_logs]
config_ru = config[:api_config_file]
w.start = 'bundle exec thin -l %s -P %s -d -D -R %s -p %s --threaded start' %[server_logs, pid_file, config_ru, port]
w.stop = 'bundle exec thin -l %s -P %s -d -D -R %s -p %s --threaded stop' %[server_logs, pid_file, config_ru, port]
w.restart = 'bundle exec thin -l %s -P %s -d -D -R %s -p %s --threaded restart' %[server_logs, pid_file, config_ru, port]
w.log = config[:api_god_log]
w.keepalive
end
and my init script:
#!/bin/sh
### BEGIN INIT INFO
# Provides: god
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: God
### END INIT INFO
NAME=god
DESC=god
GOD_BIN=/home/username/.rvm/wrappers/Godrunner/god
GOD_CONFIG=/etc/god/god.conf
GOD_LOG=/var/log/god.log
GOD_PID=/var/run/god.pid
set -e
RETVAL=0
case "$1" in
start)
echo -n "Starting $DESC: "
$GOD_BIN load -c $GOD_CONFIG
exit 0
fi
RETVAL=0
case "$1" in
start)
echo -n "Starting $DESC: "
$GOD_BIN load -c $GOD_CONFIG
RETVAL=$?
echo "$NAME."
;;
status)
$GOD_BIN status
RETVAL=$?
;;
*)
echo "Usage: god {start|status}"
exit 1
;;
esac
exit $RETVAL
I have solved it this way:
daemon --user $USER "$GOD_BIN \
-c $CONFIG_FILE \
-l $LOG_FILE \
--log-level $LOG_LEVEL \
-P $PID_FILE >/dev/null"
This is the part which should replace your $GOD_BIN load -c $GOD_CONFIG. And now God runs as $USER.
Now if you want it to know where your ruby and gems are you will have to provide it with this information. I am doing
source /etc/profile.d/ruby.sh
somewhere in the beginning of the script.
ruby.sh contents:
export PATH=/opt/ruby-2.1/bin/:$PATH
export GEM_PATH=/opt/ruby-2.1/lib64/ruby/gems/2.1.0
i was written bash script which will start slave.jar process and vm will appear in jenkins. I have to start this script as service when linux boot up. I place my file in etc/init.d, with chmod +x and after that make chckconfig on it and all links are appears in rc.d folders, output of chkconfig shows:
jenkins-slave 0:off 1:off 2:on 3:on 4:on 5:on 6:off
When i make reboot nothing happend, when i run via sudo service jenkins-slave start everything is ok. All propertis contains in another file, everything is working when make it by hands in open session. How to make it auto executable when CentOs 6 up?
my script:
#!/bin/sh
#
# jenkins-slave: Launch a Jenkins BuildSlave instance on this node
#
# chkconfig: - 99 01
# description: Enable this node to fulfill build jobs
#
# Source function library.
. /etc/rc.d/init.d/functions
[ -f /etc/sysconfig/jenkins-slave ] && . /etc/sysconfig/jenkins-slave
[ -n "$JENKINS_URL" ] || exit 0
[ -n "$JENKINS_WORKDIR" ] || exit 0
[ -n "$JENKINS_USER" ] || exit 0
[ -n "$JENKINS_NODENAME" ] || exit 0
[ -x /usr/bin/java ] || exit 0
download_jar()
{
curl -s -o slave.jar $JENKINS_URL/jnlpJars/slave.jar || exit 0
}
start()
{
cd $JENKINS_WORKDIR
[ -f slave.jar ] || download_jar
echo -n $"Starting Jenkins BuildSlave: "
su - $JENKINS_USER sh -c "\
java -jar slave.jar \
-jnlpUrl $JENKINS_URL/computer/$JENKINS_NODENAME/slave-agent.jnlp \
>slave.log 2>&1 &"
echo Done.
}
stop()
{
echo -n $"Shutting down Jenkins BuildSlave: "
killproc slave.jar
echo Done.
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
status)
status java
;;
*)
echo $"Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
I'm trying to run this dropbox script on my nginx server , but im getting:
Syntax error: word unexpected (expecting "do")
I copy pasted the script for a website, and I tried removing special characters, but im still getting the same error.
script:
#!/bin/sh
# /etc/init.d/dropbox
### BEGIN INIT INFO
# Provides: dropbox
# Required-Start: $network $syslog $remote_fs
# Required-Stop: $network $syslog $remote_fs
# Should-Start: $named $time
# Should-Stop: $named $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the dropbox daemon for debian/ubuntu
# Description: Dropbox daemon for linux
### END INIT INFO
DROPBOX_USERS="root"
start() {
echo "Starting dropbox..."
for dbuser in $DROPBOX_USERS; do
start-stop-daemon -b -o -c $dbuser -S -x /home/$dbuser/.dropbox-dist/dropboxd
done
}
stop() {
echo "Stopping dropbox..."
for dbuser in $DROPBOX_USERS; do
start-stop-daemon -o -c $dbuser -K -x /home/$dbuser/.dropbox-dist/dropboxd
done
}
status() {
for dbuser in $DROPBOX_USERS; do
dbpid=`pgrep -u $dbuser dropbox`
if [ -z $dbpid ] ; then
echo "dropboxd for USER $dbuser: not running."
else
echo "dropboxd for USER $dbuser: running."
fi
done
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
stop
start
;;
status)
status
;;
*)
echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
exit 1
esac
exit 0
Probably you managed to insert windows line endings when you copy and pasted. If you have dos2unix, use it. (dos2unix scriptfile) Otherwise, there are a number of similar utilities.
Why do you have
/home/$dbuser/.dropbox-dist/dropboxd
or replacing variables.
/home/root/.dropbox-dist/dropboxd
Shouldn't it be
/root/.dropbox-dist/dropboxd
eg
/$dbuser/.dropbox-dist/dropboxd
Are you seriously allowing dropboxes in /root ?
Also why a for dbuser in DROPBOX_USERS; do reassign? rather than
dbuser=$DROPBOX_USERS