<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>Eric&#039;s Blog - 默认分类</title>
<link>https://eblog.ink/category/default/</link>
<atom:link href="https://eblog.ink/feed/category/default/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description>只是一个默认分类</description>
<lastBuildDate>Fri, 22 Nov 2024 06:30:00 +0000</lastBuildDate>
<pubDate>Fri, 22 Nov 2024 06:30:00 +0000</pubDate>
<item>
<title>Windows Linux服务方式启动程序</title>
<link>https://eblog.ink/archives/391/</link>
<guid>https://eblog.ink/archives/391/</guid>
<pubDate>Fri, 22 Nov 2024 06:30:00 +0000</pubDate>
<dc:creator>eric</dc:creator>
<description><![CDATA[场景：很多时候软件需要开机自动启动，在不登录账号的时候启动Windows方法1：1.所需软件nssm.exenssm.exe install 《服务名称》 &quot;C:\Windows\Sy...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<h1>场景：</h1><p>很多时候软件需要开机自动启动，在不登录账号的时候启动</p><h1>Windows</h1><h2>方法1：</h2><p>1.所需软件<code>nssm.exe</code></p><pre><code>nssm.exe install 《服务名称》 &quot;C:\Windows\System32\cmd.exe&quot; &quot;/c  cd /d 《所要运行软件的目录》&quot; &amp;《软件名.exe》 --参数&quot;
</code></pre><h2>方法2：</h2><p>1.所需软件<code>WinSW-x64.exe</code></p><p>2.修改WinSW-x64.xml文件</p><pre><code>1.&lt;id&gt; 和 &lt;name&gt;
    定义了服务的唯一标识和显示名称，这些值应在系统中保持唯一。

2.&lt;description&gt;

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

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

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

5.&lt;startmode&gt;
    定义服务的启动模式：
    Automatic 表示系统启动时服务会自动启动。
</code></pre><p>3.生成服务</p><pre><code>WinSW-x64.exe install
</code></pre><h1>Openwrt</h1><p>1.以vnts为例，<code>vi /etc/init.d/vnts</code></p><p>▲</p><pre><code>#!/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;
}

</code></pre><p>▲</p><pre><code>#!/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;
}
</code></pre><p>2.运行脚本并后台管理：</p><p>将脚本以服务方式启用，确保启动时进入后台运行。</p><pre><code>/etc/init.d/vnts enable
/etc/init.d/vnts start
</code></pre><p>所需文件：<a href="https://kingq.lanzouq.com/i9EFH2fuvobe">下载</a></p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://eblog.ink/archives/391/#comments</comments>
<wfw:commentRss>https://eblog.ink/feed/category/default/</wfw:commentRss>
</item>
</channel>
</rss>