Sep 4, 2016
21
4
3
Greece
cPanel Access Level
Root Administrator
Twitter
Hello,

I have installed memcached:

Code:
[root@server ~]# rpm -qa |grep memcac
ea-php56-php-memcached-2.2.0-1.4.119.cpanel.x86_64
libmemcached-1.0.18-1.3.4.cpanel.x86_64
ea-php56-php-memcache-2.2.7-1.3.118.cpanel.x86_64
ea-memcached-1.5.3-2.2.1.cpanel.x86_64
but occasionally after a cpanel update the unit file that starts the service:

Code:
/etc/systemd/system/multi-user.target.wants/memcached.service
is overwritten.

The correct unit files is this:

Code:
[Unit]
Description=Memcached
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/bin/memcached -u memcached -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

[Install]
WantedBy=multi-user.target
while the wrong one (the service is not started) is this:

Code:
[Unit]
Description=Memcached
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

[Install]
WantedBy=multi-user.target
It seems that the $USER variable is not available in the unit file.

Any idea as why this happens?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,270
463
Hello,

The /etc/systemd/system/multi-user.target.wants/memcached.service does not exist on a test CentOS 7 system when installing the Memcached via the EA4 experimental repo:

Code:
# stat /etc/systemd/system/multi-user.target.wants/memcached.service
stat: cannot stat ‘/etc/systemd/system/multi-user.target.wants/memcached.service’: No such file or directory
Instead, it uses the following file:

Code:
/usr/lib/systemd/system/memcached.service
To clarify, are you manually setting up the /etc/systemd/system/multi-user.target.wants/memcached.service file?

Thank you.
 
Sep 4, 2016
21
4
3
Greece
cPanel Access Level
Root Administrator
Twitter
This file:
Code:
/etc/systemd/system/multi-user.target.wants/memcached.service
is a link to:
Code:
/usr/lib/systemd/system/memcached.service
The truth is that the link is automatically created from systemd when you enable the service with the command:
Code:
[root@server]# systemctl enable memcached.service
Created symlink from /etc/systemd/system/multi-user.target.wants/memcached.service to /usr/lib/systemd/system/memcached.service.
Do the same in your test system and you will see that the link will be created.

So the problem is that each time a new version of ea-memcached package is installed it overwrites the /usr/lib/systemd/system/memcached.service file. More specific the problem is the $USER variable.

When this variable is present the service is not started.

When i replace the $USER variable with the "memcached" string (compare the unit files in my initial post) the service is successfully started.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,270
463
Hello,

The "$USER" variable should work, because it links to the following environment file:

Code:
/etc/sysconfig/memcached
Within this file, you should see an entry like this:

Code:
USER="memcached"
I left the default "$USER" entry in the /usr/lib/systemd/system/memcached.service file, and rebooted the system. Upon doing so, memcached was started successfully:

Code:
Jan 24 09:50:03 cp70 systemd[1]: Starting Memcached...
-- Subject: Unit memcached.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit memcached.service has begun starting up.
What does the /etc/sysconfig/memcached file look like on your system?

Thank you.
 
  • Like
Reactions: vikelidiskostas
Sep 4, 2016
21
4
3
Greece
cPanel Access Level
Root Administrator
Twitter
Thanks for the reply.

I wasn't aware of the file:

Code:
/etc/sysconfig/memcached
The contents of this file in my system is this:

Code:
user=memcached
PORT=11211
To solve the problem i have done the following:

I restored the unit file

/usr/lib/systemd/system/memcached.service

in its original state and now it looks like this:

Code:
[Unit]
Description=Memcached
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

[Install]
WantedBy=multi-user.target
Then i capitilized the variable's name in /etc/sysconfig/memcached. Now this file looks like this:

Code:
USER=memcached
PORT=11211
Problem solved.

The service is successfully started, restarted etc.

Thanks for the help!!!
 
  • Like
Reactions: cPanelMichael