编写简单的CentOS7系统服务文件
2015-11-09 00:00
645 查看
摘要: systemctl start test_service.service
编写一个无线循环的脚本, 并且将输出写入到/var/log/helloworld.log文件中.
编写一个系统服务文件
设置成为开机自启动服务
启动helloworld服务
观察日志信息
停止helloworld服务
查看报错信息:
报错信息:
编写一个无线循环的脚本, 并且将输出写入到/var/log/helloworld.log文件中.
[root@localhost ~]# mkdir /home/zhengtong/20151109/ [root@localhost ~]# cd /home/zhengtong/20151109/ [root@localhost 20151109]# vim helloworld.sh #!/bin/bash # __author__ = 'zhengtong' while [ : ] do echo $(date "+%Y-%m-%d %H:%M:%S") 'hello world!' >> /var/log/helloworld.log 2>&1 sleep 1 done [root@localhost 20151109]# chmod +x helloworld.sh
编写一个系统服务文件
[root@localhost 20151109]# vim /usr/lib/systemd/system/helloworld.service [Unit] Description=helloworld service After=network.target remote-fs.target nss-lookup.target [Service] Type=simple ExecStart=/home/zhengtong/20151109/helloworld.sh ExecStop=/bin/kill -9 $MAINPID [Install] WantedBy=multi-user.target
设置成为开机自启动服务
[root@localhost 20151109]# systemctl enable helloworld
启动helloworld服务
[root@localhost 20151109]# systemctl start helloworld
观察日志信息
[root@localhost 20151109]# tail -f /var/log/helloworld.log 2015-11-09 04:01:09 hello world! 2015-11-09 04:01:10 hello world! 2015-11-09 04:01:11 hello world! 2015-11-09 04:01:12 hello world! 2015-11-09 04:01:13 hello world! 2015-11-09 04:01:14 hello world!
停止helloworld服务
[root@localhost 20151109]# systemctl stop helloworld
查看报错信息:
[root@localhost 20151109]# systemctl status helloworld
报错信息:
main process exited, code=exited, status=2/INVALIDARGUMENT 表示ExecStart写的不正确. [emerg] 254#0: open() "xxx" failed (13: Permission denied) 表示文件没有运行权限.(chmod +x 程序文件名)
相关文章推荐
- linux里挂载(mount)和取消挂载(umount)命令的使用
- linux 常用基础命令 cat 详细介绍
- Linux 技巧:让进程在后台可靠运行的几种方法
- SVN服务器迁移(两台Linux机器之间)
- linux中bmp085驱动移植
- window下从硬盘安装linux系统iso镜像文件的方法
- CentOS安装EPEL Remi
- Linux学习之用户管理
- Linux学习之软件管理
- Linux学习之vim命令
- Linux学习之命令(用户、压缩)
- Linux下非轮询方式监控网卡连接状态
- Linux下如何清空输入缓冲区
- CentOS---网络配置详解
- php在Linux下的相对路径问题
- Linux学习之命令(文件相关)
- linux学习之绪论(相关软件)
- Linux下内核中的进程调度(浅析)
- 了解 Linux內核架構 (1)
- CentOS7编译BCM4313无线网卡驱动