ubuntu设置服务为开机自启动(以crond.serivce为例)

1,908次阅读
没有评论

ubuntu 设置服务为开机自启动(以 crond.serivce 为例)
一、设置 crond.service 服务为开机自启动

步骤 1:查看 crond.serivce 服务的自启动状态

[root@Xiwaer ~]# systemctl is-enabled crond.service
disabled
此时 crond.serivce 的自启动状态为 disabled

步骤 2:开启 crond.serivce 服务自启动

[root@Xiwaer ~]# systemctl enable crond.service
Created symlink from /etc/systemd/system/multi-user.target.wants/crond.service to /usr/lib/systemd/system/crond.service.

[root@Xiwaer ~]# systemctl is-enabled crond.service
enabled

[root@Xiwaer ~]# systemctl list-unit-files | grep enable
abrt-ccpp.service enabled
abrt-oops.service enabled
abrt-vmcore.service enabled
abrt-xorg.service enabled
abrtd.service enabled
auditd.service enabled
autovt@.service enabled
crond.service enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service enabled
getty@.service enabled
irqbalance.service enabled
lvm2-monitor.service enabled
microcode.service enabled
NetworkManager-dispatcher.service enabled
NetworkManager.service enabled
ntpd.service enabled
postfix.service enabled
rsyslog.service enabled
snmpd.service enabled
sshd.service enabled
systemd-readahead-collect.service enabled
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
tuned.service enabled
xinetd.service enabled
dm-event.socket enabled
lvm2-lvmetad.socket enabled
lvm2-lvmpolld.socket enabled
pcscd.socket enabled
telnet.socket enabled
default.target enabled
multi-user.target enabled
remote-fs.target enabled
runlevel2.target enabled
runlevel3.target enabled
runlevel4.target enabled

此时 crond.serivce 的自启动状态为 enabled

附:关闭 crond.serivce 的自启动状态

[root@Xiwaer ~]# systemctl disable crond.service
Removed symlink /etc/systemd/system/multi-user.target.wants/crond.service.

[root@Xiwaer ~]# systemctl is-enabled crond.service
disabled

二、开启和关闭 crond.service 服务

步骤 1:查看 crond.service 的启动状态

[root@Xiwaer ~]# systemctl status crond.service
● crond.service – Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 六 2017-07-29 14:19:12 CST; 5s ago
Process: 805 ExecStart=/usr/sbin/crond -n $CRONDARGS (code=exited, status=0/SUCCESS)
Main PID: 805 (code=exited, status=0/SUCCESS)

7 月 28 14:23:31 Xiwaer systemd[1]: Started Command Scheduler.
7 月 28 14:23:31 Xiwaer systemd[1]: Starting Command Scheduler…
7 月 28 14:23:31 Xiwaer crond[805]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 84% if used.)
7 月 28 14:23:31 Xiwaer crond[805]: (CRON) INFO (running with inotify support)
7 月 29 14:19:12 Xiwaer systemd[1]: Stopping Command Scheduler…
7 月 29 14:19:12 Xiwaer systemd[1]: Stopped Command Scheduler.

此处显示 crond.service 的启动状态为 dead

步骤 2:开启服务

[root@Xiwaer ~]# systemctl start crond.service

再次查看 crond.service 的启动状态

[root@Xiwaer ~]# systemctl status crond.service
● crond.service – Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since 六 2017-07-29 14:19:56 CST; 3s ago
Main PID: 8465 (crond)
CGroup: /system.slice/crond.service
└─8465 /usr/sbin/crond -n

7 月 29 14:19:56 Xiwaer systemd[1]: Started Command Scheduler.
7 月 29 14:19:56 Xiwaer systemd[1]: Starting Command Scheduler…
7 月 29 14:19:56 Xiwaer crond[8465]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 44% if used.)
7 月 29 14:19:56 Xiwaer crond[8465]: (CRON) INFO (running with inotify support)
7 月 29 14:19:56 Xiwaer crond[8465]: (CRON) INFO (@reboot jobs will be run at computer’s startup.)

此处显示 crond.service 的启动状态为 running

正文完
 0
评论(没有评论)
验证码