简体   繁体   English

有什么不同? 须藤重启

[英]What's the difference? sudo restart

What's the difference between: 之间有什么区别:

sudo /etc/init.d/apache2 restart

and

sudo service apache2 restart

I tried the first one, and it didn't apply my changes, while 我尝试了第一个,但没有应用我的更改,而

sudo service apache2 restart

did uptake my changes. 确实接受了我的更改。

Here is what is actually happening when you run sudo /etc/init.d/apache2 restart : 这是当您运行sudo /etc/init.d/apache2 restart时实际发生的事情:

if ! $APACHE2CTL configtest > /dev/null 2>&1; then
    $APACHE2CTL configtest || true
    log_end_msg 1
    exit 1
fi
if check_htcacheclean ; then
        log_daemon_msg "Restarting web server" "htcacheclean"
        stop_htcacheclean
        log_progress_msg apache2
else
        log_daemon_msg "Restarting web server" "apache2"
fi
PID=$(pidof_apache) || true
if ! apache_wait_stop; then
        log_end_msg 1 || true
fi
if $APACHE2CTL start; then
        if check_htcacheclean ; then
                start_htcacheclean || log_end_msg 1
        fi
        log_end_msg 0
else
        log_end_msg 1
fi

As you can see; 如你看到的; first a config test is run, if this is successful the server is stopped and then started. 首先运行配置测试,如果成功,则停止服务器,然后再启动。

I find it hard to believe that running this command did not apply your changes if they were properly saved and valid. 我发现很难相信如果正确保存并有效更改后,运行此命令不会应用您的更改。 I only use this command and have never had that issue. 我只使用此命令,从未遇到过该问题。

/usr/bin/service is described as: /usr/bin/service被描述为:

# A convenient wrapper for the /etc/init.d init scripts.

And it does the following: 它执行以下操作:

SERVICEDIR="/etc/init.d"

# Otherwise, use the traditional sysvinit
if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
   exec env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" ${ACTION} ${OPTIONS}
else
   echo "${SERVICE}: unrecognized service" >&2
   exit 1
fi

So the commands are basically identical, sudo service apache2 restart is just a wrapper for sudo /etc/init.d/apache2 restart . 因此命令基本上是相同的, sudo service apache2 restart只是sudo /etc/init.d/apache2 restart的包装。

You may also use sudo /etc/init.d/apache2 reload , this reloads the config without restarting the server. 您还可以使用sudo /etc/init.d/apache2 reload ,这将在不重新启动服务器的情况下重新加载配置。 This only works if you have changed config, it will not load modules that you have enabled, for that you need to restart Apache. 这仅在您更改了配置后才有效,它不会加载已启用的模块,因为您需要重新启动Apache。

Edit: This code is from a Debian system. 编辑:这段代码来自Debian系统。

In general, whether these two commands are identical or not depends on your Linux distribution. 通常,这两个命令是否相同取决于您的Linux发行版。

The first one requires the existence of a traditional SysV-style init script. 第一个要求存在传统的SysV风格的初始化脚本。 Until a few years ago that was practically the only way to control services and the service script was just a simple wrapper that basically added the init script path. 直到几年前,这实际上是控制服务的唯一方法,而service脚本只是一个简单的包装程序,基本上添加了初始化脚本路径。

These days many Linux distributions have switched to alternative service management systems such as upstart or systemd . 如今,许多Linux发行版已切换到替代服务管理系统,例如upstartsystemd Therefore, the service wrapper may also make use of these systems, providing a certain degree of compatibility. 因此, service包装器也可以利用这些系统,从而提供一定程度的兼容性。

Bottom line: depending on the specifics of your Linux distribution, the /etc/init.d/apache2 may not exist at all, it may just use service itself, or it may do nothing at all. 底线:根据您的Linux发行版的具体情况,/ /etc/init.d/apache2可能根本不存在,它可能仅使用service本身,或者根本不执行任何操作。 My Mageia Linix system, for example, launches Apache using a systemd service file and has no SysV init script at all for it. 例如,我的Mageia Linix系统使用systemd服务文件启动Apache,并且根本没有SysV初始化脚本。

You are generally better off just using service <service> <command>... . 通常,最好只使用service <service> <command>...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “service apache2 reload”和“sudo systemctl restart apache2”有什么区别? - What is the difference between 'service apache2 reload' and 'sudo systemctl restart apache2'? “sudo whoami”和“sudo who am i”有什么区别? - What is the difference between “sudo whoami” and “sudo who am i”? `$/sbin/restart nginx` 和 `$service nginx restart` 有什么区别? - What is the difference between `$/sbin/restart nginx` and `$service nginx restart`? “ systemctl restart”和“ systemctl start”之间有什么区别? - What is the difference between “systemctl restart” and “systemctl start”? AWS Marketplace和sudo apt-get install有什么区别? - What is the difference between AWS Marketplace and sudo apt-get install? sudo -u postgres psql和sudo psql -U postgres有什么区别? - What is the difference between sudo -u postgres psql and sudo psql -U postgres? 测试用户是否可以在 Bash 中执行 sudo 的最佳方法是什么? - What's the best way to test if a user can sudo in Bash? Capistrano:run和sudo之间的区别? - Capistrano: difference between `run` and `sudo`? {}和\\在&#39;sudo find / var / www / html -type d -exec chmod g + s {} \\;&#39;中是什么意思? - What do {} and \ mean in 'sudo find /var/www/html -type d -exec chmod g+s {} \;' insmod和modprobe有什么区别? - What's the difference between insmod and modprobe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM