Memcached systemd file
Hello,
I have installed memcached:
but occasionally after a cpanel update the unit file that starts the service:
is overwritten. The correct unit files is this:
while the wrong one (the service is not started) is this:
It seems that the $USER variable is not available in the unit file. Any idea as why this happens?
[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:
/etc/systemd/system/multi-user.target.wants/memcached.serviceis overwritten. The correct unit files is this:
[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:
[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?
-
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: # 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:/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.0 -
This file: /etc/systemd/system/multi-user.target.wants/memcached.service
is a link to:/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:[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.0 -
Hello, The "$USER" variable should work, because it links to the following environment file: /etc/sysconfig/memcached
Within this file, you should see an entry like this: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: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.0 -
Thanks for the reply. I wasn't aware of the file: /etc/sysconfig/memcached
The contents of this file in my system is this: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:[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:USER=memcached PORT=11211
Problem solved. The service is successfully started, restarted etc. Thanks for the help!!!0
Please sign in to leave a comment.
Comments
4 comments