linux add service service, set from the start
reprint: October 16, 2018 15:02:00 weixin_34174132 Reads: 2
location and file: /etc/init.d/idea
IDEA
# / bin / SH!
# Chkconfig: 2345 80 90
# the Description: idea the Register Server
Start)
SH /usr/local/idea/start.sh
;;
STOP)
PS -ef | grep IDEA | grep -v grep | awk 'Print $ {2}' | xargs the kill
;;
Esac
# the chkconfig, # description not less, need to set up from the start.
Service starts: service idea start
service shut down: service idea shutdown
set from the start: chkconfig idea on
close from the start: chkconfig idea off
linux add your own services to the system service service
linux add your own services to the system service service
Foreword
We want to start a program on linux was time to write a bunch of paths are often found to have to start the service program, and then ./*** start the service. Then we have no way to do this quick start, the answer is yes too
service introduction
The official description (English): https://linux.die.net/man/8/service
Briefly about the service process to run iptables for example:. Service iptables start
- First, sevice will go to /etc/init.d looking iptables script, start iptables script is a parameter (you can go to see the script parameters networking support)
- Then tell the system to run this iptables script, the rest of the things to sit iptables script, and the fact is that simple.
At this point, you should know how to add a command bar service
Write a script, and then put it in the /etc/init.d directory, then service + script name to run. If it is to have to use it at startup commands chkconfig
Note:
A, this command is often Service with immediate effect, do not switch, but after the restart the service will return to the default state.
B, in init.d there was no script name suffix
Set at startup
--add the Test chkconfig chkconfig the Test ON / OFF // restart permanent
The above does not take effect: you have to use the following method
Update-rc.d named by setting the boot from the start
cd /etc/init.d sudo update-rc.d test defaults 95
Note: where the number 95 is a script to start the sequence number, according to their needs can be modified accordingly. In you have multiple startup script, but when there are dependencies between them has started you will know the specific role of this figure. Output information with reference to the following:
update-rc.d: warning: /etc/init.d/test missing LSB information update-rc.d: see <http://wiki.debian.org/LSBInitScripts> Adding system startup for /etc/init.d/test ... /etc/rc0.d/K95test -> ../init.d/test /etc/rc1.d/K95test -> ../init.d/test /etc/rc6.d/K95test -> ../init.d/test /etc/rc2.d/S95test -> ../init.d/test /etc/rc3.d/S95test -> ../init.d/test /etc/rc4.d/S95test -> ../init.d/test /etc/rc5.d/S95test -> ../init.d/test
Uninstall startup script:
cd /etc/init.d sudo update-rc.d -f test remove
Command output reference to the following information:
Removing any system startup links for /etc/init.d/test ... /etc/rc0.d/K95test /etc/rc1.d/K95test /etc/rc2.d/S95test /etc/rc3.d/S95test /etc/rc4.d/S95test /etc/rc5.d/S95test /etc/rc6.d/K95test
Common mistakes:
1. When prompted to start the service task: Program-service: out with unrecognized service
This is because we do not have to change the script execute permissions for the executable. After re-execute the commandchmod +x /etc/init.d/serviceName
2. When prompted to add a start-up task: Service does not Support chkconfig ***
[root @ redis01 the Test] # chkconfig --add the Test Service does not Support the Test chkconfig solution :( add two lines of comments in /etc/init.d/test) #! / bin / SH two-line comments to add the following content # : # chkconfig: 2345 90 10 # the Description: the Test iS a persistent Key-value Database # comment mean, test service must be enabled or disabled at run level 2,3,4,5, start priority is 90, Close priority is 10 [root @ redis01 the Test] # chkconfig --add the Test [root @ redis01 the Test] # echo $? 0 [root @ redis01 the Test] # chkconfig --list | grep the Test the Test 0: OFF1: off2: on3: on4: on5: on6: off
When editing other similar services, but also may be the case, the solution substantially similar
reference:
Solve "service XXX does not support chkconfig" problem
In order to facilitate the management services on the linux server, a lot of people like to use this way service nginx start to manage, it is a system service
so that you can set to automatically start
Software service script compiler installed were located in / usr / local under / sbin directory, for example,
Commands
So many times we've created a script, right after he copied to /etc/init.d after using chkconfig --add nginx when such errors occur below
That solution is as follows:
Add the following two lines to the beginning of the script:
Do not remove the pound sign.
Why the service does not support chkconfig, there is another very important
is executable permissions
Foreword
We want to start a program on linux was time to write a bunch of paths are often found to have to start the service program, and then ./*** start the service. Then we have no way to do this quick start, the answer is yes too
service introduction
The official description (English): https://linux.die.net/man/8/service
Briefly about the service process to run iptables for example:. Service iptables start
- First, sevice will go to /etc/init.d looking iptables script, start iptables script is a parameter (you can go to see the script parameters networking support)
- Then tell the system to run this iptables script, the rest of the things to sit iptables script, and the fact is that simple.
At this point, you should know how to add a command bar service
Write a script, and then put it in the /etc/init.d directory, then service + script name to run. If it is to have to use it at startup commands chkconfig
Note:
A, this command is often Service with immediate effect, do not switch, but after the restart the service will return to the default state.
B, in init.d there was no script name suffix
Set at startup
--add the Test chkconfig chkconfig the Test ON / OFF // restart permanent
The above does not take effect: you have to use the following method
Update-rc.d named by setting the boot from the start
cd /etc/init.d sudo update-rc.d test defaults 95
Note: where the number 95 is a script to start the sequence number, according to their needs can be modified accordingly. In you have multiple startup script, but when there are dependencies between them has started you will know the specific role of this figure. Output information with reference to the following:
update-rc.d: warning: /etc/init.d/test missing LSB information update-rc.d: see <http://wiki.debian.org/LSBInitScripts> Adding system startup for /etc/init.d/test ... /etc/rc0.d/K95test -> ../init.d/test /etc/rc1.d/K95test -> ../init.d/test /etc/rc6.d/K95test -> ../init.d/test /etc/rc2.d/S95test -> ../init.d/test /etc/rc3.d/S95test -> ../init.d/test /etc/rc4.d/S95test -> ../init.d/test /etc/rc5.d/S95test -> ../init.d/test
Uninstall startup script:
cd /etc/init.d sudo update-rc.d -f test remove
Command output reference to the following information:
Removing any system startup links for /etc/init.d/test ... /etc/rc0.d/K95test /etc/rc1.d/K95test /etc/rc2.d/S95test /etc/rc3.d/S95test /etc/rc4.d/S95test /etc/rc5.d/S95test /etc/rc6.d/K95test
Common mistakes:
1. When prompted to start the service task: Program-service: out with unrecognized service
This is because we do not have to change the script execute permissions for the executable. After re-execute the commandchmod +x /etc/init.d/serviceName
2. When prompted to add a start-up task: Service does not Support chkconfig ***
[root @ redis01 the Test] # chkconfig --add the Test Service does not Support the Test chkconfig solution :( add two lines of comments in /etc/init.d/test) #! / bin / SH two-line comments to add the following content # : # chkconfig: 2345 90 10 # the Description: the Test iS a persistent Key-value Database # comment mean, test service must be enabled or disabled at run level 2,3,4,5, start priority is 90, Close priority is 10 [root @ redis01 the Test] # chkconfig --add the Test [root @ redis01 the Test] # echo $? 0 [root @ redis01 the Test] # chkconfig --list | grep the Test the Test 0: OFF1: off2: on3: on4: on5: on6: off
When editing other similar services, but also may be the case, the solution substantially similar
reference: