Articles
Although I think in numbers there are times when I just write, it doesn’t happen very much but it does occur at times. I target what I write to fellow technology developers and designers as it allows me to describe the things that I am thinking without needing to “dumb them down” too much. If you have any questions or feedback about any of these articles feel free to contact me, the more feedback I receive the better the chances of me writing more often will become.
All articles tagged with “Server”
User init scripts16th February, 2008
While porting my Apache development server configuration over to Lighttpd I needed a script that would maintain Django FastCGI daemons even after a reboot of the host server. Even though I could have done this by just starting the daemons in an init script directly there where two problems with this approach:
- Running a web-server CGI script as root is massive security risk, and
- Users would require root access to restart the daemons if they made a change to the instance.
To get around these problems I wrote the following script that will automatically execute a script in the user’s home directory with their permissions on system boot. This also allows the user to manually restart the daemons at any time without being a security hazard if they require it, as well as not interfering with daemons of other users. The user init script itself should behave just like a normal one, meaning it should respect the “start”, “stop” and “restart” arguments and not require any user input to execute to completion.
By default the the script will search each subdirectory in /home/ non-recursively for a script called .init and then attempt to execute it as the user defined by the subdirectory’s name. I.e. the script /home/bob/.init will be executed as the “bob” user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #!/bin/sh
HOMEROOT="/home"
INITFILE=".init"
case "$1" in
start)
echo -n "Starting user scripts..."
for USER in `ls $HOMEROOT`; do
[ -d $HOMEROOT/$USER ] && [ -f $HOMEROOT/$USER/$INITFILE ] && \
sudo -u $USER $HOMEROOT/$USER/$INITFILE start >> /dev/null &
done
echo " Done"
;;
stop)
echo -n "Stopping user scripts..."
for USER in `ls $HOMEROOT`; do
[ -d $HOMEROOT/$USER ] && [ -f $HOMEROOT/$USER/$INITFILE ] && \
sudo -u $USER $HOMEROOT/$USER/$INITFILE stop >> /dev/null &
done
echo " Done"
;;
restart)
echo -n "Restarting user scripts..."
for USER in `ls $HOMEROOT`; do
[ -d $HOMEROOT/$USER ] && [ -f $HOMEROOT/$USER/$INITFILE ] && \
sudo -u $USER $HOMEROOT/$USER/$INITFILE restart >> /dev/null &
done
echo " Done"
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac
|
Apache 2 Configuration6th March, 2007
After upgrading one of my private servers a little while ago I decided to expand upon the web-server that was being happily hosted on it for the last year or so. As I cannot find any sample configuration files online that do something similar to what this server does I present to you the configuration files that I used on my server. Hopefully they will be of use to somebody.