Uninstall fails on Ubuntu with SysV

I have elasticsearch installed on my Ubuntu installation (18.04 on WSL), which uses SysV.
I installed it using the instructions https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html
I want to uninstall it but am getting an error when I use sudo apt-get purge --autoremove elasticsearch

Removing elasticsearch (6.4.2) ...
Stopping elasticsearch service...System has not been booted with systemd as init system (PID 1). Can't operate.
dpkg: error processing package elasticsearch (--remove):
 installed elasticsearch package pre-removal script subprocess returned error exit status 1
System has not been booted with systemd as init system (PID 1). Can't operate.
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
Errors were encountered while processing:
 elasticsearch
E: Sub-process /usr/bin/dpkg returned an error code (1)

I have ensured that the service elasticsearch start and stop commands work, and that the service is stopped.

I have tried the commands that the error message suggests, but as my system does not use systemd , they do not work:

$ sudo systemctl daemon-reload
[sudo] password for you:
System has not been booted with systemd as init system (PID 1). Can't operate.
$ sudo systemctl enable elasticsearch.service
Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /usr/lib/systemd/system/elasticsearch.service.
$ sudo systemctl start elasticsearch
System has not been booted with systemd as init system (PID 1). Can't operate.
$ sudo apt purge --autoremove elasticsearch
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  elasticsearch*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 168 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 37566 files and directories currently installed.)
Removing elasticsearch (6.5.4) ...
Stopping elasticsearch service...System has not been booted with systemd as init system (PID 1). Can't operate.
dpkg: error processing package elasticsearch (--remove):
 installed elasticsearch package pre-removal script subprocess returned error exit status 1
System has not been booted with systemd as init system (PID 1). Can't operate.
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

The service is already running (SysV way):

$ sudo -i service elasticsearch status
 * elasticsearch is running

Yet the uninstall continues to complain like this that init system is not used...

How do I uninstall?

This works without issues on a plain Ubuntu 18.04 installation:

vagrant@elastic-stack:/opt$ sudo dpkg -i elasticsearch-6.4.2.deb 
Selecting previously unselected package elasticsearch.
(Reading database ... 166235 files and directories currently installed.)
Preparing to unpack elasticsearch-6.4.2.deb ...
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Unpacking elasticsearch (6.4.2) ...
Setting up elasticsearch (6.4.2) ...
Created elasticsearch keystore in /etc/elasticsearch
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10.9) ...
vagrant@elastic-stack:/opt$ sudo service elasticsearch start 
vagrant@elastic-stack:/opt$ sudo service elasticsearch status
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-01-04 20:12:55 UTC; 2min 12s ago
     Docs: http://www.elastic.co
 Main PID: 7900 (java)
    Tasks: 41 (limit: 3571)
   CGroup: /system.slice/elasticsearch.service
           ├─7900 /usr/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOcc
           └─7970 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Jan 04 20:12:55 elastic-stack systemd[1]: Started Elasticsearch.
vagrant@elastic-stack:/opt$ sudo apt-get purge --autoremove elasticsearch
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  elasticsearch*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 151 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 166630 files and directories currently installed.)
Removing elasticsearch (6.4.2) ...
Stopping elasticsearch service... OK
Deleting log directory... OK
(Reading database ... 166244 files and directories currently installed.)
Purging configuration files for elasticsearch (6.4.2) ...
dpkg: warning: while removing elasticsearch, directory '/var/lib/elasticsearch' not empty so not removed
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10.9) ...
vagrant@elastic-stack:/opt$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic

I guess WSL is to blame and I'm pretty sure we don't test this scenario. Also systemd support doesn't seem to be an option on WSL.

Maybe plain dpkg works on WSL?

vagrant@elastic-stack:/opt$ sudo dpkg -r elasticsearch 
(Reading database ... 166630 files and directories currently installed.)
Removing elasticsearch (6.4.2) ...
Stopping elasticsearch service... OK

Thanks for the info @xeraa.

I had tried to more fully assess the systemd situation on WSL but don't really know what I'm at on that front so haven't had much success :smile:

I tried the dpkg route but unfortunately it suffers the same issue. Is there a manual method?
Or maybe a link to the script that is run to uninstall that I can step through?

Thanks!

I think https://github.com/elastic/elasticsearch/tree/master/distribution/packages/src/common/scripts is what you are looking for.

PS: Without knowing the specific context, we have a well maintained MSI binary for Windows — in case you don't want to fight the DEB.

Thanks @xeraa

I followed the steps in from the script that pertained to my system from the prerm and postrm scripts from your link.

Additionally, I needed to manually remove the elasticsearch script from /etc/init.d/ after the sudo update-rc.d -f elasticsearch remove.

Thanks again.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.