我不想通过创建新的systemd脚本来做正确的事,我只是希望我的旧init脚本能够再次正常工作,因为我已经将系统升级到使用systemd的操作系统。
我已经简要研究了如何转换初始化脚本以及如何编写systemd脚本,但是我敢肯定,正确学习它并正确执行将花费我几个小时。
当前的情况是:
systemctl start solr
Failed to start solr.service: Unit solr.service failed to load: No such file or directory.
和:
sudo service solr start
Failed to start solr.service: Unit solr.service failed to load: No such file or directory.
现在,我只想恢复工作。使此功能再次起作用的阻力最小的途径是什么?
更新
我不想弄清楚这一切-我确实不是-但是我必须并且我已经发掘出我的第一个线索:
sudo systemctl enable solr
Synchronizing state for solr.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d solr defaults
insserv: warning: script 'K01solr' missing LSB tags and overrides
insserv: warning: script 'solr' missing LSB tags and overrides
Executing /usr/sbin/update-rc.d solr enable
update-rc.d: error: solr Default-Start contains no runlevels, aborting.
LSB报头依赖性信息很重要。许多发行版上的SysV实现都没有使用LSB初始化脚本头中编码的依赖项信息,或者仅以非常有限的方式使用了它们。因此,它们通常不正确或不完整。但是,systemd会完全解释这些标头,并在运行时密切关注它们
我认为这意味着我的脚本要先解决,才能解决。
有问题的脚本:
#!/bin/sh
# Prerequisites:
# 1. Solr needs to be installed at /usr/local/solr/example
# 2. daemon needs to be installed
# 3. Script needs to be executed by root
# 4. $INSTALL_ROOT must be set
# This script will launch Solr in a mode that will automatically respawn if it
# crashes. Output will be sent to /var/log/solr/solr.log. A pid file will be
# created in the standard location.
start () {
echo -n "Starting solr..."
# Reset ulimit or else get issues with too many open files (https://issues.apache.org/jira/browse/SOLR-4)
ulimit -n 10000
# start daemon
daemon --chdir='/usr/local/solr/example' --command "java -jar -server start.jar -DINSTALL_ROOT=$INSTALL_ROOT" --respawn --output=/var/log/solr/solr.log --name=solr --verbose
RETVAL=$?
if [ $RETVAL = 0 ]
then
echo "done."
else
echo "failed. See error code for more information."
fi
return $RETVAL
}
stop () {
# stop daemon
echo -n "Stopping solr..."
daemon --stop --name=solr --verbose
RETVAL=$?
if [ $RETVAL = 0 ]
then
echo "done."
else
echo "failed. See error code for more information."
fi
return $RETVAL
}
restart () {
daemon --restart --name=solr --verbose
}
status () {
# report on the status of the daemon
daemon --running --verbose --name=solr
return $?
}
case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
stop
sleep 15
start
;;
*)
echo $"Usage: solr {start|status|stop|restart}"
exit 3
;;
esac
exit $RETVAL