Build custom systemctl service command


Let’s create a service command in linux to execute the Laravel queue listen command.

php artisan queue:listen

Lets start 🙂

STEP 1: Create bash script for Laravel php artisan queue:listen

Create a bash script to any preferred location in server. I preferred to create in /root as a root user.

$ sudo su –

$ vim /root/


In file


cd /path/to/laravel/project

php artisan queue:listen


Save the file and change the file mode executable.

$ chmod +x /root/

STEP 2: Create .service

Create a service .service file named ays_queue.service. 

$ sudo vim  /etc/systemd/system/ays_queue.service

In ays_queue.service file

Description=AYS Laravel queue listen service

ExecStart=/bin/sh /root/


Here, ‘’ refers the service create can can be executed by any user in the system.

Now, once .service file created the system should reload the daemon.

$ systemctl daemon-reload

To verify, the system service working following commands can be executed

$ systemctl status ays_queue
$ systemctl start ays_queue
$ systemctl stop ays_queue
$ systemctl restart ays_queue

STEP 4: Check and re-start command

In advance, one more step to check the command and start the service in case of inactive.

Create a new bash file again in /root named

$ sudo vim /root/

In file


CHECKQUEUE=$(systemctl is-active ays_queue)

if [ $CHECKQUEUE = ‘active’ ]; then
echo ‘active’
systemctl restart ays_queue

Also, make file executable.

$ sudo chmod +x /root/

You can add in crontabs to check the status and restart the service in case of inactive. In this way, your service will never stops.