How to run multiple sidekiq workers using init.d
I'm using Amazon Linux 1. I have 2 apps in the same EC2 server. 1 is rails 3 and the other is a rails 5. I'm trying run sidekiq from both apps using init.d but only one of them runs.
Below is a sample of my script in /etc/init.d/sidekiq_myapp. I just changed the APP_DIR of the other script and used different names for sidekiq (-q parameter):
#!/bin/sh
### BEGIN INIT INFO
# Provides: sidekiq
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts and stops sidekiq
# Description: starts and stops sidekiq
### END INIT INFO
# You will need to modify these
APP="myapp"
AS_USER="root"
APP_DIR="/var/www/myapp"
APP_CONFIG="${APP_DIR}/config"
LOG_FILE="/opt/nginx/logs/error.log"
LOCK_FILE="$APP_DIR/tmp/${APP}-sidekiq-lock"
PID_FILE="$APP_DIR/tmp/pids/sidekiq.pid"
GEMFILE="$APP_DIR/Gemfile"
SIDEKIQ="sidekiq"
APP_ENV="production"
BUNDLE="bundle"
START_CMD="$BUNDLE exec $SIDEKIQ -q critical,5 -q default,2 -q low -d -L $LOG_FILE -e $APP_ENV -P $PID_FILE"
CMD="cd ${APP_DIR}; ${START_CMD} >> ${LOG_FILE} 2>&1 &"
RETVAL=0
start() {
status
if [ $? -eq 1 ]; then
[ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5)
[ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6)
cd $APP_DIR
echo "Starting $SIDEKIQ message processor .. "
su -c "$CMD" - $AS_USER
RETVAL=$?
#Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
sleep 8
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
else
echo "$SIDEKIQ message processor is already running .. "
fi
}
stop() {
status
if [ $? -eq 0 ]; then
echo "Stopping sidekiq message processor .."
SIG="INT"
kill -$SIG `cat $PID_FILE`
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
return $RETVAL
else
echo "Sidekiq message processor is stopped already .."
fi
}
status() {
ps -ef | grep 'sidekiq [0-9]*.[0-9]*.[0-9]*' | grep -v grep
return $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
if [ $? -eq 0 ]; then
echo "$SIDEKIQ message processor is running .."
RETVAL=0
else
echo "$SIDEKIQ message processor is stopped .."
RETVAL=1
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 0
;;
esac
exit $RETVAL
I can verify that the one from rails 3 is running. The one from rails 5 does not. I still have to manually run bundle exec sidekiq on the rails 5 for it to work.
# ps -ef | grep sidekiq
2672 1 1 13:37 ? 00:00:09 sidekiq 3.3.0 squadzip [0 of 25 busy]
7048 6954 0 13:51 pts/1 00:00:00 grep --color=auto sidekiq
I'd like to stick with systemV. Any thoughts? Both will run if I'll manually run the bundle exec sidekiq, that means that my rails/sidekiq setup is fine. My problem is how to start them both.
ruby-on-rails bash sidekiq init.d
add a comment |
I'm using Amazon Linux 1. I have 2 apps in the same EC2 server. 1 is rails 3 and the other is a rails 5. I'm trying run sidekiq from both apps using init.d but only one of them runs.
Below is a sample of my script in /etc/init.d/sidekiq_myapp. I just changed the APP_DIR of the other script and used different names for sidekiq (-q parameter):
#!/bin/sh
### BEGIN INIT INFO
# Provides: sidekiq
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts and stops sidekiq
# Description: starts and stops sidekiq
### END INIT INFO
# You will need to modify these
APP="myapp"
AS_USER="root"
APP_DIR="/var/www/myapp"
APP_CONFIG="${APP_DIR}/config"
LOG_FILE="/opt/nginx/logs/error.log"
LOCK_FILE="$APP_DIR/tmp/${APP}-sidekiq-lock"
PID_FILE="$APP_DIR/tmp/pids/sidekiq.pid"
GEMFILE="$APP_DIR/Gemfile"
SIDEKIQ="sidekiq"
APP_ENV="production"
BUNDLE="bundle"
START_CMD="$BUNDLE exec $SIDEKIQ -q critical,5 -q default,2 -q low -d -L $LOG_FILE -e $APP_ENV -P $PID_FILE"
CMD="cd ${APP_DIR}; ${START_CMD} >> ${LOG_FILE} 2>&1 &"
RETVAL=0
start() {
status
if [ $? -eq 1 ]; then
[ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5)
[ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6)
cd $APP_DIR
echo "Starting $SIDEKIQ message processor .. "
su -c "$CMD" - $AS_USER
RETVAL=$?
#Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
sleep 8
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
else
echo "$SIDEKIQ message processor is already running .. "
fi
}
stop() {
status
if [ $? -eq 0 ]; then
echo "Stopping sidekiq message processor .."
SIG="INT"
kill -$SIG `cat $PID_FILE`
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
return $RETVAL
else
echo "Sidekiq message processor is stopped already .."
fi
}
status() {
ps -ef | grep 'sidekiq [0-9]*.[0-9]*.[0-9]*' | grep -v grep
return $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
if [ $? -eq 0 ]; then
echo "$SIDEKIQ message processor is running .."
RETVAL=0
else
echo "$SIDEKIQ message processor is stopped .."
RETVAL=1
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 0
;;
esac
exit $RETVAL
I can verify that the one from rails 3 is running. The one from rails 5 does not. I still have to manually run bundle exec sidekiq on the rails 5 for it to work.
# ps -ef | grep sidekiq
2672 1 1 13:37 ? 00:00:09 sidekiq 3.3.0 squadzip [0 of 25 busy]
7048 6954 0 13:51 pts/1 00:00:00 grep --color=auto sidekiq
I'd like to stick with systemV. Any thoughts? Both will run if I'll manually run the bundle exec sidekiq, that means that my rails/sidekiq setup is fine. My problem is how to start them both.
ruby-on-rails bash sidekiq init.d
add a comment |
I'm using Amazon Linux 1. I have 2 apps in the same EC2 server. 1 is rails 3 and the other is a rails 5. I'm trying run sidekiq from both apps using init.d but only one of them runs.
Below is a sample of my script in /etc/init.d/sidekiq_myapp. I just changed the APP_DIR of the other script and used different names for sidekiq (-q parameter):
#!/bin/sh
### BEGIN INIT INFO
# Provides: sidekiq
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts and stops sidekiq
# Description: starts and stops sidekiq
### END INIT INFO
# You will need to modify these
APP="myapp"
AS_USER="root"
APP_DIR="/var/www/myapp"
APP_CONFIG="${APP_DIR}/config"
LOG_FILE="/opt/nginx/logs/error.log"
LOCK_FILE="$APP_DIR/tmp/${APP}-sidekiq-lock"
PID_FILE="$APP_DIR/tmp/pids/sidekiq.pid"
GEMFILE="$APP_DIR/Gemfile"
SIDEKIQ="sidekiq"
APP_ENV="production"
BUNDLE="bundle"
START_CMD="$BUNDLE exec $SIDEKIQ -q critical,5 -q default,2 -q low -d -L $LOG_FILE -e $APP_ENV -P $PID_FILE"
CMD="cd ${APP_DIR}; ${START_CMD} >> ${LOG_FILE} 2>&1 &"
RETVAL=0
start() {
status
if [ $? -eq 1 ]; then
[ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5)
[ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6)
cd $APP_DIR
echo "Starting $SIDEKIQ message processor .. "
su -c "$CMD" - $AS_USER
RETVAL=$?
#Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
sleep 8
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
else
echo "$SIDEKIQ message processor is already running .. "
fi
}
stop() {
status
if [ $? -eq 0 ]; then
echo "Stopping sidekiq message processor .."
SIG="INT"
kill -$SIG `cat $PID_FILE`
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
return $RETVAL
else
echo "Sidekiq message processor is stopped already .."
fi
}
status() {
ps -ef | grep 'sidekiq [0-9]*.[0-9]*.[0-9]*' | grep -v grep
return $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
if [ $? -eq 0 ]; then
echo "$SIDEKIQ message processor is running .."
RETVAL=0
else
echo "$SIDEKIQ message processor is stopped .."
RETVAL=1
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 0
;;
esac
exit $RETVAL
I can verify that the one from rails 3 is running. The one from rails 5 does not. I still have to manually run bundle exec sidekiq on the rails 5 for it to work.
# ps -ef | grep sidekiq
2672 1 1 13:37 ? 00:00:09 sidekiq 3.3.0 squadzip [0 of 25 busy]
7048 6954 0 13:51 pts/1 00:00:00 grep --color=auto sidekiq
I'd like to stick with systemV. Any thoughts? Both will run if I'll manually run the bundle exec sidekiq, that means that my rails/sidekiq setup is fine. My problem is how to start them both.
ruby-on-rails bash sidekiq init.d
I'm using Amazon Linux 1. I have 2 apps in the same EC2 server. 1 is rails 3 and the other is a rails 5. I'm trying run sidekiq from both apps using init.d but only one of them runs.
Below is a sample of my script in /etc/init.d/sidekiq_myapp. I just changed the APP_DIR of the other script and used different names for sidekiq (-q parameter):
#!/bin/sh
### BEGIN INIT INFO
# Provides: sidekiq
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts and stops sidekiq
# Description: starts and stops sidekiq
### END INIT INFO
# You will need to modify these
APP="myapp"
AS_USER="root"
APP_DIR="/var/www/myapp"
APP_CONFIG="${APP_DIR}/config"
LOG_FILE="/opt/nginx/logs/error.log"
LOCK_FILE="$APP_DIR/tmp/${APP}-sidekiq-lock"
PID_FILE="$APP_DIR/tmp/pids/sidekiq.pid"
GEMFILE="$APP_DIR/Gemfile"
SIDEKIQ="sidekiq"
APP_ENV="production"
BUNDLE="bundle"
START_CMD="$BUNDLE exec $SIDEKIQ -q critical,5 -q default,2 -q low -d -L $LOG_FILE -e $APP_ENV -P $PID_FILE"
CMD="cd ${APP_DIR}; ${START_CMD} >> ${LOG_FILE} 2>&1 &"
RETVAL=0
start() {
status
if [ $? -eq 1 ]; then
[ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5)
[ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6)
cd $APP_DIR
echo "Starting $SIDEKIQ message processor .. "
su -c "$CMD" - $AS_USER
RETVAL=$?
#Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
sleep 8
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
else
echo "$SIDEKIQ message processor is already running .. "
fi
}
stop() {
status
if [ $? -eq 0 ]; then
echo "Stopping sidekiq message processor .."
SIG="INT"
kill -$SIG `cat $PID_FILE`
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
return $RETVAL
else
echo "Sidekiq message processor is stopped already .."
fi
}
status() {
ps -ef | grep 'sidekiq [0-9]*.[0-9]*.[0-9]*' | grep -v grep
return $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
if [ $? -eq 0 ]; then
echo "$SIDEKIQ message processor is running .."
RETVAL=0
else
echo "$SIDEKIQ message processor is stopped .."
RETVAL=1
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 0
;;
esac
exit $RETVAL
I can verify that the one from rails 3 is running. The one from rails 5 does not. I still have to manually run bundle exec sidekiq on the rails 5 for it to work.
# ps -ef | grep sidekiq
2672 1 1 13:37 ? 00:00:09 sidekiq 3.3.0 squadzip [0 of 25 busy]
7048 6954 0 13:51 pts/1 00:00:00 grep --color=auto sidekiq
I'd like to stick with systemV. Any thoughts? Both will run if I'll manually run the bundle exec sidekiq, that means that my rails/sidekiq setup is fine. My problem is how to start them both.
ruby-on-rails bash sidekiq init.d
ruby-on-rails bash sidekiq init.d
edited Nov 20 '18 at 14:07
tungsten_carbide
asked Nov 20 '18 at 14:00
tungsten_carbidetungsten_carbide
315312
315312
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394667%2fhow-to-run-multiple-sidekiq-workers-using-init-d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394667%2fhow-to-run-multiple-sidekiq-workers-using-init-d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
