How can I create a service in CentOS 6?












1















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










share|improve this question




















  • 2





    Init system in your Centos 6 is probably not systemd and you need to work with /etc/init.d/ instead of systemd units. Please study How to find out if a system uses SysV, Upstart or Systemd initsystem, Detect init system using the shell and edit your question to tell us what it is.

    – Kamil Maciorowski
    Jan 19 '18 at 16:44











  • Thanks @KamilMaciorowski Yes.i understand i would need to use /etc/init.d .My question was how can i write the above service in init.d in centos 6?

    – Faryal Gohar
    Jan 19 '18 at 21:04











  • What research have you done? On Google there are dozens of resources on how to write an init script for CentOS 6.

    – mtak
    Jan 19 '18 at 21:27











  • @FaryalGohar did you found the answer of this question? I also need this service in CENTOS 6.

    – munjal
    Jan 31 at 5:02
















1















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










share|improve this question




















  • 2





    Init system in your Centos 6 is probably not systemd and you need to work with /etc/init.d/ instead of systemd units. Please study How to find out if a system uses SysV, Upstart or Systemd initsystem, Detect init system using the shell and edit your question to tell us what it is.

    – Kamil Maciorowski
    Jan 19 '18 at 16:44











  • Thanks @KamilMaciorowski Yes.i understand i would need to use /etc/init.d .My question was how can i write the above service in init.d in centos 6?

    – Faryal Gohar
    Jan 19 '18 at 21:04











  • What research have you done? On Google there are dozens of resources on how to write an init script for CentOS 6.

    – mtak
    Jan 19 '18 at 21:27











  • @FaryalGohar did you found the answer of this question? I also need this service in CENTOS 6.

    – munjal
    Jan 31 at 5:02














1












1








1








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










share|improve this question
















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







linux centos services centos-6 centos-7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 '18 at 21:11







Faryal Gohar

















asked Jan 19 '18 at 16:09









Faryal GoharFaryal Gohar

913




913








  • 2





    Init system in your Centos 6 is probably not systemd and you need to work with /etc/init.d/ instead of systemd units. Please study How to find out if a system uses SysV, Upstart or Systemd initsystem, Detect init system using the shell and edit your question to tell us what it is.

    – Kamil Maciorowski
    Jan 19 '18 at 16:44











  • Thanks @KamilMaciorowski Yes.i understand i would need to use /etc/init.d .My question was how can i write the above service in init.d in centos 6?

    – Faryal Gohar
    Jan 19 '18 at 21:04











  • What research have you done? On Google there are dozens of resources on how to write an init script for CentOS 6.

    – mtak
    Jan 19 '18 at 21:27











  • @FaryalGohar did you found the answer of this question? I also need this service in CENTOS 6.

    – munjal
    Jan 31 at 5:02














  • 2





    Init system in your Centos 6 is probably not systemd and you need to work with /etc/init.d/ instead of systemd units. Please study How to find out if a system uses SysV, Upstart or Systemd initsystem, Detect init system using the shell and edit your question to tell us what it is.

    – Kamil Maciorowski
    Jan 19 '18 at 16:44











  • Thanks @KamilMaciorowski Yes.i understand i would need to use /etc/init.d .My question was how can i write the above service in init.d in centos 6?

    – Faryal Gohar
    Jan 19 '18 at 21:04











  • What research have you done? On Google there are dozens of resources on how to write an init script for CentOS 6.

    – mtak
    Jan 19 '18 at 21:27











  • @FaryalGohar did you found the answer of this question? I also need this service in CENTOS 6.

    – munjal
    Jan 31 at 5:02








2




2





Init system in your Centos 6 is probably not systemd and you need to work with /etc/init.d/ instead of systemd units. Please study How to find out if a system uses SysV, Upstart or Systemd initsystem, Detect init system using the shell and edit your question to tell us what it is.

– Kamil Maciorowski
Jan 19 '18 at 16:44





Init system in your Centos 6 is probably not systemd and you need to work with /etc/init.d/ instead of systemd units. Please study How to find out if a system uses SysV, Upstart or Systemd initsystem, Detect init system using the shell and edit your question to tell us what it is.

– Kamil Maciorowski
Jan 19 '18 at 16:44













Thanks @KamilMaciorowski Yes.i understand i would need to use /etc/init.d .My question was how can i write the above service in init.d in centos 6?

– Faryal Gohar
Jan 19 '18 at 21:04





Thanks @KamilMaciorowski Yes.i understand i would need to use /etc/init.d .My question was how can i write the above service in init.d in centos 6?

– Faryal Gohar
Jan 19 '18 at 21:04













What research have you done? On Google there are dozens of resources on how to write an init script for CentOS 6.

– mtak
Jan 19 '18 at 21:27





What research have you done? On Google there are dozens of resources on how to write an init script for CentOS 6.

– mtak
Jan 19 '18 at 21:27













@FaryalGohar did you found the answer of this question? I also need this service in CENTOS 6.

– munjal
Jan 31 at 5:02





@FaryalGohar did you found the answer of this question? I also need this service in CENTOS 6.

– munjal
Jan 31 at 5:02










2 Answers
2






active

oldest

votes


















0














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






share|improve this answer































    -2














    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





    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1287147%2fhow-can-i-create-a-service-in-centos-6%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      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






      share|improve this answer




























        0














        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






        share|improve this answer


























          0












          0








          0







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '18 at 17:12









          ancmancm

          11




          11

























              -2














              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





              share|improve this answer






























                -2














                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





                share|improve this answer




























                  -2












                  -2








                  -2







                  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





                  share|improve this answer















                  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






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 24 '18 at 15:42









                  Darren

                  2,0201123




                  2,0201123










                  answered Jan 24 '18 at 12:03









                  bala4rtrainingbala4rtraining

                  11




                  11






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1287147%2fhow-can-i-create-a-service-in-centos-6%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to make a Squid Proxy server?

                      Is this a new Fibonacci Identity?

                      Touch on Surface Book