我有这个 SystemD 脚本:
[单位] 描述=RTC 客户服务
[Service]
user=linuxuser
WorkingDirectory=/usr/lib/systemd/scripts/
Type=forking
ExecStart=/bin/bash rtc_client.sh start
ExecStop=/bin/bash rtc_client.sh stop
Restart=no
RemainAfterExit=no
TimeoutStartSec=0
TimeoutStopSec=60
[Install]
WantedBy=multi-user.target
它正确启动脚本,但始终使用 root。这是:
#!/bin/bash
RTCENGINEID=$HOSTNAME'_engine'
RTCUSER='RTCUSER'
RTCPW='RTCPWD'
RTCSERVER='SERVER'
RTCSERVERPORT='9443'
RTCREPOSITORY=https://$RTCSERVER:$RTCSERVERPORT/ccm
export WORKDIR='/opt/ibm/buildsystemtoolkit/buildsystem/buildengine/eclipse'
export JAVACMD=/opt/ibm/java-s390x-71/jre/bin/java
export ARGS="-cp ./plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar org.eclipse.equinox.launcher.Main -application com.ibm.team.build.engine.jazzBuildEngine -repository $RTCREPOSITORY -engineId $RTCENGINEID -userId $RTCUSER -pass $RTCPW"
RTCJAR=org.eclipse.equinox.launcher
PIDFILE='/var/run/rtc_client/rtc_client.pid'
DEBUGLOG='/tmp/rtc_debug.log'
. /home/linuxuser/.bash_profile
start() {
cd $WORKDIR
nohup $JAVACMD $ARGS > $DEBUGLOG &
sleep 10
pgrep -f $RTCJAR > $PIDFILE
echo "USER IS: " $(whoami) | tee -a $DEBUGLOG
echo "PID IS: " $(cat $PIDFILE) | tee -a $DEBUGLOG
}
stop() {
echo "USER IS: " $(whoami) | tee -a $DEBUGLOG
echo "PID IS: " $(cat $PIDFILE) | tee -a $DEBUGLOG
kill $(cat $PIDFILE)
rm -f $PIDFILE
}
restart() {
stop
start
}
reload() {
restart
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
我试图用“su pers5i”启动它,它运行正常,我不知道可能是什么问题。
任何帮助深表感谢。
根据https://www.freedesktop.org/software/systemd/man/systemd.exec.html。也许用户中的 'u' 必须大写才能完成您需要的操作。