最新文章:

首页 code

systemd下添加local启动项

发布时间:2018年04月25日 评论数:抢沙发 阅读数:16851

    从gentoo下找到的一键脚本,/usr/lib64/systemd/system-generators/gentoo-local-generator

    要添加的启动命令以start stop后缀放当前目录,再运行 gentoo-local-generator, 非常方便


    #!/bin/sh
    
    locald_dir=/etc/local.d
    cd "${locald_dir}" || exit 0
    
    svc_dir=/run/systemd/generator
    wan_dir=${svc_dir}/multi-user.target.wants
    mkdir -p "${svc_dir}" "${wan_dir}" || exit 1
    
    previous=
    
    for f in *.start *.stop; do
    	# omit non-existing files ('*.start' when glob doesn't match)
    	[ -f "${f}" ] || continue
    
    	case "${f}" in
    		*.start)
    			is_start=1
    			fn=${f%.start}
    
    			# 'env' guarantees shell-like behavior when starting files.
    			# Especially that text files without shebangs will be
    			# executed via shell.
    
    			start_cmd="/usr/bin/env ${locald_dir}/${f}"
    			stop_cmd=/bin/true
    			if [ -f "${fn}".stop ]; then
    				stop_cmd="/usr/bin/env ${locald_dir}/${fn}.stop"
    			fi
    			;;
    		*.stop)
    			is_start=
    			fn=${f%.stop}
    			start_cmd=/bin/true
    			stop_cmd="/usr/bin/env ${locald_dir}/${f}"
    			;;
    	esac
    
    	# omit .stop files which have matching .start files
    	[ -z "${is_start}" -a -e "${fn}.start" ] && continue
    
    	svc_file=gentoo-local-${fn}.service
    
    	echo "[Unit]
    Description=Service for local.d/${fn}.*
    After=multi-user.target graphical.target ${previous}
    ConditionFileIsExecutable=${locald_dir}/${f}
    
    [Service]
    Type=forking
    RemainAfterExit=on
    TimeoutSec=0
    ExecStart=${start_cmd}
    ExecStop=${stop_cmd}" > "${svc_dir}/${svc_file}"
    
    	ln -s "../${svc_file}" "${wan_dir}/${svc_file}"
    
    	previous=${svc_file}
    done

二维码加载中...
本文作者:admin      文章标题: systemd下添加local启动项
本文地址:http://jiang.shuang.he.cn/blog/?post=32
版权声明:若无注明,本文皆为“”原创,转载请保留文章出处。
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论