mmmdbybyd / CNS

CuteBi Network Server
339 stars 140 forks source link

请问如何设置开机启动 #27

Open zsanjin-p opened 1 year ago

zsanjin-p commented 1 year ago

我试了2种开机方式都不行,文件在/root/cns下

[Unit] Description=CNS Service After=network.target

[Service] Type=simple ExecStart=/root/cns/cns -daemon Restart=always User=root

[Install] WantedBy=multi-user.target

!/bin/sh

#

chkconfig: 345 99 10

description: cns daemon

#

processname: cns

pidfile: /var/run/cns.pid

configfile: /root/cns/config.cfg

Source function library.

. /etc/rc.d/init.d/functions

prog=cns lockfile=/var/lock/subsys/$prog pidfile=/var/run/$prog.pid configfile=/root/cns/config.cfg start() { echo -n $"Starting $prog: " daemon --pidfile=$pidfile --user=root --check $prog \ $prog -f $configfile & RETVAL=$? [ $RETVAL -eq 0 ] && touch $lockfile echo return $RETVAL }

stop() { echo -n $"Stopping $prog: " killproc -p $pidfile $prog RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile echo return $RETVAL }

restart() { stop start }

See how we were called.

case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $prog {start|stop|restart}" exit 1 esac

exit $RETVAL

rhy12345 commented 11 months ago

使用systemctl enable cns就行 程序安装的时候添加了自启程序