user1553248
user1553248

Reputation: 1204

dpkg remove to stop processes

I am currently running Ubuntu 12.04. I've created a debian package that currently installs successfully and starts three new processes. I have also made these three processes start at runtime by placing the following script inside /etc/init.d:

# This example is from http://www.debian-administration.org/article/Making_scripts_run_at_boot_time_with_Debian
#  Also used http://wiki.debian.org/LSBInitScripts/

### BEGIN INIT INFO
# Provides:          bleh
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO


# Carry out specific functions when asked to by the system
case "$1" in
  start)
    cd //opt/bleh
    attrf=.gatewayattributes

    if [ ! -z "$1" ]
    then
  echo "[gateway]" >> $attrf
    echo "activationKey = $1" >> $attrf
fi

./bleh1 -n &
./bleh2 &
python bleh3 &

    ;;
  stop)
cd //opt/bleh
/usr/bin/pkill -f ./bleh1 -n
    /usr/bin/pkill -f bleh3
    kill -9 $(pidof bleh2)
    rm -rf logs
    ;;

This script does start the three processes at runtime, but for some reason I cannot actually use the start/stop commands, as in sudo /etc/init.d bleh.sh stop.

An even bigger issue is that removing this package using the command: sudo dpkg -r bleh

Does not actually stop the three processes, it only tries to remove the bleh directory I installed in my opt folder. Also, I have a folder inside my bleh directory which does not get removed, it gives me a warning stating: Removing bleh ... dpkg: warning: while removing bleh, directory '/opt/bleh/logs' not empty so not removed.

The files inside of that logs directory are read-only unless you have SU priviledges, but I don't see how that should be a problem as I am calling sudo on that dpkg -r command.

If I run sudo dpkg -r bleh again, it states there's no installed package matching bleh, meaning it thinks it has successfully removed the installed package, even with that exisiting logs directory and the three processes which are still running.

Sorry, I know this was long, but I could really use some help.. thanks in advance!

Upvotes: 2

Views: 2913

Answers (1)

ephemient
ephemient

Reputation: 204926

As recommended by the Debian New Maintainer's Guide, please use dh_installinit (building your whole package with debhelper, of course). By default, this will add scripts to start and stop on package installation and removal.

Auxiliary files (such as configuration) are usually removed in purge (e.g. dpkg -P) state. To handle this yourself, you need a deconfigure script.

Also, it is highly preferable to use start-stop-daemon instead of &, which is insufficient for proper daemonization.

Upvotes: 2

Related Questions