我是 maven scala 插件使用的锌增量编译器的忠实粉丝,但我发现每次弹出笔记本电脑时都必须手动启动它很烦人。我编写了一个脚本来在 Ubuntu 中将它作为服务运行 - 它启动正常,但是当我运行 mvn install 时,我收到一个错误,指出它找不到程序 javac。下面是我在 /etc/init.d 中的脚本 - 注意:我指定了 $JAVA_HOME 并将其添加到 /etc/bash.bashrc 中的路径中,该路径在此脚本中明确引用。
#!/bin/bash
### BEGIN INIT INFO
# Provides: zinc
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start compiler at boot time
# Description: Starts and stops the zinc incremental compiler
### END INIT INFO
source /etc/bash.bashrc
PROG_PATH="/opt/zinc/bin"
PROG="zinc"
start() {
su - gary "-c $PROG_PATH/$PROG -start 2>&1 >/dev/null &"
echo "$PROG started"
}
stop() {
su - gary "-c $PROG_PATH/$PROG -shutdown 2>&1 >/dev/null &"
echo "$PROG stopped"
}
## Check to see if we are running as root first.
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
case "$1" in
start)
start
exit 0
;;
stop)
stop
exit 0
;;
reload|restart|force-reload)
stop
start
exit 0
;;
**)
echo "Usage: $0 {start|stop|reload}" 1>&2
exit 1
;;
esac