在我的拱安装,/etc/bash.bashrc
以及/etc/skel/.bashrc
包含这些行:
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
Run Code Online (Sandbox Code Playgroud)
在 Debian 上,/etc/bash.bashrc
有:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
Run Code Online (Sandbox Code Playgroud)
并且/etc/skel/.bashrc
:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Run Code Online (Sandbox Code Playgroud)
man bash
然而,根据,非交互式 shell 甚至不读取这些文件:
When bash is started non-interactively, to run a shell script, for
example, it looks for the variable …
Run Code Online (Sandbox Code Playgroud) 我将这个定义用于systemd
工作:
[Unit]
Description=Some job
[Service]
ExecStart=/usr/local/sbin/somejob
User=dlt
Type=forking
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
脚本调用如下(调用一个简单的例程,侦听 tcpip 套接字并将输入附加到文件):
#!/bin/sh
cd /home/user/tmp/testout
nohup java -jar /home/user/programming/tests/java/core/SocketTest/SocketTest.jar </dev/null >/dev/null &
Run Code Online (Sandbox Code Playgroud)
之后systemctl start somejob
的过程显示为下运行,同时init
作为其父:
user@CANTANDO ~$ ps -u dlt eo pid,ppid,command
PID PPID COMMAND
8718 1 java -jar /home/user/programming/tests/java/core/SocketTest/SocketTest.jar
Run Code Online (Sandbox Code Playgroud)
执行systemctl stop somejob
该过程后不再显示(并且端口已关闭)。
所以一切看起来都很好
我的问题是:这是运行 java 守护进程的可接受的解决方案systemd
,还是有警告,以及其他更稳定或安全的方法来实现这一目标?