WebFaction
Community site: login faq

Other users are not allowed to kill my processes, so pyramid_app/bin/stop doesn't work. This is resistant to setuid-bit solutions since bin/pserve is a script, rather than a binary.

asked 25 Sep '12, 00:12

bluej100
112
accept rate: 0%

Thank you to @seanf for getting me on the right track with "How can I let another user restart my Django app's Apache server?".

(25 Sep '12, 00:20) bluej100

This is hacked together, but I threw up a little Bash daemon that solves the problem. It uses three files. bin/pserve-wrapper-start must be run by the owner user once, and then bin/pserve-wrapper-trigger-restart is a drop-in replacement for bin/restart. I welcome suggestions.

bin/pserve-wrapper:

#!/bin/bash
cd /home/username/webapps/pyramid_app
while [ true ]; do
if [ -e pserve-wrapper-trigger ]
then
  echo 'restarting!'
  /home/username/webapps/pyramid_app/bin/restart
  rm pserve-wrapper-trigger
fi
sleep 3
done

bin/pserve-wrapper-start:

#!/bin/bash
cd /home/username/webapps/pyramid_app && nohup bin/pserve-wrapper &> pserve-wrapper.log &
echo 'Started!'

bin/pserve-wrapper-trigger-restart:

#!/bin/bash
cd /home/username/webapps/pyramid_app && touch pserve-wrapper-trigger
echo 'Triggered!'
permanent link

answered 25 Sep '12, 00:18

bluej100
112
accept rate: 0%

edited 25 Sep '12, 00:26

This is a really creative solution!

As you correctly pointed out, this topic is related and solves the problem via a setuid binary.

(25 Sep '12, 01:25) ryans ♦♦

Thanks! I'm glad to hear from an admin that it's not obviously terrible.

(25 Sep '12, 02:23) bluej100

I should give credit to seanf for this solution as well as the setuid solution; he suggested something similar in Webfaction forums: svn hooks.

(25 Sep '12, 11:49) bluej100

@ryans, do you think that setting this up as a cronjob, as in seanf's post, would be preferable to my manual sleep loop here?

(25 Sep '12, 11:53) bluej100

Thanks for the credit, but none of that was really my idea :)

In my opinion, a cron job is preferable to using a sleep loop in a daemon process as you're doing above. If something were to kill your daemon process, your other user would not be able to restart your app until you restarted the daemon.

(25 Sep '12, 12:56) seanf

Good point. Thank you, seanf. I'll get a cron job set up and post it as an answer here. Feel free to downvote this answer in the meantime.

(25 Sep '12, 13:03) bluej100

Why not combine the two approaches?

  • You can run your daemon as above - this will give you a shorter interval between checks (cron will give you only a 1-minute interval).
  • You can have a cron job that restarts your daemon if it isn't running.
(25 Sep '12, 13:09) seanf

That's a great idea. A one-minute delay is acceptable for now, though. I'll post the combined solution if I ever get around to it.

(25 Sep '12, 13:30) bluej100
showing 5 of 8 show 3 more comments

Here's a cron-based solution, which is less immediately responsive but more robust:

bin/restart-check:

#!/bin/bash
cd /home/username/webapps/pyramid_app
if [ -e restart-trigger ]
then
  echo 'Restarting!'
  bin/restart
  rm restart-trigger
fi

bin/restart-trigger

#!/bin/bash
cd /home/username/webapps/pyramid_app && touch restart-trigger
echo 'Triggered!'

And a new line in your crontab:

* * * * * cd ~/webapps/pyramid_app; bin/restart-check &>> ~/restart-check.log
permanent link

answered 25 Sep '12, 13:29

bluej100
112
accept rate: 0%

edited 25 Sep '12, 13:31

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×64
×24
×17

question asked: 25 Sep '12, 00:12

question was seen: 5,288 times

last updated: 25 Sep '12, 13:31

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM