我需要让一个程序在启动时以 root 身份运行。该程序是。
/usr/bin/svxlink
我正在运行 Ubuntu 服务器 14.04 LTS
我就是无法让它工作。有人能指导我完成这些步骤吗?谢谢你的帮助。
我读了一整晚的书,但就是无法让它工作。不只是问,自己却不尝试。
我把它放入 /etc/init.d
#!/bin/sh
### BEGIN INIT INFO
# Provides: svxlink
# Required-Start: $network $local_fs $syslog $ntp
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start SvxLink Server daemon
### END INIT INFO
# Use the following command to activate the start script
# update-rc.d svxlink start 30 2 3 4 5 . stop 70 0 1 6 .
PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /lib/lsb/init-functions
PNAME=svxlink
NAME="SvxLink Server"
DAEMON=/usr/bin/$PNAME
test -x $DAEMON || exit 5
if [ -r /etc/default/$PNAME ]; then
. /etc/default/$PNAME
fi
POPTS="--daemon ${RUNASUSER:+--runasuser=$RUNASUSER} ${PIDFILE:+--pidfile=$PIDFILE} ${LOGFILE:+--logfile=$LOGFILE} ${CFGFILE:+--config=$CFGFILE}"
create_logfile()
{
touch $LOGFILE
if [ -n "$RUNASUSER" ]; then
chown $RUNASUSER.$RUNASUSER $LOGFILE
fi
}
case $1 in
start)
log_daemon_msg "Starting $NAME: $PNAME"
create_logfile
export $ENV
start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON -- $POPTS
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping $NAME: $PNAME"
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
log_end_msg $?
rm -f $PIDFILE
;;
restart|force-reload)
$0 stop && sleep 2 && $0 start
;;
try-restart)
if $0 status >/dev/null; then
$0 restart
else
exit 0
fi
;;
reload)
exit 3
;;
status)
pidofproc -p $PIDFILE $DAEMON >/dev/null
status=$?
if [ $status -eq 0 ]; then
log_success_msg "$NAME is running."
else
log_failure_msg "$NAME is not running."
fi
exit $status
;;
*)
echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 2
;;
esac
我明白了。
执行 /etc/init.d/svxlink start ..
* Starting SvxLink Server: svxlink
touch: missing file operand
Try 'touch --help' for more information.
export HOME='/root'
export LD_LIBRARY_PATH=''
export PATH='/sbin:/bin:/usr/sbin:/usr/bin'
export PERLLIB='/usr/share/webmin'
export PWD='/usr/share/webmin/init/'
export REMOTE_ADDR='192.168.4.25'
export REMOTE_ADDR_PROTOCOL='4'
export SERVER_REALROOT='/usr/share/webmin'
start-stop-daemon: --start needs --exec or --startas
Try 'start-stop-daemon --help' for more information.
...fail!
答案1
启动时运行程序 初学者指南 https://forums.raspberrypi.com/viewtopic.php?t=314455