linux学习-将seafile启动脚本设置为开机启动服务
有時候,我們安裝的linux軟件和程序不是通過yum安裝,而是通過編譯或者其他方式安裝。有時需要將程序設(shè)置為服務(wù),達(dá)到開機啟動的目的。
我在公有云的與服務(wù)器上搭建了seafile網(wǎng)盤,當(dāng)我重啟云服務(wù)器的時候,seafile的程序不會自動啟動,需要我在相關(guān)目錄下執(zhí)行腳本,才能啟動。
將兩個腳本使用軟連接到/root/目錄下,方便執(zhí)行
現(xiàn)在采用服務(wù)的方式,將這這兩個腳本加入開機啟動
創(chuàng)建 systemd 服務(wù)文件?/etc/systemd/system/seafile.service
vim?/etc/systemd/system/seafile.service? =======================內(nèi)容如下======================== [Unit] Description=Seafile #?add?mysql.service?or?postgresql.service?depending?on?your?database?to?the?line?below After=network.target[Service] Type=oneshot ExecStart=/home/cloud_storage/seafile-server-latest/seafile.sh?start ExecStop=/home/cloud_storage/seafile-server-latest/seafile.sh?stop RemainAfterExit=yes User=seafile Group=seafile[Install] WantedBy=multi-user.target這個文件由三個部分組成:Unit\Service\Install
[Unit]主要是為了解決依賴關(guān)系。常見的添加Requires、After,如果這個依賴是可選的,那么是Wants、After。依賴關(guān)系通常被用在服務(wù)(service)而不是(target)上,所以上述的httpd所依賴的僅僅是一些target,因而也就沒有Requires和Wants出現(xiàn)。
[service]可選擇幾種不同的服務(wù)啟動方式,啟動方式通過Type參數(shù)進(jìn)行設(shè)置。
Type=simple(默認(rèn)值):systemd認(rèn)為該服務(wù)將立即啟動。服務(wù)進(jìn)程不會fork。如果該服務(wù)要啟動其他服務(wù),不要使用此類型啟動,除非該服務(wù)是socket激活型。
Type=forking:systemd認(rèn)為當(dāng)該服務(wù)進(jìn)程fork,且父進(jìn)程退出后服務(wù)啟動成功。對于常規(guī)的守護(hù)進(jìn)程(daemon),除非你確定此啟動方式無法滿足需求,使用此類型啟動即可。使用此啟動類型應(yīng)同時指定 PIDFile=,以便systemd能夠跟蹤服務(wù)的主進(jìn)程。
Type=oneshot:這一選項適用于只執(zhí)行一項任務(wù)、隨后立即退出的服務(wù)。可能需要同時設(shè)置 RemainAfterExit=yes 使得 systemd 在服務(wù)進(jìn)程退出之后仍然認(rèn)為服務(wù)處于激活狀態(tài)。
Type=notify:與 Type=simple 相同,但約定服務(wù)會在就緒后向 systemd 發(fā)送一個信號。這一通知的實現(xiàn)由 libsystemd-daemon.so 提供。
Type=dbus:若以此方式啟動,當(dāng)指定的 BusName 出現(xiàn)在DBus系統(tǒng)總線上時,systemd認(rèn)為服務(wù)就緒
[Install]
WantedBy=multi-user.target多用戶啟動
創(chuàng)建 systemd 服務(wù)文件?/etc/systemd/system/seahub.service
vim?/etc/systemd/system/seahub.service =======================內(nèi)容如下======================== [Unit] Description=Seafile?hub After=network.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 User=seafile Group=seafile Type=oneshot RemainAfterExit=yes[Install] WantedBy=multi-user.target重新加載服務(wù)
systemctl?daemon-reload systemctl?enable?seafile.service systemctl?enable?seahub.service轉(zhuǎn)載于:https://blog.51cto.com/11555417/2151938
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的linux学习-将seafile启动脚本设置为开机启动服务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle dg 备库未设置conve
- 下一篇: linux 其他常用命令