怎样自己创造网站,开鲁吧,网页传奇单职业,天合建设集团网站有时候#xff0c;我们安装的linux软件和程序不是通过yum安装#xff0c;而是通过编译或者其他方式安装。有时需要将程序设置为服务#xff0c;达到开机启动的目的。我在公有云的与服务器上搭建了seafile网盘#xff0c;当我重启云服务器的时候#xff0c;seafile的程序不… 有时候我们安装的linux软件和程序不是通过yum安装而是通过编译或者其他方式安装。有时需要将程序设置为服务达到开机启动的目的。我在公有云的与服务器上搭建了seafile网盘当我重启云服务器的时候seafile的程序不会自动启动需要我在相关目录下执行脚本才能启动。将两个脚本使用软连接到/root/目录下方便执行现在采用服务的方式将这这两个脚本加入开机启动创建 systemd 服务文件 /etc/systemd/system/seafile.servicevim /etc/systemd/system/seafile.service
内容如下
[Unit]
DescriptionSeafile
# add mysql.service or postgresql.service depending on your database to the line below
Afternetwork.target[Service]
Typeoneshot
ExecStart/home/cloud_storage/seafile-server-latest/seafile.sh start
ExecStop/home/cloud_storage/seafile-server-latest/seafile.sh stop
RemainAfterExityes
Userseafile
Groupseafile[Install]
WantedBymulti-user.target这个文件由三个部分组成Unit\Service\Install[Unit]主要是为了解决依赖关系。常见的添加Requires、After如果这个依赖是可选的那么是Wants、After。依赖关系通常被用在服务service而不是target上所以上述的httpd所依赖的仅仅是一些target因而也就没有Requires和Wants出现。[service]可选择几种不同的服务启动方式启动方式通过Type参数进行设置。Typesimple默认值systemd认为该服务将立即启动。服务进程不会fork。如果该服务要启动其他服务不要使用此类型启动除非该服务是socket激活型。Typeforkingsystemd认为当该服务进程fork且父进程退出后服务启动成功。对于常规的守护进程daemon除非你确定此启动方式无法满足需求使用此类型启动即可。使用此启动类型应同时指定 PIDFile以便systemd能够跟踪服务的主进程。Typeoneshot这一选项适用于只执行一项任务、随后立即退出的服务。可能需要同时设置 RemainAfterExityes 使得 systemd 在服务进程退出之后仍然认为服务处于激活状态。Typenotify与 Typesimple 相同但约定服务会在就绪后向 systemd 发送一个信号。这一通知的实现由 libsystemd-daemon.so 提供。Typedbus若以此方式启动当指定的 BusName 出现在DBus系统总线上时systemd认为服务就绪[Install]WantedBymulti-user.target多用户启动创建 systemd 服务文件 /etc/systemd/system/seahub.servicevim /etc/systemd/system/seahub.service
内容如下
[Unit]
DescriptionSeafile hub
Afternetwork.target seafile.service[Service]
# change start to start-fastcgi if you want to run fastcgi
ExecStart/home/cloud_storage/seafile-server-latest/seahub.sh start
ExecStop/home/cloud_storage/seafile-server-latest/seahub.sh stop
Userseafile
Groupseafile
Typeoneshot
RemainAfterExityes[Install]
WantedBymulti-user.target重新加载服务systemctl daemon-reload
systemctl enable seafile.service
systemctl enable seahub.service 转载于:https://blog.51cto.com/11555417/2151938