5

I need to create ratchet service on my dedicated server (CentOS 6). I have successfully created this service on local CentOS 7. The problem is that the server has got old version of CentOS and I need to create a service there.

I have taken the following steps to create a service in CentOS 7:

Created a file named ratchet.service in /etc/systemd/system/ and put the following in it:

[Unit]
Description=Ratchet Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/php -f /path/to/ratchet/server$
Restart=on-abort

[Install]
WantedBy=multi-user.target

To start:

service ratchet start

Can anyone please advise how can this be achieved in CentOS 6?

UPDATE: What i am trying to achieve is to run Ratchet Service written in php.I want to run this service on Centos 6 so that it can run persistently on my server. I need to execute server file script (named above as /path/to/ratchet/server.php).

I am following this tutorial and code : https://github.com/amirsanni/Video-Call-App

3

2 Answers 2

8

I'll provide the basic service script but anyone is invited to improve my answer.

This is for CentOS 6.10

The service scripts are placed in this directory: /etc/rc.d/init.d

There's a template provided by the system, open the file with your editor of choice (example vi): vi /usr/share/doc/initscripts-*/sysvinitfiles

Here's a simple example of my kafka script:

#!/bin/bash
#/etc/rc.d/init.d/kafka

# Source function library.
. /etc/init.d/functions


start() {
        echo -n "Starting kafka... "
        nohup /home/kafka/kafka/bin/kafka-server-start.sh /home/kafka/kafka/config/server.properties &
        touch /var/lock/subsys/kafka
        return 0
}

stop() {
        echo -n "Shutting down kafka... "
        nohup /home/kafka/kafka/bin/kafka-server-stop.sh &
        rm -f /var/lock/subsys/kafka
        return 0
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        ;;
    restart)
        stop
        start
        ;;
    reload)
        ;;
    *)
        echo "Usage: kafka {start|stop|status|reload|restart}"
 exit 1
        ;;
esac
exit $?

Based on this kafka example, this file should be saved as /etc/rc.d/init.d/kafka

I run it by typing: service kafka start

-1

You can write the init script logic in vi editor & save in /etc/init.d path, as shown below:-

vi /etc/init.d/ratchet

write your start/stop/restart logic here

Once done, you can start the service

service ratchet start

or

/etc/init.d/rachet start

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .