How can I create a service in CentOS 6?
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
add a comment |
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
2
Init system in your Centos 6 is probably notsystemd
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
add a comment |
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
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
linux centos services centos-6 centos-7
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 notsystemd
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
add a comment |
2
Init system in your Centos 6 is probably notsystemd
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
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Dec 28 '18 at 17:12
ancmancm
11
11
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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 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
edited Jan 24 '18 at 15:42
Darren
2,0201123
2,0201123
answered Jan 24 '18 at 12:03
bala4rtrainingbala4rtraining
11
11
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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