Solved: [error] Unable to obtain semaphore.

Today we will see an interesting article how to resolve below error.

I. Error Details

[root@ngelinux001 conf.d]# service httpd start
Starting httpd: [Wed May 18 23:41:31 2022] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed May 18 23:41:31 2022] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed May 18 23:41:31 2022] [error] Server certificate is expired: 'Server-Cert'
[Wed May 18 23:41:31 2022] [error] Server certificate is expired: 'Server-Cert'
[Wed May 18 23:41:31 2022] [error] Unable to obtain semaphore.
[Wed May 18 23:41:31 2022] [error] Unable to obtain semaphore.
                                                           [FAILED]

 

II. Solution

a. First check the semaphores allocated.

[root@ngelinux001 conf.d]# ipcs -u semaphores
------ Shared Memory Status --------
segments allocated 6
pages allocated 299
pages resident  296
pages swapped   2
Swap performance: 0 attempts     0 successes

------ Semaphore Status --------
used arrays = 127
allocated semaphores = 127

------ Messages: Status --------
allocated queues = 0
used headers = 0
used space = 0 bytes
[root@ngelinux001 conf.d]#

 

b. Checkout the shmid allocated.

[root@ngelinux001 conf.d]# ipcs -p

------ Shared Memory Creator/Last-op --------
shmid      owner      cpid       lpid
163840     postgres   10279      22208
84475905   root       28693      28693
262146     eldar      12487      30110
29622275   pvsqa      27022      17242
29655044   pvsqa      27022      27022
71958533   pvsqa      27273      19058


------ Message Queues PIDs --------
msqid      owner      lspid      lrpid

[root@ngelinux001 conf.d]#

 

c. Check semids and clear them.

[root@ngelinux001 conf.d]# ipcs -s
------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x00000000 0          root       600        1
0x00000000 32769      root       600        1
0x00000000 5799939    apache     600        1
0x00000000 163844     apache     600        1
0x00000000 196613     apache     600        1
0x00000000 229382     apache     600        1
0x00000000 262151     apache     600        1
0x00000000 294920     apache     600        1
0x00000000 393225     apache     600        1
0x00000000 425994     apache     600        1
0x00000000 458763     apache     600        1
0x00000000 491532     apache     600        1
0x00000000 524301     apache     600        1
0x00000000 622606     apache     600        1
0x00000000 655375     apache     600        1
0x00000000 688144     apache     600        1
0x00000000 720913     apache     600        1
0x00000000 753682     apache     600        1
0x00000000 851987     apache     600        1
0x00000000 884756     apache     600        1
0x00000000 917525     apache     600        1
0x00000000 950294     apache     600        1
0x00000000 983063     apache     600        1
0x00000000 1081368    apache     600        1
0x00000000 1114137    apache     600        1
0x00000000 1146906    apache     600        1
0x00000000 1179675    apache     600        1
0x00000000 1212444    apache     600        1
0x00004155 1245213    pvsqa      666        1
0x00000000 1343518    apache     600        1
0x00000000 1376287    apache     600        1
0x00000000 1409056    apache     600        1
0x00000000 1441825    apache     600        1
0x00000000 1474594    apache     600        1
0x00000000 1572899    apache     600        1
0x00000000 1605668    apache     600        1
0x00000000 1638437    apache     600        1
0x00000000 1671206    apache     600        1
0x00000000 1703975    apache     600        1
0x00000000 1802280    apache     600        1
0x00000000 1835049    apache     600        1
0x00000000 1867818    apache     600        1
0x00000000 1900587    apache     600        1
0x00000000 1933356    apache     600        1
0x00000000 2031661    apache     600        1
0x00000000 2064430    apache     600        1
0x00000000 2097199    apache     600        1
0x00000000 2129968    apache     600        1
0x00000000 2162737    apache     600        1
0x00000000 2261042    apache     600        1
0x00000000 2293811    apache     600        1
0x00000000 2326580    apache     600        1
0x00000000 2359349    apache     600        1
0x00000000 2392118    apache     600        1
0x00000000 2490423    apache     600        1
0x00000000 2523192    apache     600        1
0x00000000 2555961    apache     600        1
0x00000000 2588730    apache     600        1
0x00000000 2621499    apache     600        1
0x00000000 2719804    apache     600        1
0x00000000 2752573    apache     600        1
0x00000000 2785342    apache     600        1
0x00000000 2818111    apache     600        1
0x00000000 2850880    apache     600        1
0x00000000 2949185    apache     600        1
0x00000000 2981954    apache     600        1
0x00000000 3014723    apache     600        1
0x00000000 3047492    apache     600        1
0x00000000 3080261    apache     600        1
0x00000000 3178566    apache     600        1
0x00000000 3211335    apache     600        1
0x00000000 3244104    apache     600        1
0x00000000 3276873    apache     600        1
0x00000000 3309642    apache     600        1
0x00000000 3407947    apache     600        1
0x00000000 3440716    apache     600        1
0x00000000 3473485    apache     600        1
0x00000000 3506254    apache     600        1
0x00000000 3539023    apache     600        1
0x00000000 3637328    apache     600        1
0x00000000 3670097    apache     600        1
0x00000000 3702866    apache     600        1
0x00000000 3735635    apache     600        1
0x00000000 3768404    apache     600        1
0x00000000 3866709    apache     600        1
0x00000000 3899478    apache     600        1
0x00000000 3932247    apache     600        1
0x00000000 3965016    apache     600        1
0x00000000 3997785    apache     600        1
0x00000000 4096090    apache     600        1
0x00000000 4128859    apache     600        1
0x00000000 4161628    apache     600        1
0x00000000 4194397    apache     600        1
0x00000000 4227166    apache     600        1
0x00000000 4325471    apache     600        1
0x00000000 4358240    apache     600        1
0x00000000 4391009    apache     600        1
0x00000000 4423778    apache     600        1
0x00000000 4456547    apache     600        1
0x00000000 4554852    apache     600        1
0x00000000 4587621    apache     600        1
0x00000000 4620390    apache     600        1
0x00000000 4653159    apache     600        1
0x00000000 4685928    apache     600        1
0x00000000 4784233    apache     600        1
0x00000000 4817002    apache     600        1
0x00000000 4849771    apache     600        1
0x00000000 4882540    apache     600        1
0x00000000 4915309    apache     600        1
0x00000000 5013614    apache     600        1
0x00000000 5046383    apache     600        1
0x00000000 5079152    apache     600        1
0x00000000 5111921    apache     600        1
0x00000000 5144690    apache     600        1
0x00000000 5242995    apache     600        1
0x00000000 5275764    apache     600        1
0x00000000 5308533    apache     600        1
0x00000000 5341302    apache     600        1
0x00000000 5374071    apache     600        1
0x00000000 5472376    apache     600        1
0x00000000 5505145    apache     600        1
0x00000000 5537914    apache     600        1
0x00000000 5570683    apache     600        1
0x00000000 5603452    apache     600        1
0x00000000 5832829    apache     600        1
0x00000000 5865598    apache     600        1
0x00000000 5898367    apache     600        1
[root@ngelinux001 conf.d]#

 

d. Get PID of the semid

[root@ngelinux001 conf.d]# ipcs -s -i 5898367
Semaphore Array semid=5898367
uid=48   gid=48  cuid=0  cgid=0
mode=0600, access_perms=0600
nsems = 1
otime = Not set
ctime = Wed May 18 03:00:48 2022
semnum     value      ncount     zcount     pid
0          1          0          0          28693

 

e. Remove this semaphore

[root@ngelinux001 conf.d]# ipcrm -m 5898367
ipcrm: invalid id (5898367)

 

f. Remove all semaphores

[root@ngelinux001 conf.d]# for i in `ipcs -s | grep -i apache | awk '{print $2}'`; do ipcrm -m $i; done
ipcrm: already removed id (5799939)
ipcrm: already removed id (163844)
ipcrm: already removed id (196613)
ipcrm: invalid id (229382)
ipcrm: invalid id (262151)
ipcrm: invalid id (294920)
ipcrm: invalid id (393225)
ipcrm: invalid id (425994)
ipcrm: invalid id (458763)
ipcrm: invalid id (491532)
ipcrm: invalid id (524301)
ipcrm: invalid id (622606)
ipcrm: invalid id (655375)
ipcrm: invalid id (688144)
ipcrm: invalid id (720913)
ipcrm: invalid id (753682)

 

III. Permanent Fix: Increase the semaphore limit on server.

### Enter below two variables in sysctl.conf file.
# cat /etc/sysctl.conf
kernel.msgmni = 512
kernel.sem = 250 128000 32 512

### Print the new values.
# sysctl -p

 

IV. Restart the http service now and the error will be removed.

[root@ngelinux001 kernel]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: [Thu May 19 00:10:41 2022] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu May 19 00:10:41 2022] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
                                                           [OK]
[root@ngelinux001 kernel]#
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments