You wrote that the /etc/init.d/xyz is done by "sudo" so the deploy user
apparently has access to password-less sudo (at least for some actions), it
would appear that the file is not visible to `root`. Which I don't believe
or expect.

You included a part of the /etc/init.d/xyz, but didn't include the full
thing for some reason, so I can't see what the value of $PIDFILE should be
in this case (*please*, adhere to the list guidelines and paste long files
in an external service, and link them), nor state where you got the
template.

I also don't understand the logic behind setting shell: 'bash' on the run()
lines that interface with the init script.

Your task:

task :stop_app, :roles => :web do

run "sudo /etc/init.d/xyz stop", :shell => :bash

end


​I might suggest you extend that (or make a similar one,
"debug_initd_stuff") that does something like:

task :debug_initd_stuff, :roles => :web do

run "sudo whoam"

run "sudo ls -l /etc/init.d"

run "sudo ls -l /var/run"

end​


​You might also want to run the init.d script through shellcheck.net, since
there are quite a few violations and bad practices already in sight there,
shellcheck might help you iron some of them out. (That said, honestly the
problem is probably something much simpler.)​


Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667

On 18 May 2015 at 21:14, niristotle okram <nirish.ok...@gmail.com> wrote:

> Versions:
>
>    - Ruby 2.1.1
>    - Capistrano 2
>    - Rake / Rails / etc
>
> Platform:
>
>    - Working on.... RHEL 6
>    - Deploying to... RHEL 6
>
>
> A part of the Deploy.rb:
>
> #before "deploy", "deploy:stop_app"
>
>  #after "deploy", "deploy:start_app"
>
>    after "deploy", "deploy:restart_app"
>
>    namespace :deploy do
>
>     task :update_code, :roles => :web, :except => { :no_release => true }
> do
>
>       on_rollback { puts "DO NOT WANT TO ROLL BACK?" }
>
>       strategy.deploy!
>
>       finalize_update
>
>     end
>
>
>
>     task :stop_app, :roles => :web do
>
>       run "sudo /etc/init.d/xyz stop", :shell => :bash
>
>     end
>
>
>
>     task :start_app, :roles => :web do
>
>       run "sudo /etc/init.d/xyz start", :shell => :bash
>
>     end
>
>
>
>
>
>     task :restart_app, :roles => :web do
>
>       run "sudo /etc/init.d/xyz restart", :shell => :bash
>
>     end
>
>   end
>
>
>
>
>
>
>
>
>
> I have the parameter in the 'deploy.rb',
>
> *set :user, 'a_user'*
>
> Q: Which user performs the task to restart the service (xyz) after the
> deployment of app (xyz)? I am getting the errors saying the xyz.pid doesn't
> exist, when it actually does. This is a part of the shell script while
> stopping the service.
>
>
> A part of the /etc/init.d/xyz
>
> case "$1" in
> start)
>         printf "%-50s" "Starting $DAEMON_NAME..."
>         cd $DIR
>         [ -d $LOGPATH ] || mkdir $LOGPATH
>   [ -f $LOGFILE ] || su $DAEMON_USER -c 'touch $LOGFILE'
>         PID=`$PYTHON $DAEMON $DAEMON_OPTS > $LOGFILE  2>&1 & echo $!`
>         #echo "Saving PID" $PID " to " $PIDFILE
>         if [ -z $PID ]; then
>             printf "%s\n" "Fail"
>         else
>             echo $PID > $PIDFILE
>             printf "%s\n" "Ok"
>         fi
> ;;
> status)
>         printf "%-50s" "Checking $DAEMON_NAME..."
>         if [ -f $PIDFILE ]; then
>             PID=`cat $PIDFILE`
>             if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
>                 printf "%s\n" "Process dead but pidfile exists"
>             else
>                 echo "Running"
>             fi
>         else
>             printf "%s\n" "Service not running"
>         fi
> ;;
> stop)
>         printf "%-50s" "Stopping $DAEMONNAME"
>             PID=`cat $PIDFILE`
>             cd $DIR
>         if [ -f $PIDFILE ]; then
>             kill -HUP $PID
>             printf "%s\n" "Ok"
>             rm -f $PIDFILE
>         else
>             printf "%s\n" "pidfile not found"
>         fi
> ;;
>
> restart)
>         $0 stop
>         $0 start
> ;;
>
> *)
>         echo "Usage: $0 {status|start|stop|restart}"
>         exit 1
> esac
>
>
>
> Capistrano log
>
>   * executing `deploy:restart_app'
>
>   * executing multiple commands in parallel
>
>     -> "else" :: "sudo /etc/init.d/xyz restart"
>
>     -> "else" :: "sudo /etc/init.d/xyz restart"
>
>     -> "else" :: "sudo /etc/init.d/xyz restart"
>
>     -> "else" :: "sudo /etc/init.d/xyz restart"
>
>     servers: ["server1", "server2", "server3", "server4"]
>
>     [server1] executing command
>
>     [server2] executing command
>
>     [server3] executing command
>
>     [server4] executing command
>
>  ** [out :: server1] Stopping
>
>  ** [out :: server1] cat: /var/run/xyz.pid: No such file or directory
>
>  ** [out :: server1] pidfile not found
>
>  ** [out :: server1] Starting xyz...
>
>  ** [out :: server2] Stopping
>
>  ** [out :: server2] cat: /var/run/xyz.pid: No such file or directory
>
>  ** [out :: server2] pidfile not found
>
>  ** [out :: server2] Starting xyz...
>
>  ** [out :: server2] Ok
>
>  ** [out :: server1] Ok
>
>  ** [out :: server3] Stopping
>
>  ** [out :: server3] cat: /var/run/xyz.pid: No such file or directory
>
>  ** [out :: server3] pidfile not found
>
>  ** [out :: server4] Stopping
>
>  ** [out :: server4] Ok
>
>  ** [out :: server3] Starting xyz...
>
>  ** [out :: server3] Ok
>
>  ** [out :: server4] Starting xyz...
>
>  ** [out :: server4] Ok
>
>     command finished in 659ms
>
> Finished: SUCCESS
>
>
>
>
> I can cat the file as the deploy user just fine.
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Capistrano" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to capistrano+unsubscr...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/capistrano/56a2a2dd-fd26-4b14-a2da-0d7af37f8354%40googlegroups.com
> <https://groups.google.com/d/msgid/capistrano/56a2a2dd-fd26-4b14-a2da-0d7af37f8354%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to capistrano+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/capistrano/CAN_%2BVLWcTrwkJWPd%3D9adZV0XYhvSGHQroBHPYypnyMHeWu7AOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to