Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)

Rate this post

Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)

When first learning Asterisk some users will find they are unable to connect to the Asterisk service.

You may see the below message after running some variation of asterisk -r

Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)

The asterisk.ctl file

asterisk.ctl is a UNIX Domain Socket file. It is used to pass commands to an Asterisk process and it is how the Asterisk console (“asterisk r” or any variation) communicates with the back-end Asterisk process.

 

The /var/run/asterisk/ directory

This directory is the default Asterisk run directory. Asterisk will create it the first time it is run. This location is defined in the Asterisk Main Configuration File. As is explained in the Directory and File Structure section; when Asterisk is running, you’ll see two files here, asterisk.ctl and asterisk.pid. These are the control socket and the PID(Process ID) files for Asterisk.

Potential Causes and Solutions

Cause 1: asterisk.ctl does exist. Your user does not have write permission for this file.

Solution:

  1. To verify, check the permissions of the asterisk.ctl file and also check what user you are currently running as.
  2. Switch to the correct user that has access to the /var/run/asterisk/ directory and asterisk.ctl file, or provide your current user with the correct permissions.

Cause 2: Permissions issue. Asterisk does not have write access to /var/run/asterisk or your user doesn’t have write access to asterisk.ctl.

Solution:

  1. If /var/run/asterisk does not exist then create it and assign permission to it such that the user that runs Asterisk will have write and read access.
  2. If it already exists, simply verify and assign the correct permissions to the directory. You probably want to double-check what user runs Asterisk.

Cause 3: asterisk.ctl does not exist because Asterisk isn’t running. When Asterisk is started it may run briefly and then quickly halt due to an error.

Solution:

You need to find out what error is causing Asterisk to halt and resolve it.

  • The quick way is to run Asterisk in root/core console mode and watch for the last messages Asterisk prints out before halting.
    • asterisk -cvvvvv

      This will start Asterisk in console mode with level 5 verbosity. That should give you plenty to look at.

  • Another way is to setup Asterisk Logging to log what you want to see to a file. You’ll need to read up on Asterisk’s Logging Configuration
  • Asterisk could halt for a variety of reasons. The last messages you see before Asterisk halts will give you a clue. Then you can Google from there or ask the user community.

Cause 4: SELinux enabled and not properly configured for Asterisk. SELinux not allowing asterisk.ctl to be created.

Solution:

Configuring SELinux is outside the scope of this article.

  • Consult an experienced SELinux user or SELinux documentation on how to configure it properly.
  • Disable SELinux if you don’t require it (Not recommended)
 Other Solution:


It’s probably because asterisk is not running on your server.

Try to run it with this command :

asterisk -vvvvvvc

You’ll enter into the Asterisk CLI and if something goes wrong you’ll see it. After that you can quit the CLI by entering the exit command. Then you can reconnect to the CLI by typing asterisk -r. All this commands assumed you’re the root user. If you are not root prefix them by sudo, by example sudo asterisk -vvvvvvc.


This could be due to an ownership problem

try to:

ls -l /var/run/asterisk/asterisk.ctl

you will see that the file has ownership of ‘root’

although you have changed the ownership with:

chown -R asterisk /var/run/asterisk

once you restart the asterisk server the ownership gets back to the ‘root’ again

they should be for ‘asterisk:asterisk’ user and group


 

For any query or issue, feel free to discuss on http://discuss.eduguru.in

Leave a Reply

%d bloggers like this: