马春杰杰 Exit Reader Mode

[mcj]Ubuntu设置开机自动运行命令

Centos下设置开机自启方式如下:

Ubuntu下设置开机自启方式如下:

设置开机自启:

目前手里有一台服务器的快照,不过每次都需要打开,然后手动进去打开服务,想着把开启服务的命令加到开机自启,这样就方便了。

新建脚本为autoss.sh

#!/bin/sh
### BEGIN INIT INFO
# Provides:          svnd.sh
# Required-start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the svnd.sh daemon
# Description:       starts svnd.sh using start-stop-daemon
### END INIT INFO

ssserver -c /path/to/config.json -d start

设置权限:

sudo chmod 775 autoss.sh

复制到自启目录下:

cp autoss.sh /etc/init.d

执行更新命令:

cd /etc/init.d/

sudo update-rc.d autoss.sh

重启即可。

想要取消开机自启?

cd /etc/init.d

sudo update-rc.d -f autoss.sh remove

本文最后更新于2020年10月19日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!