Ubuntu 增加服务 比如openfire

在Ubuntu上,可以使用systemd来管理和配置服务。下面是将命令添加为服务的一般步骤:

创建一个.service文件,该文件描述了您要添加的服务。打开终端,并使用以下命令创建一个新的服务文件:

sudo nano /etc/systemd/system/my-service.service

在打开的文件中,输入以下内容(请根据您的需求进行适当修改):

Unit

Description=My Service

After=network.target

Service

ExecStart=/path/to/your/command

WorkingDirectory=/path/to/working/directory

Restart=always

Install

WantedBy=multi-user.target

Description:服务的简短描述。

After:指定服务应在哪个目标之后启动(例如network.target表示在网络连接之后启动)。

ExecStart:要执行的命令或脚本的路径。

WorkingDirectory:命令执行的工作目录。

Restart:定义服务在发生错误或停止后是否应自动重启。

WantedBy:指定服务所属的目标。

保存并关闭文件。使用Ctrl + X,然后按Y确认保存,最后按Enter键退出编辑器。

让系统重新加载systemd服务配置:

sudo systemctl daemon-reload

启动服务并设置其在系统启动时自动启动:

sudo systemctl start my-service

sudo systemctl enable my-service

start:启动服务。

enable:设置服务在系统启动时自动启动。

现在,您的命令已经以服务的形式添加到Ubuntu中,并且可以通过systemctl命令启动、停止和管理该服务。例如:

sudo systemctl start my-service # 启动服务

sudo systemctl stop my-service # 停止服务

sudo systemctl restart my-service # 重启服务

sudo systemctl status my-service # 查看服务状态


针对openfire,下载的tar.gz解压缩文件目录如下:

复制代码
root@QHTProxy:/opt/openfire/bin# ls
extra  openfire  openfire.sh  openfirectl

在/etc/systemd/system下面新建文件 openfired.service

bash 复制代码
root@QHTProxy:/opt/openfire/bin#  cat /etc/systemd/system/openfired.service 
[Unit]
Description=OpenFire
After=network.target

[Service]
ExecStart=/opt/openfire/bin/openfire.sh
WorkingDirectory=/opt/openfire/bin
Restart=always

[Install]
WantedBy=multi-user.target

增加可执行权限

bash 复制代码
root@QHTProxy:/opt/openfire/bin# chmod a+x /etc/systemd/system/openfired.service

重新加载systemd服务配置

bash 复制代码
root@QHTProxy:/opt/openfire/bin# systemctl daemon-reload

开启服务:

bash 复制代码
root@QHTProxy:/opt/openfire/bin# systemctl start  openfired 

root@QHTProxy:/opt/openfire/bin# systemctl status  openfired 
● openfired.service - OpenFire
   Loaded: loaded (/etc/systemd/system/openfired.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2023-11-03 11:00:20 CST; 8s ago
 Main PID: 2702 (java)
    Tasks: 59
   Memory: 289.8M
      CPU: 13.435s
   CGroup: /system.slice/openfired.service
           └─2702 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Dlog4j.configurationFile=/opt/openfire/lib/log4j2.xml -Dlog4j2.formatMsgNoLookups=true -Djdk.tls.ephemeralDHKeySize=matched -Djsse.S

Nov 03 11:00:20 QHTProxy systemd[1]: Started OpenFire.
Nov 03 11:00:20 QHTProxy openfire.sh[2702]: /opt/openfire/bin/openfire.sh: 21: /opt/openfire/bin/openfire.sh: shopt: not found
Nov 03 11:00:23 QHTProxy openfire.sh[2702]: Openfire 4.7.5 [2023-11-3 11:00:23]
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: 管理平台开始监听:
Nov 03 11:00:24 QHTProxy openfire.sh[2702]:   http://qhtproxy:9090
Nov 03 11:00:24 QHTProxy openfire.sh[2702]:   https://qhtproxy:9091
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: Successfully loaded plugin 'admin'.
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: Successfully loaded plugin 'search-1.7.3'.
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: Successfully loaded plugin 'userimport
相关推荐
dessler26 分钟前
Elasticsearch(ES)Cerebro部署和使用
linux·运维·elasticsearch
an869500142 分钟前
ubuntu 安装 JDK8
linux·运维·ubuntu
weixin_436525071 小时前
Docker 镜像导出与导入教程(Windows - Linux)
运维·docker·容器
小鹿学程序1 小时前
虚拟机之间配置免密登录(Centos)
大数据·linux·运维·centos
边疆.2 小时前
【Linux】编辑器vim的使用和理解gcc编译器
linux·运维·服务器·编辑器·vim
z10_142 小时前
什么是住宅IP,住宅IP应用场景有哪些
linux·服务器·tcp/ip
羑悻的小杀马特2 小时前
从零搭建群晖私有影音库:NasTool自动化追剧全流程拆解与远程访问协议优化实践
运维·数据库·自动化
雾江流2 小时前
快指点击器 1.1.9 | 支持多点操作、自动化脚本,操作记录等功能,快速解放双手
运维·自动化·软件工程
孙同学要努力2 小时前
《Linux篇》命令行参数与环境变量
linux·运维