AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[sysvinit](unix)

Martin Hope
Muhammad Ikhwan Perwira
Asked: 2022-05-23 01:48:35 +0800 CST

自动检测网络接口卡,network init.d

  • 0

我已经根据本书构建了我的 LFS linux ,它工作正常,网络接口卡也在工作。即使它使用dhcpcd服务自动配置IP。

根据那本书的第9章,有一个文件叫做

/etc/sysconfig/ifconfig.eth0 问题是,如果我正在使用wlan0,我是否需要手动修改配置文件或将 eth0 重命名为 wlan0 每次更改网络接口卡,我希望它会自动检测到

这里是由 LFS 书籍生成的初始化网络脚本,/etc/init.d/network与/etc/sysconfig/ifconfig.*

### BEGIN INIT INFO
# Provides:            $network
# Required-Start:      $local_fs localnet swap
# Should-Start:        $syslog firewalld iptables nftables
# Required-Stop:       $local_fs localnet swap
# Should-Stop:         $syslog firewalld iptables nftables
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   Starts and configures network interfaces.
# Description:         Starts and configures network interfaces.
# X-LFS-Provided-By:   LFS
### END INIT INFO

case "${1}" in
   start)
      # Start all network interfaces
      for file in /etc/sysconfig/ifconfig.*
      do
         interface=${file##*/ifconfig.}

         # Skip if $file is * (because nothing was found)
         if [ "${interface}" = "*" ]; then continue; fi

         /sbin/ifup ${interface}
      done
      ;;

   stop)
      # Unmount any network mounted file systems
       umount --all --force --types nfs,cifs,nfs4

      # Reverse list
      net_files=""
      for file in  /etc/sysconfig/ifconfig.*
      do
         net_files="${file} ${net_files}"
      done

      # Stop all network interfaces
      for file in ${net_files}
      do
         interface=${file##*/ifconfig.}

         # Skip if $file is * (because nothing was found)
         if [ "${interface}" = "*" ]; then continue; fi

         # See if interface exists
         if [ ! -e /sys/class/net/$interface ]; then continue; fi

         # Is interface UP?
         ip link show $interface 2>/dev/null | grep -q "state UP"
         if [ $? -ne 0 ];  then continue; fi

         /sbin/ifdown ${interface}
      done
      ;;

   restart)
      ${0} stop
      sleep 1
      ${0} start
      ;;

   *)
      echo "Usage: ${0} {start|stop|restart}"
      exit 1
      ;;
esac

exit 0

# End network
network-interface sysvinit
  • 1 个回答
  • 75 Views
Martin Hope
nirolo
Asked: 2019-08-31 12:58:16 +0800 CST

为什么我的 init.d 脚本在手动调用时有效,但在启动时无效?

  • 1

我的目标

在启动时使用参数运行 x.flux

我的尝试

一个 init.d 脚本。它可以通过手动调用

sudo /etc/init.d/xflux start
[ ok ] Starting xflux (via systemctl): xflux.service.

我的问题

程序“x.flux”在启动后没有正常运行,即屏幕没有按预期变红。在 cli 中使用相同的参数启动后手动调用它可以按预期工作。

日志和假设

我收到

sudo service xflux status
● xflux.service - LSB: xflux start script
   Loaded: loaded (/etc/init.d/xflux; generated; vendor preset: enabled)
   Active: inactive (dead) since [...] CEST; 18min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 4153 ExecStop=/etc/init.d/xflux stop (code=exited, status=0/SUCCESS)
  Process: 4065 ExecStart=/etc/init.d/xflux start (code=exited, status=0/SUCCESS)

systemd[1]: Starting LSB: xflux start script...
xflux[4065]: Couldn't open display (null)
xflux[4065]: .
xflux[4065]: [10B blob data]
xflux[4065]: --------
xflux[4065]: Welcome to xflux (f.lux for X)
xflux[4065]: This will only work if you're running X on console.
systemd[1]: Started LSB: xflux start script.
systemd[1]: Stopping LSB: xflux start script...
systemd[1]: Stopped LSB: xflux start script.

所以这可能是can-not-open-display-null-error-how-can-i-fix-this但我不明白如何解决这个问题,如果它确实是问题。

剧本

为了完成这里的脚本

#! /bin/sh
### BEGIN INIT INFO
# Provides:          xflux
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: xflux start script
### END INIT INFO

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Description of the service"
NAME=xflux
RUNDIR=/usr/local/bin/$NAME
DAEMON=/usr/local/bin/$NAME
DAEMON_ARGS="hereGoesMyLocationAsParam"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
        $DAEMON_ARGS \
        || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently.  A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
  #reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    #log_daemon_msg "Reloading $DESC" "$NAME"
    #do_reload
    #log_end_msg $?
    #;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
esac

:
shell sysvinit
  • 1 个回答
  • 984 Views
Martin Hope
Biswapriyo
Asked: 2019-03-21 12:08:25 +0800 CST

如何在不编辑初始化脚本的情况下更改 SysVinit 服务?

  • 2

假设服务是xyz. 在 systemd 中,该/lib/systemd/system/xyz.service 文件具有以下命令:

[Service]
ExecStart=/usr/bin/xyz --foo

我想--bar在该命令中添加选项。/etc/systemd/system/xyz.service.d/xyz.conf使用 systemd,我可以在插入文件中添加以下几行:

[Service]
ExecStart=
ExecStart=/usr/bin/xyz --foo --bar

这可以覆盖之后的命令systemctl daemon-reload。我想在 SysVinit 中这样做,但不编辑/etc/init.d/xyz文件。是否可以在不编辑该 SysVinit 脚本的情况下添加/更改命令选项?如果没有,那么正确的方法是什么?我想永久更改该命令选项。

linux sysvinit
  • 1 个回答
  • 633 Views
Martin Hope
TheWaterProgrammer
Asked: 2019-03-01 14:20:21 +0800 CST

如何确定从 /etc/init.d 开始的服务的顺序

  • 3

ls -l /etc/init.d/给我一个在 linux 上启动的服务列表。我如何知道服务的启动顺序?

就像如果ls -l /etc/init.d/列出来

serviceA
serviceB
serviceC

我想知道是否serviceB开始之前serviceA和所有。我想知道开始的顺序

linux sysvinit
  • 1 个回答
  • 5744 Views
Martin Hope
xCovelus
Asked: 2019-02-16 05:03:02 +0800 CST

Tiny Core:启动脚本和持久化

  • 1

我需要一个非常轻量级的,我找到了 Tiny Core Linux,我按照本指南安装了它,但是我有几个问题,与添加 SysVinit(其中基于)启动脚本有关:

  1. 我在 /etc/init.d/ 中写入的任何内容在重新启动后都会丢失
  2. 不同的运行级别没有 /etc/rcX.d/ 目录。我试图避免在 /etc/init.d/ 中的脚本末尾调用我的脚本的第二个问题,但是由于第一个问题,重新启动时一切都丢失了。

之后查看挂载的设备,我选择安装的磁盘/dev/vda1挂载在/mnt/vda1、/home和/opt中,/对应一个rootfs:

rootfs on / type rootfs (rw,size=460176k,nr_inodes=163912)

在这些测试之前,我尝试过其他安装方式而不是 Frugal,比如 USB-HDD,但结果相似,所以,我想我不太了解如何使用这个发行版。

startup sysvinit
  • 1 个回答
  • 2795 Views
Martin Hope
Tim
Asked: 2019-02-14 16:48:32 +0800 CST

是否有将服务名称解析为端口的守护程序?

  • 2

DNS 服务器将主机名解析为 IP 地址。一个程序可以通过调用将主机名解析为 IP 地址getaddrinfo(),如果我是正确的,它反过来要求 DNS 服务器进行解析。

在 SysV init 中,是否有一些守护进程将服务名称解析为端口,就像 DNS 服务器一样?它通过阅读来做到这一点/etc/services吗?是否getaddrinfo()还调用守护进程来执行解析?

我知道inetd读取 /etc/services 决定要听哪些套接字。但inetd似乎没有将服务名称解析为端口,是吗?

谢谢。

services sysvinit
  • 1 个回答
  • 276 Views
Martin Hope
Tim
Asked: 2018-12-19 16:33:44 +0800 CST

在带有 SysvInit 的操作系统上,“rebo​​ot”和“halt”符号链接到某些可执行文件吗?

  • -1

在带有 Systemd 的操作系统上,reboot并且halt是指向systemctl.

在带有 SysvInit 的操作系统上,什么是reboot和halt 符号链接?是telinit吗?还是它们本身是可执行文件,而不是符号链接?

谢谢。

init sysvinit
  • 1 个回答
  • 116 Views
Martin Hope
Paradoxis
Asked: 2018-10-26 06:31:14 +0800 CST

通过 init.d 脚本启动 UWSGI 以退出代码 1 退出并显示“失败”,但进程运行正常

  • 0

在这被标记为重复之前,我阅读了这个问题;但是添加logfile2并没有改变任何东西。


我目前正在创建一个使用 UWSGI 运行 Python 堆栈的 docker 容器,为此我使用默认的 Debian 安装的 uwsgi 作为init.d脚本,并使用pip.

但是,每当我启动服务时,它都会输出一个错误,指出脚本无法启动,但是当我尝试向服务器(localhost:5000)发出请求或尝试查看进程是否正在运行ps aux | grep -i uwsgi时,服务器运行得很好。

我的意思的例子:

root@f16b3268a956:~# /etc/init.d/uwsgi start
[FAIL] Starting app server(s): uwsgi -> ! failed!

但是,如果我查看正在运行的进程

root@f16b3268a956:~# ps aux | grep -i uwsgi
user       984  0.1  2.8 235284 57876 ?        S    14:15   0:00 /usr/local/bin/uwsgi --ini /usr/share/uwsgi/conf/default.ini --ini /etc/uwsgi/apps-enabled/portal.ini --daemonize /var/log/uwsgi/app/portal.log
user      1009  0.0  2.7 253204 57040 ?        S    14:15   0:00 /usr/local/bin/uwsgi --ini /usr/share/uwsgi/conf/default.ini --ini /etc/uwsgi/apps-enabled/portal.ini --daemonize /var/log/uwsgi/app/portal.log
root      1146  0.0  0.0  12860   976 pts/0    S+   14:24   0:00 grep -i uwsgi

我的 uwsgi 配置的内容:

[uwsgi]
http-socket = localhost:5000
http-websockets = true
chmod-socket=775
chdir = /home/user/
master = true
binary-path = /usr/local/bin/uwsgi
virtualenv = /home/user/portal
module = portal.server:app
uid = user
gid = user
processes = 1
gevent = 1000
logfile2 = /tmp/test.pid
logto = /var/log/uwsgi/app/portal.log

查看日志文件也没有显示任何奇怪的东西:

root@f16b3268a956:~# cat /var/log/uwsgi/app/portal.log
Thu Oct 25 14:29:48 2018 - *** Starting uWSGI 2.0.17.1 (64bit) on [Thu Oct 25 14:29:48 2018] ***
Thu Oct 25 14:29:48 2018 - compiled with version: 6.3.0 20170516 on 25 October 2018 13:26:09
Thu Oct 25 14:29:48 2018 - os: Linux-4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018
Thu Oct 25 14:29:48 2018 - nodename: f16b3268a956
Thu Oct 25 14:29:48 2018 - machine: x86_64
Thu Oct 25 14:29:48 2018 - clock source: unix
Thu Oct 25 14:29:48 2018 - pcre jit disabled
Thu Oct 25 14:29:48 2018 - detected number of CPU cores: 4
Thu Oct 25 14:29:48 2018 - current working directory: /
Thu Oct 25 14:29:48 2018 - writing pidfile to /run/uwsgi/app/portal/pid
Thu Oct 25 14:29:48 2018 - detected binary path: /usr/local/bin/uwsgi
Thu Oct 25 14:29:48 2018 - setgid() to 1000
Thu Oct 25 14:29:48 2018 - setuid() to 1000
Thu Oct 25 14:29:48 2018 - chdir() to /home/user/
Thu Oct 25 14:29:48 2018 - writing pidfile to /tmp/test.pid
Thu Oct 25 14:29:48 2018 - your memory page size is 4096 bytes
Thu Oct 25 14:29:48 2018 - detected max file descriptor number: 1048576
Thu Oct 25 14:29:48 2018 - - async cores set to 1000 - fd table size: 1048576
Thu Oct 25 14:29:48 2018 - lock engine: pthread robust mutexes
Thu Oct 25 14:29:48 2018 - thunder lock: disabled (you can enable it with --thunder-lock)
Thu Oct 25 14:29:48 2018 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/portal/socket fd 3
Thu Oct 25 14:29:48 2018 - uwsgi socket 1 bound to TCP address localhost:5000 fd 5
Thu Oct 25 14:29:48 2018 - Python version: 3.6.6 (default, Sep  5 2018, 03:40:52)  [GCC 6.3.0 20170516]
Thu Oct 25 14:29:48 2018 - Set PythonHome to /home/user/portal
Thu Oct 25 14:29:48 2018 - Python main interpreter initialized at 0x563332cd13a0
Thu Oct 25 14:29:48 2018 - python threads support enabled
Thu Oct 25 14:29:48 2018 - your server socket listen backlog is limited to 100 connections
Thu Oct 25 14:29:48 2018 - your mercy for graceful operations on workers is 60 seconds
Thu Oct 25 14:29:48 2018 - mapped 21036928 bytes (20543 KB) for 1000 cores
Thu Oct 25 14:29:48 2018 - *** Operational MODE: async ***
Thu Oct 25 14:29:49 2018 - WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x563332cd13a0 pid: 1814 (default app)
Thu Oct 25 14:29:49 2018 - *** uWSGI is running in multiple interpreter mode ***
Thu Oct 25 14:29:49 2018 - spawned uWSGI master process (pid: 1814)
Thu Oct 25 14:29:49 2018 - spawned uWSGI worker 1 (pid: 1839, cores: 1000)
Thu Oct 25 14:29:49 2018 - *** running gevent loop engine [addr:0x5633314d0fd0] ***

有谁知道如何解决这个问题?

sysvinit uwsgi
  • 2 个回答
  • 717 Views
Martin Hope
Hoai Nguyen Trung
Asked: 2018-07-27 01:56:37 +0800 CST

是否有关于 init.d 默认脚本的列表或文档?

  • 1

根据我的理解,ls -l /etc/init.d列出当前里面的所有脚本init.d,包括那些后来由用户创建的脚本。如果是真的,那么我想问有没有文件或列表可以观看默认脚本init.d?

debian sysvinit
  • 1 个回答
  • 70 Views
Martin Hope
Steffi Ma
Asked: 2018-07-22 02:30:54 +0800 CST

如何写访问默认的 /etc/init.d

  • 0

我正在尝试在 Ubuntu 16 中安装Proteios软件。该软件的要求之一是

  • (*) 对 $SERVICE_PATH 的写入权限(默认 /etc/init.d)

我怎样才能做到这一点?

ubuntu sysvinit
  • 2 个回答
  • 3252 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve