Experience of emoving mysql in debian/ubuntu forcefully

I had faced this instance where there ocurred problem with mysql configuration in debian. Something went wrong with the configuration and could not be traced out. We needed to fix it soon and reinstall was the easy option as there was no useful data.
But, the package couldn’t be removed because mysql is stopped before removing, Here, what was happening was that the init script would neither start or stop mysqld due to configuration error. Thus, the package couldn’t be removed as it failed to stop mysql.
So, thus I followed a hack’ish kind of a method to remove mysql.
First I killed mysqld by using top. Then I edited the file /var/lib/dpkg/mysql-server.prerm to remove the relevant section. So, now when I remove the package, the script won’t try to stop mysql-server.
Thus, I was cleanly able to remove the package without any problems.
Also, you get choice whether you want to keep your databases or remove them. Thus, is safe if you have important database.
Though, this method doesn’t have any bad side effects as far as I know, but still it would be better to sort out the configuration issues but here I had no other choice as it was important to remove it quickly and also there were no important configuration saved.

Advertisements

Start rtorrent using init scripts

Searching around the net I came across 2 articles which helped in writing the init script presented below.
There are 3 versions of the script – one for gentoo based distros one for debian based distros and one for Fedora, which is quite similar to debian one.
Requirements for running the scripts

  • rtorrent
  • screen
  • adequate knowledge to operate rtorrent and screen

Steps to get started

  • Copy the contents of the script for your distro to a file
  • Save it with the name indicated in the script
  • Make the file executable with following command

chmod +x /path/to/file

  • Add it to your default boot level as indicated in the comments
  • Change the TUSER value from username to your username
  • Optionally you can change rtorrent to some other bittorrent client depending on your preference. NOTE:- It should be a CLI bittorrent client

The gentoo version of the script

#!/sbin/runscript

# To add the script automatically at the startup execute the following command in the terminal
# eselect rc add rtorrent default

RTUSER=username
TORRENT=/usr/bin/rtorrent

opts=”start stop”

depend() {
#this daemon needs internet to function
need net.eth0
use logger
}

start() {
#display to user that what is being started
ebegin “Starting rtorrent”
#start the process and record record it’s pid
start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER
# To interact with rtorrent you will need to reattach the screen
einfo “To use your rtorrent session, reattach screen using following command:”
einfo “screen -r torrent”
#output failure or success
if [[ $? -eq 0 ]]; then
if [[ $? -eq 0 ]]; then
eend “Process started successfully”
else
eend “Process failed to start”
}

stop () {
#display that we are stopping the process
ebegin “Stopping rtorrent”
#stop the process using pid from start()
start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent
#output success or failure
if [[ $? -eq 0 ]]; then
eend “Process stopped successfully”
else
eend “Process failed to stop”
}

Debian version

#!/bin/bash

# To start the script automatically at bootup type the following command
# update-rc.d torrent defaults 99

RTUSER=username
TORRENT=/usr/bin/rtorrent

case $1 in
start)
#display to user that what is being started
echo “Starting rtorrent”
#start the process and record record it’s pid
start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER
#output failure or success
#info on how to interact with the torrent
echo “To interact with the torrent client, you will need to reattach the screen session with following command”
echo “screen -r torrent”
if [[ $? -eq 0 ]]; then
echo “The process started successfully”
else
echo “The process failed to start”
;;

stop)
#display that we are stopping the process
echo “Stopping rtorrent”
#stop the process using pid from start()
start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent
#output success or failure
if [[ $? -eq 0 ]]; then
echo “The process stopped successfully”
else
echo “The process failed to stop”
;;

*)
# show the options
echo “Usage: {start|stop}”
;;
esac

Seems that debian version will work for Fedora too. Still, here’s the script

#!/bin/bash

# To start the script automatically at bootup type the following command
# chkconfig add torrent

RTUSER=username
TORRENT=/usr/bin/rtorrent

case $1 in
start)
#display to user that what is being started
echo “Starting rtorrent”
#start the process and record record it’s pid
start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER
#output failure or success
#info on how to interact with the torrent
echo “To interact with the torrent client, you will need to reattach the screen session with following command”
echo “screen -r torrent”
if [[ $? -eq 0 ]]; then
echo “The process started successfully”
else
echo “The process failed to start”
;;

stop)
#display that we are stopping the process
echo “Stopping rtorrent”
#stop the process using pid from start()
start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent
#output success or failure
if [[ $? -eq 0 ]]; then
echo “The process stopped successfully”
else
echo “The process failed to stop”
;;

*)
# show the options
echo “Usage: {start|stop}”
;;
esac

One thing I need to implement is to show status. If it is started or stopped. Reload or restart doesn’t seem to make much sense to me thus I haven’t implemented those.
This is only the initial version it may have bugs. Please report them so they can be corrected.
Debian and fedora users please try it and report if it works.
For user of other distros, if interested, please provide some idea of your distro’s init system or attach some init script so that I can work on it.
For people familiar with init system, it would be great to post your modifications/improvements/bug fixes/ideas to this script.