• CentOS systemd 的自启动项文件位置


    举例1)

    建立自启动的命令如下:

    # systemctl enable nginx.service

    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

    命令的反馈提示了文件和链接的位置关系。

    启动文件的内容如下:

    # cat nginx.service
    [Unit]
    Description=The nginx HTTP and reverse proxy server
    After=network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    # Nginx will fail to start if /run/nginx.pid already exists but has the wrong
    # SELinux context. This might happen when running `nginx -t` from the cmdline.
    # https://bugzilla.redhat.com/show_bug.cgi?id=1268621
    ExecStartPre=/usr/bin/rm -f /run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t
    ExecStart=/usr/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    KillSignal=SIGQUIT
    TimeoutStopSec=5
    KillMode=process
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

    举例2)

    安装完mariadb后

    # systemctl enable mariadb

    Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

    文件内容如下:

    # cat /usr/lib/systemd/system/mariadb.service
    # It's not recommended to modify this file in-place, because it will be
    # overwritten during package upgrades. If you want to customize, the
    # best way is to create a file "/etc/systemd/system/mariadb.service",
    # containing
    # .include /lib/systemd/system/mariadb.service
    # ...make your changes here...
    # or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
    # which doesn't need to include ".include" call and which will be parsed
    # after the file mariadb.service itself is parsed.
    #
    # For more info about custom unit files, see systemd.unit(5) or
    # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

    # For example, if you want to increase mariadb's open-files-limit to 10000,
    # you need to increase systemd's LimitNOFILE setting, so create a file named
    # "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
    # [Service]
    # LimitNOFILE=10000

    # Note: /usr/lib/... is recommended in the .include line though /lib/...
    # still works.
    # Don't forget to reload systemd daemon after you change unit configuration:
    # root> systemctl --system daemon-reload

    [Unit]
    Description=MariaDB database server
    After=syslog.target
    After=network.target

    [Service]
    Type=simple
    User=mysql
    Group=mysql

    ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
    # Note: we set --basedir to prevent probes that might trigger SELinux alarms,
    # per bug #547485
    ExecStart=/usr/bin/mysqld_safe --basedir=/usr
    ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID

    # Give a reasonable amount of time for the server to start up/shut down
    TimeoutSec=300

    # Place temp files in a secure directory, not /tmp
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target
    #

  • 相关阅读:
    Java技术学习笔记:C/S 与B/S 区别
    Java开发面试题总结(八)
    Java技术笔记:数据库的性能优化
    零基础学习Python可以学会吗?你有哪些方法?
    java培训学习路线图之SpringBoot多模块开发学习
    计算机专业选Java和Python哪个前景好点?
    bzoj2152 聪聪可可
    bzoj1468 Tree
    bzoj2879 [Noi2012]美食节
    bzoj2208 [Jsoi2010]连通数
  • 原文地址:https://www.cnblogs.com/leooys/p/8667996.html
Copyright © 2020-2023  润新知