4

I currently have the uwsgi Install uwsgi package installed. I would like to remove the package but leave the current uWSGI instances running. Is this possible?

(Yes, I do realize the service will only continue running until it is stopped or the server restarts.)

Nathan Osman
  • 31,915
  • 40
  • 179
  • 259

2 Answers2

9

The prerm of uwsgi script contains this:

#!/bin/sh
set -e
# Automatically added by dh_installinit
if [ -x "/etc/init.d/uwsgi" ] || [ -e "/etc/init/uwsgi.conf" ]; then
    invoke-rc.d uwsgi stop || exit $?
fi
# End automatically added section
                                                                   

You have a few options:

Edit the prerm script.

The script is usually located at /var/lib/dpkg/uwsgi.prerm. Do:

sudo sed -i '/invoke-rc.d/ s/^/#/' /var/lib/dpkg/uwsgi.prerm

to comment out the command that stops the service.

Use the conditions in the script to your advantage

Either:

sudo chmod -x /etc/init.d/uwsgi

since the script checks for execute permissions of this script,

Or:

mv /etc/init/uwsgi.conf /etc/init/uwsgi.conf.bak

since the script checks for existence of this Upstart service file.

According to the list of files, the package has /etc/init.d/uwsgi and not the Upstart script.

(Mis)Use policy-rc.d

invoke-rc.d is controlled by policy-rc.d. However, using it directly has a problem. The prerm script is has exit $?, and dpkg doesn't like non-zero exit codes. Hence, this will still require changing the prerm script:

echo 'exit 101' > /usr/sbin/invoke-rc.d
chmod +x /usr/sbin/invoke-rc.d
sed 's/exit/echo/' -i /var/lib/dpkg/uwsgi.prerm

Why did I even answer?

There are some brilliant answers already available: Install packages without starting background processes and services (possibly with some slight adaptation required).

muru
  • 193,181
  • 53
  • 473
  • 722
1

You could just keep the package installed until shutdown. That will accomplish relatively the same thing.

Do this by running this command as root:

echo "sudo apt-get remove uwsgi" > /etc/rc6.d/K99_script

followed by:

chmod +x K99_script

When you shutdown, the package will automagically be uninstalled.

Note, though, that after your system comes back up, you should delete the K99 script file.

Kaz Wolfe
  • 33,802
  • 20
  • 111
  • 168
  • Thanks but I need to have the package removed before shutdown since I'm installing the uWSGI package from PIP and some of the files will likely conflict. – Nathan Osman Sep 21 '14 at 19:04
  • @NathanOsman uWSGI might depend on NTLM (not loaded to memory) files. Keeping the service running might cause problems. Why can't you just uninstall one and install the other? – Kaz Wolfe Sep 21 '14 at 19:07
  • I was trying to avoid downtime since I only had a single server at the time I originally asked this question (we have two now). – Nathan Osman Sep 21 '14 at 19:13
  • @NathanOsman Downtime is inevitable sometimes, unfortunately. – Kaz Wolfe Sep 21 '14 at 19:14
  • You meant /etc/rc6.d instead of /etc/r6.d? – thiagowfx Sep 21 '14 at 20:01