之前说到安装好leanote,可以开机自动运行了,但是控制起来很不方便,于是就找到了一个脚本,就是前一篇日志
自己修改了一下,CentOS7下可用
vim /etc/init.d/leanoted #在init.d下新建一个控制脚本
把下面的内容贴近去
#!/bin/bash # leanoted go/revel daemon # chkconfig: 345 20 80 # description: leanote daemon # processname: leanote NAME="leanoted" PIDFILE=/path/to/leanote/run/$NAME.pid #进程文件的路径 DAEMON_USER=leanote #用来运行服务的用户名 DAEMON="su -m -l $DAEMON_USER -c /path/to/leanote/bin/run.sh" #leanote的路径 DAEMON_OPTS="" case "$1" in start) printf "%-50s" "Starting $NAME..." if [ -f $PIDFILE ]; then echo "Already running? (pid=`cat $PIDFILE`)" else PID=`$DAEMON $DAEMON_OPTS > /dev/null 2>&1 & echo $!` echo "$PID" > $PIDFILE echo "Ok. (pid=$PID)" fi ;; status) printf "%-50s" "Checking $NAME..." if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then printf "%s\n" "Process dead but pidfile exists." else echo "Running. (pid=$PID)" fi else printf "%s\n" "Service not running." fi ;; stop) printf "%-50s" "Stopping $NAME" if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` pkill -9 -P $PID printf "%s\n" "Ok." rm -f $PIDFILE else printf "%s\n" "Already stoppied? $PIDFILE not found." fi ;; restart) $0 stop sleep 5 $0 start ;; *) echo "Usage: $0 {status|start|stop|restart}" exit 1 esac
保存,添加到服务
chkconfig --add leanoted
设置自动启动
chkconfig --level345 leanoted on
手动启动
/etc/init.d/leanoted start
或者
service leanoted start
大功告成!
发表回复