Linux:将流程转化为服务 [英] Linux: process into a service

查看:151
本文介绍了Linux:将流程转化为服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将linux可执行文件作为服务

I am trying to make a linux executable as a service

我在下面执行我的程序

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上执行此操作的最常见方法是构建一个初始化脚本并将其放置在/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.

这是示例初始化脚本:

#!/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆