【发布时间】:2021-07-14 13:26:01
【问题描述】:
我正在尝试在谷歌云终端中使用以下命令创建 systemd 服务后激活服务:
vim /etc/systemd/system/app.service
将以下内容粘贴到此文件中:
#vim /etc/systemd/system/app.service
[Unit]
# specifies metadata and dependencies
Description=Gunicorn instance to serve myproject
After=network.target
# tells the init system to only start this after the networking target has been reached
# We will give our regular user account ownership of the process since it owns all of the relevant files
[Service]
# Service specify the user and group under which our process will run.
User=clashgamers2021
# give group ownership to the www-data group so that Nginx can communicate easily with the Gunicorn processes.
Group=www-data
# We'll then map out the working directory and set the PATH environmental variable so that the init system knows where our the executables for the process are located (wi$
WorkingDirectory=/home/clashgamers2021/clashgamers/
Environment="PATH=/home/clashgamers2021/clashgamers/env/bin"
# We'll then specify the commanded to start the service
ExecStart=/home/clashgamers2021/clashgamers/env/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app
# This will tell systemd what to link this service to if we enable it to start at boot. We want this service to start when the regular multi-user system is up and running:
[Install]
WantedBy=multi-user.target
为了激活这项服务,我输入了:
sudo systemctl start app
sudo systemctl enable app
但是我得到了这个错误:
clashgamers2021@cloudshell:~/clashgamers (clash-gamers-318206)$ sudo systemctl start app
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
【问题讨论】:
-
您好!您提到您在
google cloud terminal中运行此代码,具体在哪里?在虚拟机内部还是在 Google Cloud Shell 内部?您正在使用什么操作系统(Red Hat、Rocky、COS 等)运行什么类型的 VM(N1、E2 等)? -
根据错误信息,您确定您的操作系统版本安装了systemd服务吗?确认第一件事是我在您的原始帖子中没有看到您,请确保在添加新服务后重新加载 systemd 守护进程:systemctl daemon-reload
标签: google-cloud-platform systemd