[SOLVED] Restart Zimbra from another Linux user

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
Post Reply
tonyg
Advanced member
Advanced member
Posts: 51
Joined: Fri Mar 16, 2018 5:25 pm
Location: USA
ZCS/ZD Version: 8.8.12.GA.3794.UBUNTU18.64 FOSS
Contact:

[SOLVED] Restart Zimbra from another Linux user

Post by tonyg »

Following wiki advice, I'm trying to ensure that Zimbra 8.8.12 Beta for Ubuntu is in a proper state when updating Ubuntu 18.04.
In short we need to stop all Zimbra services, restart LDAP and ConfigD, then do the update/upgrade, then restart all Zimbra services. I had to start looking for a solution like that when I did an update and Ubuntu failed to connect to remote repositories.

I typically login as "ubuntu" and do all server operations via sudo, including the update. I use this alias:

Code: Select all

alias update='sudo sh -c '\''apt-get update && apt-get upgrade --yes && if [ -f /var/run/reboot-required ]; then echo You should reboot; fi'\'' '
To execute Zimbra commands before and after that, we need to sudo as user zimbra. This is what leads to my question with the following line:

Code: Select all

sudo -u zimbra /opt/zimbra/bin/zmcontrol restart
That does stop all services, but on restart there is an error which has been noted in this forum before:

Code: Select all

Starting opendkim...Failed.
opendkim: /opt/zimbra/conf/opendkim.conf: ldap://sub.sub.domain.tld:389/?DKIMSelector?sub?(DKIMIdentity=$d): dkimf_db_open(): Connect error
Failed to start opendkim: 0
If I login to zimbra ( sudo su - zimbra ), and "zmopendkimctl start", it starts without a problem.

Also, from user ubuntu, this actually does stop opendkim but returns the above error on start:

Code: Select all

sudo -u zimbra /opt/zimbra/bin/zmopendkimctl restart
I'm sure this has something to do with the environment variables but I don't know what the secret sauce is to make this work. I've tried various combinations of sudo and su, related options, and trying to execute /opt/zimbra/.bashrc to load the zimbra environment before executing anything else.

To dd jut a little more, logswatch has exactly the same problem: starts fine when actually in user zimbra but returns a simple 'failed' message when started with zmcontrol restart above.
On one hand this seems like a Linux/Ubuntu question which could be applied to any similar request. On the other hand, I am wondering if there is something very Zimbra-specific going on, like maybe some other permissions are required that user zimbra gets but that aren't provided when shelling into the user like this. I'm really hoping someone else already has a working script just for updates like this.

Thanks!
Last edited by tonyg on Thu Jun 27, 2019 10:20 pm, edited 1 time in total.
User avatar
ccelis5215
Outstanding Member
Outstanding Member
Posts: 632
Joined: Sat Sep 13, 2014 2:04 am
Location: Caracas - Venezuela
ZCS/ZD Version: 8.8.15.GA.3869.UBUNTU18.64 P12

Re: Restart Zimbra from another Linux user

Post by ccelis5215 »

Hi,

Code: Select all

su - zimbra -c "zmcontrol restart"
as user root or any users with privilegues to do so..

ccelis
tonyg
Advanced member
Advanced member
Posts: 51
Joined: Fri Mar 16, 2018 5:25 pm
Location: USA
ZCS/ZD Version: 8.8.12.GA.3794.UBUNTU18.64 FOSS
Contact:

Re: Restart Zimbra from another Linux user

Post by tonyg »

Thank you very much. This works perfectly. I'm providing my script for others:

Code: Select all

# Ubuntu OS update on Zimbra server
# https://wiki.zimbra.com/wiki/Best_Practices_for_executing_Package_Updates
# TG 2019/06/27

# Stop all zimbra processes
sudo -u zimbra /opt/zimbra/bin/zmcontrol stop

# Restart LDAP so update can make external calls to repositories
sudo -u zimbra /opt/zimbra/bin/ldap start

# zmconfigd keeps LDAP running? https://wiki.zimbra.com/wiki/Zmconfigd
sudo -u zimbra /opt/zimbra/bin/zmconfigdctl start

# Now do an update, but only upgrade (with auto-remove) if something was updated
sudo apt-get update && sudo apt-get dist-upgrade --yes

# restart Zimbra with full zimbra user environment, not that of the current user
sudo su - zimbra -c "zmcontrol restart"

# Tell user at the CLI if we need to restart, enhance later to email admin
if [ -f /var/run/reboot-required ]; then echo You should reboot; fi
Post Reply