mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
fix: Make systemd unit more production-like (#929)
* fix: Make systemd unit more production-like * docs: updated server.md * fix: Restart=on-failure instead of always in systemd unit
This commit is contained in:
parent
de7812558e
commit
ffc941016b
@ -9,40 +9,44 @@ This is mostly basic linux server configuration stuff but I felt it important to
|
|||||||
First create the verdaccio user:
|
First create the verdaccio user:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo adduser --disabled-login --gecos 'Verdaccio NPM mirror' verdaccio
|
$ sudo adduser --system --gecos 'Verdaccio NPM mirror' --group --home /var/lib/verdaccio verdaccio
|
||||||
|
```
|
||||||
|
|
||||||
|
Or, in case you do not have `adduser`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo useradd --system --comment 'Verdaccio NPM mirror' --create-home --home-dir /var/lib/verdaccio --shell /sbin/nologin verdaccio
|
||||||
```
|
```
|
||||||
|
|
||||||
You create a shell as the verdaccio user using the following command:
|
You create a shell as the verdaccio user using the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo su verdaccio
|
$ sudo su -s /bin/bash verdaccio
|
||||||
$ cd ~
|
$ cd
|
||||||
```
|
```
|
||||||
|
|
||||||
The 'cd ~' command send you to the home directory of the verdaccio user. Make sure you run verdaccio at least once to generate the config file. Edit it according to your needs.
|
The `cd` command sends you to the home directory of the verdaccio user. Make sure you run verdaccio at least once to generate the config file. Edit it according to your needs.
|
||||||
|
|
||||||
## Listening on all addresses
|
## Listening on all addresses
|
||||||
If you want to listen to every external address set the listen directive in the config to:
|
If you want to listen to every external address set the listen directive in the config to:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# you can specify listen address (or simply a port)
|
# you can specify listen address (or simply a port)
|
||||||
listen: 0.0.0.0:4873
|
listen: 0.0.0.0:4873
|
||||||
```
|
```
|
||||||
If you are running `verdaccio` in a Amazon EC2 Instance, [you will need set the listen in change your config file](https://github.com/verdaccio/verdaccio/issues/314#issuecomment-327852203) as is described above.
|
|
||||||
|
|
||||||
> Apache configure? Please check out the [Reverse Proxy Setup](reverse-proxy.md)
|
If you are running verdaccio in a Amazon EC2 Instance, [you will need set the listen in change your config file](https://github.com/verdaccio/verdaccio/issues/314#issuecomment-327852203) as is described above.
|
||||||
|
|
||||||
|
> Configure Apache or nginx? Please check out the [Reverse Proxy Setup](reverse-proxy.md)
|
||||||
|
|
||||||
## Keeping verdaccio running forever
|
## Keeping verdaccio running forever
|
||||||
We can use the node package called 'forever' to keep verdaccio running all the time.
|
You can use node package called ['forever'](https://github.com/nodejitsu/forever) to keep verdaccio running all the time.
|
||||||
https://github.com/nodejitsu/forever
|
|
||||||
|
|
||||||
First install forever globally:
|
|
||||||
|
|
||||||
|
First install `forever` globally:
|
||||||
```bash
|
```bash
|
||||||
$ sudo npm install -g forever
|
$ sudo npm install -g forever
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure you've started verdaccio at least once to generate the config file and write down the created admin user. You can then use the following command to start verdaccio:
|
Make sure you've run verdaccio at least once to generate the config file and write down the created admin user. You can then use the following command to start verdaccio:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ forever start `which verdaccio`
|
$ forever start `which verdaccio`
|
||||||
@ -51,7 +55,7 @@ $ forever start `which verdaccio`
|
|||||||
You can check the documentation for more information on how to use forever.
|
You can check the documentation for more information on how to use forever.
|
||||||
|
|
||||||
## Surviving server restarts
|
## Surviving server restarts
|
||||||
We can use crontab and forever together to restart verdaccio after a server reboot.
|
You can use `crontab` and `forever` together to start verdaccio after a server reboot.
|
||||||
When you're logged in as the verdaccio user do the following:
|
When you're logged in as the verdaccio user do the following:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -72,4 +76,9 @@ $ which forever
|
|||||||
$ which verdaccio
|
$ which verdaccio
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using systemd
|
||||||
|
Instead of `forever` you can use `systemd` for starting verdaccio and keeping it running. Verdaccio installation has systemd unit, you only need to copy it:
|
||||||
|
```bash
|
||||||
|
$ sudo cp /usr/lib/node_modules/verdaccio/systemd/verdaccio.service /lib/systemd/system/ && sudo systemctl daemon-reload
|
||||||
|
```
|
||||||
|
This unit assumes you have configuration in `/etc/verdaccio/config.yaml` and store data in `/var/lib/verdaccio`, so either move your files to those locations or edit the unit.
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=verdaccio Service
|
Description=Verdaccio lightweight npm proxy registry
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
Restart=on-failure
|
||||||
User=verdaccio
|
User=verdaccio
|
||||||
WorkingDirectory=/home/verdaccio
|
ExecStart=/usr/bin/verdaccio --config /etc/verdaccio/config.yaml
|
||||||
ExecStart=/usr/bin/env verdaccio
|
|
||||||
ExecStop=/usr/bin/bash -c "kill $(ps -ef | grep ^verdacc+ | awk {'print $2'})"
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
Loading…
Reference in New Issue
Block a user