Centos7
Centos7 systemctl start unit not found
我到處尋找,只是為了我的生命找出為什麼 systemctl 不會啟動我的單元。
我正在嘗試將 GCP 的 cloud-sql-proxy 作為 systemd 服務啟動。這就是我的
cloud-sql-proxy.service
樣子。[Install] WantedBy=multi-user.target [Unit] Description=Cloud SQL Proxy Requires=networking.service After=networking.service [Service] Type=simple WorkingDirectory=/opt ExecStart=/opt/cloud_sql_proxy -instances=pupa=tcp:5432 -credential_file=/etc/pupa-240309-5336639b0c06.json Restart=always StandardOutput=journal User=root
我
sudo systemctl enable cloud-sql-proxy
成功地跑了。然後當我執行sudo systemctl start cloud-sql-proxy.service
它時失敗並顯示以下消息:Failed to start cloud-sql-proxy.service: Unit not found.
以下是更多資訊:
$ ll -al /etc/systemd/system/cloud-sql-proxy.service -rw-r--r--. 1 root root 327 May 22 10:56 /etc/systemd/system/cloud-sql-proxy.service $ sudo systemctl list-unit-files ... cloud-sql-proxy.service enabled ... $ systemctl status cloud-sql-proxy ● cloud-sql-proxy.service - Cloud SQL Proxy Loaded: loaded (/etc/systemd/system/cloud-sql-proxy.service; enabled; vendor preset: disabled) Active: failed (Result: resources) since Sun 2019-05-19 15:49:48 UTC; 3 days ago Main PID: 1414 (code=exited, status=1/FAILURE) May 19 15:49:48 instance-1 systemd[1]: cloud-sql-proxy.service: main process exited, code=exited, status=1/FAILURE May 19 15:49:48 instance-1 systemd[1]: Unit cloud-sql-proxy.service entered failed state. May 19 15:49:48 instance-1 systemd[1]: cloud-sql-proxy.service failed. May 19 15:49:48 instance-1 systemd[1]: cloud-sql-proxy.service holdoff time over, scheduling restart. May 19 15:49:48 instance-1 systemd[1]: cloud-sql-proxy.service failed to schedule restart job: Unit not found. May 19 15:49:48 instance-1 systemd[1]: Unit cloud-sql-proxy.service entered failed state. May 19 15:49:48 instance-1 systemd[1]: cloud-sql-proxy.service failed.
關於我錯過的地方有什麼建議嗎?謝謝!
你能在 /usr/lib/systemd/system/cloud_sql_proxy.service 中嘗試這樣的事情嗎
[Unit] Description=GCP CloudSQL Proxy After=network.target [Service] User=root Group=root WorkingDirectory=/usr/bin Type=forking RemainAfterExit=yes ExecStart=/bin/sh -c '/usr/bin/nohup /usr/local/cloud_sql_proxy -instances=${INSTANCE_CONNECTION_NAME} -credential_file=${CREDENTIAL_FILE} &' StandardOutput=journal KillMode=process [Install] WantedBy=multi-user.target
您的配置文件將是 /usr/lib/systemd/system/cloud_sql_proxy.service.d/settings.conf
[Service] Environment=INSTANCE_CONNECTION_NAME=[YOUR CONNECTION NAME] Environment=CREDENTIAL_FILE=[PATH TO YOUR CREDENTIAL FILE]