<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel rdf:about="https://eblog.ink/feed/rss/category/default/">
<title>Eric&#039;s Blog - 默认分类</title>
<link>https://eblog.ink/category/default/</link>
<description>只是一个默认分类</description>
<items>
<rdf:Seq>
<rdf:li resource="https://eblog.ink/archives/391/"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="https://eblog.ink/archives/391/">
<title>Windows Linux服务方式启动程序</title>
<link>https://eblog.ink/archives/391/</link>
<dc:date>2024-11-22T06:30:00+00:00</dc:date>
<description>场景：很多时候软件需要开机自动启动，在不登录账号的时候启动Windows方法1：1.所需软件nssm.exenssm.exe install 《服务名称》 &quot;C:\Windows\System32\cmd.exe&quot; &quot;/c  cd /d 《所要运行软件的目录》&quot; &amp;《软件名.exe》 --参数&quot;
方法2：1.所需软件WinSW-x64.exe2.修改WinSW-x64.xml文件1.&lt;id&gt; 和 &lt;name&gt;
    定义了服务的唯一标识和显示名称，这些值应在系统中保持唯一。

2.&lt;description&gt;

    服务的描述，将显示在服务管理器中，帮助用户理解服务的用途。

3.&lt;executable&gt;
    指定要执行的主程序路径
    确保程序位于配置文件的相同目录，或使用绝对路径。

4.&lt;arguments&gt;
    向主程序传递的参数

5.&lt;startmode&gt;
    定义服务的启动模式：
    Automatic 表示系统启动时服务会自动启动。
3.生成服务WinSW-x64.exe install
Openwrt1.以vnts为例，vi /etc/init.d/vnts▲#!/bin/sh /etc/rc.common
# 开头定义
START=99
STOP=10

start() {
    echo &quot;Starting vnts with parameters...&quot;
    /path/to/vnts --param1 value1 --param2 value2
}
my_pkill() {
    ps | grep &quot;$1&quot; | grep -v &quot;grep&quot; | awk &#039;{print $1}&#039; | while read -r pid; do
        kill -9 &quot;$pid&quot;
    done
}
stop() {
    echo &quot;Stopping vnts...&quot;
    my_pkill &quot;vnt-cli&quot;
}

▲#!/bin/sh /etc/rc.common
START=99

start() {
    echo &quot;Starting vnts with auto-restart loop...&quot;
    # 检查是否已有后台监控脚本运行，避免重复
    if pgrep -f &quot;sh /etc/init.d/vnt start&quot; &gt; /dev/null; then
        echo &quot;vnt monitor already running.&quot;
        return 0
    fi

    # 启动后台监控
    nohup sh -c &#039;
    while true; do
        if ! pgrep -x &quot;/root/vnt/vnt-cli&quot; &gt; /dev/null; then
            echo &quot;$(date &quot;+%Y-%m-%d %H:%M:%S&quot;) vnt not running, starting...&quot; &gt;&gt; /root/vnt/vnt.log
            nohup /path/to/vnts --param1 value1 --param2 value2 &gt;&gt; /root/vnt/vnt.log 2&gt;&amp;1 &amp;
        fi
        sleep 60
    done
    &#039; &gt;&gt; /root/vnt/vnt.log 2&gt;&amp;1 &amp;
}

my_pkill() {
    ps | grep &quot;$1&quot; | grep -v &quot;grep&quot; | awk &#039;{print $1}&#039; | while read -r pid; do
        kill -9 &quot;$pid&quot;
    done
}

stop() {
    echo &quot;Stopping vnt...&quot;
    my_pkill &quot;vnt-cli&quot;
    # 杀掉监控循环
    my_pkill &quot;sh /etc/init.d/vnt start&quot;
}
2.运行脚本并后台管理：将脚本以服务方式启用，确保启动时进入后台运行。/etc/init.d/vnts enable
/etc/init.d/vnts start
所需文件：下载</description>
</item>
</rdf:RDF>