Linux:处理成服务 [英] Linux: process into a service
问题描述
我正在尝试将 linux 可执行文件作为服务
I am trying to make a linux executable as a service
我像下面这样执行我的程序
I execute my program like this below
java -jar mytestprogram.jar
创建一个持续运行并为 REST 请求提供服务的进程.但我想将它作为一项服务来运行
creates a process that runs continuously and serves REST requests. But I want to run it as a service where I can do
service mytestprogram start
service mytestprogram stop
service mytestprogram status
chkconfig mytestprogram on
等等.最简单的方法是什么?
etc. What is the most simple way of doing it?
推荐答案
这取决于你的系统管理员
That depends on your system manager
在 debian/ubuntu 上执行此操作的最常见方法是构建一个 initscript 并将其放置在 /etc/init.d
或 /etc/rc/init.d
并在其中放置一个名为 mytestprogram
的脚本.
the most common way to do that on debian/ubuntu is to build an initscript and place it in /etc/init.d
or /etc/rc/init.d
and place a script named mytestprogram
in that.
这是一个示例初始化脚本:
this is an example initscript:
#!/bin/sh
### BEGIN INIT INFO
# Provides: testone
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: Example init script
# Description: Start/stop an example script
### END INIT INFO
DESC="test script"
NAME=testone
#DAEMON=
do_start()
{
echo "starting!";
}
do_stop()
{
echo "stopping!"
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
esac
exit 0
建议你看看那个目录下的一些脚本,如果你懂一点bash就简单了;)
I suggest you to look some scripts in that directory, It's simple if you know bash a little ;)
这篇关于Linux:处理成服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!