80后的细娃儿

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

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

点赞

发表评论