ログアウト後もvncサーバーをアクティブに保つことはできますか?

ログアウト後もvncサーバーをアクティブに保つことはできますか?

私はOpenSUSEを使用しており、x11vncサーバーの起動時に起動するスクリプトを作成しました。ただし、ユーザーがログアウトすると、x11vncは終了します。自動的に再起動したい。これは私が書いたスクリプトです。起動時に完全に実行されます。

#!/bin/sh
#
# /etc/init.d/vnc
#
### BEGIN INIT INFO
# Provides:          x11vnc server
# Required-Start:    xdm
# Should-Start: 
# Required-Stop: 
# Should-Stop: 
# Default-Start:     5
# Default-Stop:      0 1 2 6
# Short-Description: 
# Description:       Start or stop vnc server
### END INIT INFO


#INIT SCRIPT VARIABLES
SERVICE=$(basename $0)
#Gets the name of the script

BIN="/usr/bin/x11vnc"
#Binary path
ALLOWED_GROUP=$(getent group g_vnc-usr | awk -F ":" '{ print $4 }')
#Only inf-usr group is allowed to take control of any machine.

AUTH=`ps wwaux | grep '/X.*-auth' | sed -e 's/^.*-auth *//' -e 's/ .*$//' | head -n 1`

OPT="-display :0 -auth ${AUTH} -nopw -unixpw ${ALLOWED_GROUP} -shared -oa /var/log/vnc.log -xkb -bg -verbose -forever"
#Various options of the x11vnc providing auth, user auth, logging and "keep alive" connection.

CMD="${BIN} ${OPT}"
#Both bin and options are stored

. /lib/lsb/init-functions

rc_reset
# Reset status of this service

case "$1" in
    start)
    echo -n "Starting ${SERVICE}..."
        ## Start daemon with startproc(8). 
    /sbin/startproc ${CMD}

    ##>> /dev/null 2>&1
    sleep 2s

    # Remember status and be verbose.
        rc_status -v
    ;;

    stop)
    echo -n "Shutting down ${SERVICE}..."
    ## Stop daemon with killproc(8) 
    /sbin/killproc ${BIN}

    # Remember status and be verbose
    rc_status -v
        ;;

    restart)
    ## Stop the service and regardless of whether it was
    ## running or not, start it again.
    $0 stop
    $0 start

    # Remember status and be quiet
    rc_status
    ;;

    status)
    echo -n "Checking for service ${SERVICE}..."
    ## Check status with checkproc(8), if process is running
    ## checkproc will return with exit status 0.
    /sbin/checkproc ${BIN}

    # Remember status and be verbose
    rc_status -v
    ;;
    *)
    echo -n 
    echo -n "Usage: ${SERVICE} {start|stop|restart|status}"
    exit 1
    ;;
esac
rc_exit

このスクリプトを使用すると、現在ログインしている人がいなくても、このグループのすべてのユーザーがコンピュータを管理できます。

xinitrc試して追加したいexec /etc/init.d/vnc restart

ありがとうございます。

ベストアンサー1

systemdを使用している場合、ここの他の提案よりも優れた解決策は、システム作成者が設計し、推奨するようにsystemd単位のオーバーライドファイルを追加することです。

これは、カスタマイズを最小限に抑え、将来のメンテナンスとアップグレードへの影響を最小限に抑えながら、正確に必要です。

デフォルトのシステムサービス(:INTEGERサフィックスなし)の名前が私とvncserver@同じ名前の場合は、ディレクトリを作成してその中に名前のあるファイルを置きます。/etc/systemd/system/[email protected]/override.conf

[Service]
Restart=on-success
RestartSec=10

それからsystemctl daemon-reload。システムが以前のセッションプロセスをどれだけ早く削除するかに応じて、RestartSecを調整します。

ディレクトリとファイルを手動で作成するのではなく、次を実行することを選択できます。

systemctl edit vncserver@

そして、定型句のテキストが指す位置に上記のテキストを入力します。このアプローチでは、ディレクトリではなくデフォルトのサービス名だけを知ることができ、editコマンドはデーモンの再ロードを処理します。

おすすめ記事