Soh*_*ani 1 server startup command-line bash
我想在 Ubuntu 服务器 16.04 启动后(而不是登录后)在名为Zookeeper的用户下启动 Zookeeper 守护进程。所以我改变了文件/etc/rc.local
如下:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 'never'; defrag_file_pathname
su -c '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper &
exit 0
Run Code Online (Sandbox Code Playgroud)
su -c '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper &
,在 之前添加行exit 0
。但重启后进程并没有启动!
这是怎么回事?
详细信息:zookeeper用户位于sudo组中并且有密码。
详细信息:当我su -c '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper &
在终端中运行命令时,它需要密码才能运行。
创建一个 。service
文件/etc/systemd/system/zoo.service
并添加以下行:
[Unit]
Description=Zookeeper Daemon
Wants=syslog.target
[Service]
Type=forking
WorkingDirectory=/path/to/dir/of/interest
User=zookeeper
ExecStart=/home/zookeeper_home/bin/zkServer.sh
TimeoutSec=30
Restart=on-failure
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
现在设置服务:
sudo systemctl start zoo
sudo systemctl enable zoo
Run Code Online (Sandbox Code Playgroud)
检查状态:
sudo systemctl status zoo
Run Code Online (Sandbox Code Playgroud)
请阅读创建守护进程的更多详细信息:
https://www.freedesktop.org/software/systemd/man/systemd.unit.html
归档时间: |
|
查看次数: |
10271 次 |
最近记录: |