LinuxPlanet Blogs

By Linux Geeks, For Linux Geeks.

Removing packages and configurations with apt-get

without comments

Yesterday while re-purposing a server I was removing packages with apt-get and stumbled upon an interesting problem. After I removed the package and all of it's configurations, the subsequent installation did not re-deploy the configuration files.

After a bit of digging I found out that there are two methods for removing packages with apt-get. One of those method should be used if you want to remove binaries, and the other should be used if you want to remove both binaries and configuration files.

What I did

Since the method I originally used caused at least 10 minutes of head scratching; I thought it would be useful to share what I did and how to resolve it.

On my system the package I wanted to remove was supervisor which is pretty awesome btw. To remove the package I simply removed it with apt-get remove just like I've done many times before.

# apt-get remove supervisor
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  supervisor
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,521 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 14158 files and directories currently installed.)
Removing supervisor ...
Stopping supervisor: supervisord.
Processing triggers for ureadahead ...

No issues so far, the package was removed according to apt without any issues. However, after looking around a bit I noticed that the /etc/supervisor directory still existed. As well as the supervisord.conf file.

# ls -la /etc/supervisor
total 12
drwxr-xr-x  2 root root 4096 Aug 17 19:44 .
drwxr-xr-x 68 root root 4096 Aug 17 19:43 ..
-rw-r--r--  1 root root 1178 Jul 30  2013 supervisord.conf

Considering I was planning on re-installing supervisor and I didn't want to cause any weird configuration issues as I moved from one server role to another I did what any other reasonable Sysadmin would do. I removed the directory...

# rm -Rf /etc/supervisor

I knew the supervisor package was removed, and I assumed that the package didn't remove the config files to avoid losing custom configurations. In my case I wanted to start over from scratch, so deleting the directory sounded like a reasonable thing.

# apt-get install supervisor
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  supervisor
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/314 kB of archives.
After this operation, 1,521 kB of additional disk space will be used.
Selecting previously unselected package supervisor.
(Reading database ... 13838 files and directories currently installed.)
Unpacking supervisor (from .../supervisor_3.0b2-1_all.deb) ...
Processing triggers for ureadahead ...
Setting up supervisor (3.0b2-1) ...
Starting supervisor: Error: could not find config file /etc/supervisor/supervisord.conf
For help, use /usr/bin/supervisord -h
invoke-rc.d: initscript supervisor, action "start" failed.
dpkg: error processing supervisor (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 supervisor
E: Sub-process /usr/bin/dpkg returned an error code (1)

However, it seems supervisor could not start after re-installing.

# ls -la /etc/supervisor
ls: cannot access /etc/supervisor: No such file or directory

There is good reason why supervisor wouldn't restart; because the /etc/supervisor/supervisord.conf file was missing. Shouldn't the package installation deploy the supervisord.conf file? Well, technically no. Not with the way I removed the supervisor package.

Why it didn't work

How remove works

If we look at apt-get's man page a little closer we can see why the configuration files are still there.

remove
  remove is identical to install except that packages are removed
  instead of installed. Note that removing a package leaves its
  configuration files on the system.

As the manpage clearly says, remove will remove the package but leaves configuration files in place. This explains why the /etc/supervisor directory was lingering after removing the package; but it doesn't explain why a subsequent installation doesn't re-deploy the configuration files.

Package States

If we use dpkg to look at the supervisor package, we will start to see the issue.

# dpkg --list supervisor
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                             Version               Architecture          Description
+++-================================-=====================-=====================-========================================
rc  supervisor                       3.0b2-1               all                   A system for controlling process state

With the dpkg package manager a package can have more states than just being installed or not-installed. In fact there are several package states with dpkg.

  • not-installed - The package is not installed on this system
  • config-files - Only the configuration files are deployed to this system
  • half-installed - The installation of the package has been started, but not completed
  • unpacked - The package is unpacked, but not configured
  • half-configured - The package is unpacked and configuration has started but not completed
  • triggers-awaited - The package awaits trigger processing by another package
  • triggers-pending - The package has been triggered
  • installed - The packaged is unpacked and configured OK

If you look at the first column of the dpkg --list it shows rc. The r in this column means the package is remove, which as we saw above means the configuration files are left on the system. The c in this column shows that the package is in the state of config-files. Meaning, only the configuration files are deployed on this system.

When running apt-get install the apt package manager will lookup the current state of the package, when it sees that the package is already in the config-files state it simply skips the configuration file portion of the package installation. Since I manually removed the configuration files outside of the apt or dpkg process the configuration files are gone and will not be deployed with a simple apt-get install.

How to resolve it and remove configurations properly

Purging the package from my system

At this point, I found myself with a broken installation of supervisor. Luckily, we can fix the issue by using the purge option of apt-get.

# apt-get purge supervisor
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  supervisor*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 1,521 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 14158 files and directories currently installed.)
Removing supervisor ...
Stopping supervisor: supervisord.
Purging configuration files for supervisor ...
dpkg: warning: while removing supervisor, directory '/var/log/supervisor' not empty so not removed
Processing triggers for ureadahead ...

Purge vs Remove

The purge option of apt-get is similar to the remove function however with one difference. The purge option will remove both the package and configurations. After running apt-get purge we can see that the package was fully removed by running dpkg --list again.

# dpkg --list supervisor
dpkg-query: no packages found matching supervisor

Re-installation without error

Now that the package has been fully purged, and the state of it is now not-installed; we can re-install without errors.

# apt-get install supervisor
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  supervisor
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/314 kB of archives.
After this operation, 1,521 kB of additional disk space will be used.
Selecting previously unselected package supervisor.
(Reading database ... 13833 files and directories currently installed.)
Unpacking supervisor (from .../supervisor_3.0b2-1_all.deb) ...
Processing triggers for ureadahead ...
Setting up supervisor (3.0b2-1) ...
Starting supervisor: supervisord.
Processing triggers for ureadahead ...

As you can see from the output above, the supervisor package has been installed and started. If we check the /etc/supervisor directory again we can also see the necessary configuration files.

# ls -la /etc/supervisor/
total 16
drwxr-xr-x  3 root root 4096 Aug 17 19:46 .
drwxr-xr-x 68 root root 4096 Aug 17 19:46 ..
drwxr-xr-x  2 root root 4096 Jul 30  2013 conf.d
-rw-r--r--  1 root root 1178 Jul 30  2013 supervisord.conf

You should probably just use purge in most cases

After running into this issue I realized, most of the times I ran apt-get remove I really wanted the functionality of apt-get purge. While it is nice to keep configurations handy in case we need them after re-installation, using remove all the time also leaves random config files to clutter your system. Free to cause configuration issues when packages are removed then re-installed.

In the future I will most likely default to apt-get purge.


Originally Posted on BenCane.com: Go To Article

Written by Benjamin Cane

August 18th, 2014 at 8:45 am

Posted in Uncategorized

[Solved] Skype 4.2.x Linux : Can’t Connect | Ubuntu 12.04 / Ubuntu 14.04 LTS

without comments

Hello All, Today Morning, I started my Laptop and Logged in to My Ubuntu 14.04.1 LTS box and tried to Login in to Skype with same credentials, Skype thrown Error was “Can’t Connect”. I managed to solve this error so sharing this error’s solution which might helps you. This Error’s solution is very simple but […]

Taking password using GUI in linux script using whiptail

without comments

In the post we saw how to install and use whiptail. We can use whiptail to accept passwords from user too.

The syntax to use the password is



Example



The password entered will not be visible and will appear only as *. But by default the entered password is sent to the error console.

 photo whip_pass.png

To use the password in the script, we will have to swap the standard error and standard output consoles which can be done as below.



what ever password the user enters, it will be stored in the variable input.

Here is an example script, in which we will take the user password and verify if the same is correct or not.



Save the script, give it execute permission and run it. $ chmod 777 whiptail_password.sh $ ./whiptail_password.sh

 photo whip_pass.png

 photo whip_correct_pass.png


Written by Tux Think

August 14th, 2014 at 11:43 am

Taking input from user using whiptail

without comments

In the post "Creating message box in a shell script" we saw how to install whiptail and use it to create a basic message box in scrpting.

Other than just displaying messages, scripts also take input from user. Whiptail can be used to create a small GUI for the user to enter his or her input.

To create an input box we need to use the option --inputbox, the syntax being



Example



 photo whip_input.png

By default whiptail passes the input entered to the standard error console, and in a usual shell we will be able see the entered text on the terminal after we exit from the whiptail window.

But if we want to use the entered input by storing it in some variable, we will have to go about a few manipulations as there is no direct way of doing it in whiptail.

The simple manipulation we will have to do is swap the standard error console and the standard output console which can be done by appending



to the command.

Thus we can write the whiptail command as



The varialbe val will get the value that is entered in the inputbox.

Here is an example script to see the use if inputbox

whip_input.sh



Give the script execute permission and run it to see the output



 photo whip_input_tux.png

 photo whip_hello_tux.png


Written by Tux Think

August 10th, 2014 at 1:10 am

Bad Voltage Season 1 Episode 22: Oval Ted Bag

without comments

From the Bad Voltage site:

We return to our normal places around the globe and continue to bring you tasty things for your ears. Stuart Langridge, Jono Bacon, myself and an inexcusable absence of Bryan Lunduke think up a new competition involving things in our houses, and also discuss:

  • Where’s our free culture revolution? Lawrence Lessig predicted a world filled with remix culture and set up the Creative Commons, but little to none of it has actually changed the way people think. Or has it? (2.25)
  • Graham Morrison of Linux Voice answers some of the questions from our discussion in the previous show about their magazine, their process, and why the December issue comes out in June (17.45)
  • Mashed Voltage: we start a new competition. Read about it on the forum and listen to it on the show, and enter before September 10th to celebrate remix culture (36.48)
  • Jono reviews the Samsung Gear Live smartwatch and the team watch, smartly (40.25)
  • Open source projects sometimes decide that they’ll build their own hardware. When they try, they fail. Why? What motivates the decision to do it in the first place? (54.22)

Listen to 1×22: Oval Ted Bag

As mentioned here, Bad Voltage is a new project I’m proud to be a part of. From the Bad Voltage site: Every two weeks Bad Voltage delivers an amusing take on technology, Open Source, politics, music, and anything else we think is interesting, as well as interviews and reviews. Do note that Bad Voltage is in no way related to LinuxQuestions.org, and unlike LQ it will be decidedly NSFW. That said, head over to the Bad Voltage website, take a listen and let us know what you think.

–jeremy


Written by jeremy

August 7th, 2014 at 9:01 am

Posted in Bad Voltage

RHEL 7 / CentOS 7 : Recovering / Reset Root Password

without comments

Hello, Setting up the root password is a mandatory part of the Red Hat Enterprise Linux 7 / CentOS 7installation. If you forget or lose your password, it is possible to reset it. Note: In GRUB 2, resetting the password is no longer performed in single-user mode as it was in GRUB included in Red Hat Enterprise Linux […]

RHEL 7 / CentOS 7: How to get started with Firewalld

without comments

Hello All, Today I was trying to learn and know about Systemd. I have found one of the great Article about firewalld, Sharing with you guys, It will help you to understand this biggest and major change in RHEL and CentOS 7. This article is not mine, I found on internet and felt that this […]

Creating yes no option box in linux scripting

without comments

In the post "Creating message box in a shell script" we saw how to create a message box using whiptail. Now let us see how to create a yes/no box where the user can choose one of the two and then the further action can be decided.

The syntax to create a yesno box using whiptail is



Example



 photo whiptail_yesno.png

If we select yes, the return value of the command will be 0, for no the return value will be 1. We can use the return value to decide the further course of action for the script.

Here is a script that keeps popping up the yes/no box as long as the user does not select "no" to stop the script.



$bash yesno.sh  photo whip_continue.png

 photo whip_yesno.png


Written by Tux Think

August 4th, 2014 at 10:03 am

Posted in Linux,Scripting

Creating message box in a shell script

without comments

Shell scripts are generally assumed to be restricted to using only the command line for interaction with the user and lacks the graphical user interfaces available in the GUI mode.

One way of creating small GUIs in shell scripts is by the use of whiptail.

Here is how we can create a message box using whiptail. To create a message box we need to use the option --msgbox.

syntax:



example



The above command will create a message box of 10 X 20 with the text hello in it as shown below.

 photo whip_tail_msgbox.png

By default the text that appears for exiting the message box is OK.

We can changet the text using the option --ok-button



 photo whiptail_ok_button.png



Example script




Written by Tux Think

August 3rd, 2014 at 3:37 am

Posted in Linux,Scripting

RHEL 7 / CentOS 7 : Disable Firewalld and use iptables

without comments

Hello, Just installed CentOS 7 on my Virtual machine and realized that, Firewalld is bit complicated as I am using iptables firewall from many years. So decided not to use firewalld at least as of now and wanted to continue with iptables commands as I was using in RHEL / CentOS 5 and 6. I […]